Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / OpenGL Development / Re: Front face change - any help appreciated! on: 2008-03-15 18:25:03
Ahhhh okay, I just wrote it out on paper and then reversed it, makes total sense haha.  I thought maybe I had broken my OpenGL :\

Thanks for the insight Riven!
2  Java Game APIs & Engines / OpenGL Development / Front face change - any help appreciated! on: 2008-03-15 18:04:46
Hi again!

I'm having a really weird problem with my call to glOrtho(), in that when I call it as GL11.glOrtho(0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1); and then draw my quad, the quad displays as I would expect. I draw my quad while my Front Face is Counter-Clockwise (call glFrontFace(GL_CCW); when I init the OpenGL stuff).

However, my problem arises when I try calling glOrtho() as GL11.glOrtho(0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), 0, -1, 1);. Here, my quad doesn't display anywhere! After some fiddling around, I found that if I changed the ordering of my vertices on my quad to make them Clockwise, it drew fine!

So my question is, does anyone know why this is so? It seems like the Front Face changes unexpectedly when I change my coordinate system using the glOrtho call. I'm guessing there is some concept I'm missing when you change coordinate systems, but I'm really at a loss.

Thanks for any help! I appreciate it!

Cheers

Jarrett
3  Java Game APIs & Engines / OpenGL Development / Re: 2D fonts won't display - any help appreciated on: 2008-03-14 02:48:02
Hi again!

I ended up finding code similar to mine that worked - looks like the problem was that my quads were built for a non-orthographic surface (they were iddy-bitty), so they didn't display in Ortho mode!  yeesh.  I'm pretty sure I grew a few grays with this one.

Anywho, thanks for the help oNyx!
4  Java Game APIs & Engines / OpenGL Development / Re: 2D fonts won't display - any help appreciated on: 2008-03-13 22:43:50
>Not sure what you mean here...

Did you bind a texture? Well, I just listed the usual things which are usually forgotten.

Other than that... sometimes the things are simply not on screen or clipped away. Try orthographic projection.

Yes that's exactly my problem, Orthographic projection isn't work!  gah!

And yes I have a texture bound.
5  Java Game APIs & Engines / OpenGL Development / Re: 2D fonts won't display - any help appreciated on: 2008-03-13 21:37:01
Did you enable textures?
Yup, here's the init code that readies OpenGL for me:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
private void init() {
      // run through some based OpenGL capability settings. Textures
      // enabled, back face culling enabled, depth texting is on,
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glEnable(GL11.GL_CULL_FACE);
      // Enable hidden-surface removal
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glDepthFunc(GL11.GL_LEQUAL);
      GL11.glShadeModel(GL11.GL_SMOOTH);
     
      // Set the clear color to Black
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
      // Set the depth to clear at
      GL11.glClearDepth(1.0f);
     
      // define the properties for the perspective of the scene
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();      
      GLU.gluPerspective(45.0f, ((float) 800) / ((float) 600), 0.1f, 100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      // Enable really nice perspective calculations
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      // Enable line antialiasing
      GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
}



Bound one?

Not sure what you mean here...


Set color to white?

Just added:
1  
GL11.glColor3f(1.0f, 1.0f, 1.0f);

before the for loop that renders the characters, but no change.


Checked the blending mode?

After posting this code, I tried adding:
1  
2  
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

before the for loop that rendered the characters, and then calling
1  
GL11.glDisable(GL11.GL_BLEND);

after, but no dice.  I also tried parameters (GL11.GL_SRC_ALPHA, GL11.GL_ONE) in the glBlendFunc to no avail.

Thanks for the post oNyx.
6  Java Game APIs & Engines / OpenGL Development / 2D fonts won't display - any help appreciated on: 2008-03-13 20:59:14
Hey all!

I'm sure most of you hate getting 2D questions, but I've done searching for this topic, followed tutorials, etc, and I can't seem to get it to work! I'm using the LWJGL conversion of NeHe's tutorial #17 on Bitmap Fonts, but no dice.  The 2D fonts just do not want to display on the screen!

Here's the code for my BitmapFont class (it controls loading of the font and printing it):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
package common.gui.font;

import common.gui.texture.*;

import java.awt.Color;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.FontMetrics;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;

import org.lwjgl.opengl.GL11;

public class BitmapFont {

   private static final BitmapFont source = new BitmapFont();
   
   private static final Color OPAQUE_WHITE = new Color(0xFFFFFFFF, true);
   private static final Color TRANSPARENT_BLACK = new Color(0x00000000, true);
   
   /** The display list id, where each character to print to the screen
    *  is added to this value.  For example, listBase+65 would be the character
    *  'A'.*/

   private int listBase;
   /** The texture for this font */
   private Texture texture;
   /** The current font */
   private String currentFont = "Courier New";
   
   
   private BitmapFont() {
      init();
   }
   
   private void init() {
      buildFont();
      buildDisplayLists();
   }
   
   private void buildFont() {
      try {
         texture = TextureMgr.get().getTexture("res/Font.bmp");
      } catch (Exception e) {
         e.printStackTrace();
         System.exit(0);
      }
   }
   
   private int testid;
   /**
    * Create the display lists used for drawing characters to the screen.
    */

   private void buildDisplayLists() {
      listBase = GL11.glGenLists(256); // Storage For 256 Characters
      testid = GL11.glGenLists(1);
     
     
      float x = (float)(texture.getWidth()/2);
      float y = (float)(texture.getHeight()/2);
      x = 2.0f;
      y = 2.0f;
      GL11.glNewList(testid, GL11.GL_COMPILE);
      texture.bind();
      GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(1.0f, 0.0f);
         GL11.glVertex3f(x, -y, 0.0f);
         GL11.glTexCoord2f(1.0f, 1.0f);
         GL11.glVertex3f(x, y, 0.0f);
         GL11.glTexCoord2f(0.0f, 1.0f);
         GL11.glVertex3f(-x, y, 0.0f);
         GL11.glTexCoord2f(0.0f, 0.0f);
         GL11.glVertex3f(-x, -y, 0.0f);
      GL11.glEnd();
      GL11.glEndList();

        /* Generate the display lists.  One for each character in the standard/extended ASCII chart.
         */

        float textureDelta = 1.0f / 16.0f;
        for(int i=0;i<256;i++) {
            float u = ((float)(i % 16)) / 16.0f;
            float v = 1.f - (((float)(i / 16)) / 16.0f);
            GL11.glNewList(listBase + i, GL11.GL_COMPILE);
            texture.bind();
            GL11.glBegin(GL11.GL_QUADS);
                GL11.glTexCoord2f(u, v - textureDelta);
                GL11.glVertex3f(-0.0450f, -0.0450f, 0.0f);
                GL11.glTexCoord2f((u + textureDelta), v - textureDelta);
                GL11.glVertex3f(0.0450f, -0.0450f, 0.0f);
                GL11.glTexCoord2f((u + textureDelta), v);
                GL11.glVertex3f(0.0450f, 0.0450f, 0.0f);
                GL11.glTexCoord2f(u, v);
                GL11.glVertex3f(-0.0450f, 0.0450f, 0.0f);
            GL11.glEnd();
            GL11.glEndList();
        }
   }
   
   public static BitmapFont get() {
      return source;
   }
   
   /**
    * Prepare OpenGL for Orthographic rendering.  The method will ensure that
    * all states are saved.
    */

   private void enterOrtho() {
      GL11.glDisable(GL11.GL_DEPTH_TEST);
     
      // Load the projection mode and save it's current state
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
     
      // Set up orthographic projection mode
      GL11.glOrtho(0, 800, 0, 600, -1, 1);
     
      // Enter model view mode
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
   }
   
   /**
    * Leave Orthographic rendering in OpenGL.  Will restore all states saved
    * by enterOrtho().
    */

   private void leaveOrtho() {
      // Restore the state of the projection mode
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glPopMatrix();
     
      // Restore the state of the model view mode
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glPopMatrix();
      GL11.glEnable(GL11.GL_DEPTH_TEST);
   }
   
   public void print(String msg, float x, float y) {
      enterOrtho();
      GL11.glTranslatef(x, y, 0.0f);
     
      // Ignore null value
      if (msg != null) {
         texture.bind();
         // Print the characters
         for(int i = 0; i < msg.length(); i++) {
            GL11.glCallList(listBase + msg.charAt(i));
            GL11.glTranslatef(1.0f, 0.0f, 0.0f);
            }        
      }
      leaveOrtho();  
   }
   
}


You might notice the TextureMgr.get().getTexture("res/Font.bmp"); bit in there. I basically took the image loading code out of here and put it in another class to make it all nicer. Also, the Texture object here is basically a class to hold the width/height of the image used for the texture, and to hold the texture id generated by the OpenGL engine. The texture.bind() method just calls GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.id);, where this.id is the texture id given by OpenGL.

So basically, I call BitmapFont.get().print("blah blah", 100.0f, 100.0f); from some class, and it (should!) print the text to the display.  But it doesn't!  And the weird thing about the above code is that, if I remove the enterOrtho() and leaveOrtho() methods, the text displays fine! (Albeit it doesn't print using pixel coordinates, which I want!)

Does anyone have any idea what's up here? I'm quite flustered at the moment. I decided to ask you guys for help before I threw my monitor out the window haha.

Thanks in advance!

ps: I thnk I've included all the relevant info, if not tho lemme know and I'll give whatever you need!
7  Game Development / Networking & Multiplayer / Re: program updates on: 2004-04-27 20:47:23
Thx blah,

I'm headin over to check it out as we speak (err...as I type) Smiley
8  Game Development / Networking & Multiplayer / program updates on: 2004-04-27 18:34:25
Howdy,

I know there are a few posts here about how to update an application.  I believe WebStart was mentioned several times.  What is webstart?  I've been trying (rather unsuccessfully) to download an update .jar file from my website using Streams (I used bufferedReader to download the stream using readLine() and bufferedWriter to write those lines in a new file on my harddrive using write(string)).  I tried to tinker with JarInputStream and JarOutputStream but I can't figure out how to get a JarInputStream to acquire the inputStream from the website connection (btw:  I use a URL to connect to the website).

Could anyone explain the WebStart?  Or if anyone knows how to get a .jar file from a webpage using Streams that would be awsome!

Thx,
Jarrett
aka. Chisser98
9  Game Development / Networking & Multiplayer / Re: Create a URL pointing to C:\ on: 2004-04-26 14:19:31
Ahh ok.  That makes sense.  Thank you for the clarification.

Regards,
Jarrett
aka. Chisser98
10  Game Development / Networking & Multiplayer / Re: Create a URL pointing to C:\ on: 2004-04-26 01:15:00
OHH MANN....I just figured it out.  Its one of those things that when you've got it you want to rip your hair out and scream "Gimme a break!".  

All I need to do was change "file://c:/test.html" to "file:///c:/test.html" !  I needed an extra "/" after the "file://"......ohhhh maann...lol!

I hope this helps someone else if they have this problem!

Regards,
Jarrett
aka. Chisser98
11  Game Development / Networking & Multiplayer / Create a URL pointing to C:\ on: 2004-04-26 00:59:07
Hey all!

How would I go about creating a URL that references to html files on my hard-drive?  I've tried to create a new URL object and sending the constructor strings like "file://C:/test.html", "file://C:\test.html", and "c:\test.html" but none of them seem to work.  

Heres the
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
package CarringtonPlace.Help;
import CarringtonPlace.IView.IBEIView;
import CarringtonPlace.Model.HelpBook;
import CarringtonPlace.Model.Constants;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.UIManager;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import java.io.File;

import java.net.URL;
import java.io.IOException;
import java.awt.Dimension;
import java.awt.GridLayout;


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */


public class HelpHTMLPane extends JEditorPane implements IBEIView
{  private HelpBook model;

   private URL helpURL;

   public HelpHTMLPane(HelpBook theModel)
   {  super();
      this.model = theModel;
     
      this.initializeHelp();
     
     
      this.model.addView(this);
   }
   
   private void initializeHelp()
   {  //String s = "http://www.icebreakersentertainment.com";
      //String s = "file://" + Constants.HELP_PATH + "test.html";
      //String s = "test.html";
      String s = "file://C:/test.html";
      //System.out.println(s);
     
      try
      {  this.helpURL = new URL(s);
      } catch (Exception e)
      {  System.err.println("Could not parse URL address.");
      }
     
      //this.helpURL = HelpHTMLPane.class.getResource("Main.html");
      if (helpURL == null)
      {  System.err.println("Couldn't open help file: " + s);
      } else
      {  System.out.println("Help URL is " + this.helpURL);
      }
     
      this.displayURL(helpURL);
   }
   
   private void displayURL(URL url)
   {  try
      {  if (url != null)
         {  this.setPage(url);
         } else
         {  //null url
            this.setText("File Not Found");
            System.out.println("Attempted to display a null URL.");
         }
      } catch (IOException e)
      {  System.err.println("Attempted to read a bad URL: " + url);
      }
   }

   
   public void updateView()
   {
   }
   
   public void updateColors()
   {
   }

}


I'd appreciate any input on this!

Thx,

Jarrett
aka. Chisser98
12  Java Game APIs & Engines / Java 2D / Re: BufferStrategy works with only 1 buffer...not on: 2004-04-25 14:43:24
Thx for the help (again) Smiley

I made the changes you suggested but to no avail.  I think java hates me!  I'm still having the same problem...I'm not seeing anything I draw onto the buffer when I have 2 buffers....but it seems to work when I only have 1 buffer (albiet it flickers).  Its insane!  

I did a system.out.println() when I created my bufferstrategy and it printed as "java.awt.Component$FlipBufferStrategy@17a29a1", which I think is correct (I'm trying to do the flip buffer strategy).  I think I'm gonna try to just draw onto the Frame...I've heard ppl who have problems with canvas do that and it works.

Thx again for your help trebovetski!


Jarrett
aka. Chisser98
13  Java Game APIs & Engines / Java 2D / Re: BufferStrategy works with only 1 buffer...not on: 2004-04-24 14:05:59
heh sry, I can see how that would be a bit confusing.  Heres the full code:
This is the FRAME I use -->
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
package View;
import Model.World;


import java.awt.Canvas;
import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsDevice;
import java.awt.DisplayMode;
import java.awt.Frame;
import javax.swing.JFrame;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */


public class GameFrame extends Frame
{  private GameCanvas gameCanvas;
   private MainMenuCanvas mainMenuCanvas;
   private MenuCanvas menuCanvas;

   private World model;

   private GraphicsEnvironment ge;
   private GraphicsDevice gd;

   private int lengthX = 800;
   private int lengthY = 600;

   private DisplayMode originalDisplayMode;

   private boolean fullScreen;

   public GameFrame(World theModel)
   {  this.model = theModel;
      this.model.addView(this);

      this.ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      this.gd = this.ge.getDefaultScreenDevice();

      this.fullScreen = this.gd.isFullScreenSupported();
      this.setUndecorated(this.fullScreen);
      this.setResizable(!this.fullScreen);
      this.setIgnoreRepaint(this.fullScreen);
      this.initializeFullScreen();

      this.gameCanvas = new GameCanvas(this.lengthX, this.lengthY);
      this.add(this.gameCanvas);
      this.gameCanvas.setVisible(true);

   }

   private void initializeFullScreen()
   {  if (this.fullScreen)
      {  this.originalDisplayMode = this.gd.getDisplayMode();

         try
         {  this.gd.setFullScreenWindow(this);
            DisplayMode newMode = new DisplayMode(this.lengthX, this.lengthY, 24, 60);
            this.gd.setDisplayMode(newMode);
         }  catch (Exception e)
         {  if (this.gd.isDisplayChangeSupported())
            {  if (!this.originalDisplayMode.equals(this.gd.getDisplayMode()))
               {  this.gd.setDisplayMode(this.originalDisplayMode);
               }

               this.gd.setFullScreenWindow(null);
            }
         }
      }

      this.setBackground(Color.black);
      this.pack();
      //this.setVisible(true);
   }

   public void updateView()
   {  this.gameCanvas.updateView();
   }
}


And this is the CANVAS I use -->
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
package View;
import Model.World;


import java.awt.Canvas;
import java.awt.BufferCapabilities;
import java.awt.image.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Graphics2D;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */


public class GameCanvas extends Canvas
{  private BufferStrategy bufferStrategy;
   private int numBuffers = 2;

   private int lengthX;
   private int lengthY;


   public GameCanvas(int lengthX, int lengthY)
   {  super();
      this.lengthX = lengthX;
      this.lengthY = lengthY;

      this.setSize(this.lengthX, this.lengthY);

      this.registerListeners();

      this.setIgnoreRepaint(true);
      this.setBackground(Color.white);
   }

   public void registerListeners()
   {
   }

   /* Ready the buffers for drawing onto the canvas - Should only be needed to be
      called from within the canvas itself
   */

   public void initializeGraphics()
   {

      this.createBufferStrategy(this.numBuffers);
      this.bufferStrategy = this.getBufferStrategy();
   }

   /* Set the canvas visible/invisible, but also initialize the canvas BufferStrategy if
      the canvas is to be shown in the GameFrame
   */

   public void setVisible(boolean state)
   {  if (state)
      {  this.initializeGraphics();
      }
      super.setVisible(state);
   }

   /* This method will 'try' to get the BufferStrategys' graphics, draw on the canvas,
      and then display the canvas (using Page Flipping)
   */

   private void drawGraphics()
   {
      try
      {  Graphics2D g2 =  (Graphics2D) this.bufferStrategy.getDrawGraphics();
         this.render(g2);
         this.bufferStrategy.show();
         g2.dispose();
      }  catch (Exception e)
      {  System.out.println("ERROR DRAWING GRAPHICS: " + e.toString());
      }

   }

   /* This will draw (render) the graphics onto the graphics buffer supplied from
      BufferStrategy
   */

   private void render(Graphics2D g2)
   {  if (!this.bufferStrategy.contentsLost())
      {  System.out.println("Rendering graphics");
         g2.setColor(Color.green);
         g2.fillRect(0, 0, this.lengthX, this.lengthY);
         g2.setColor(Color.white);
         g2.drawString("Testing 1, 2, 3.  GameCanvas TEST.", 10, 10);
         g2.setColor(Color.magenta);
         g2.fillRect(40, 100, 80, 250);
      } else
      {  System.out.println("Contents of the buffer have been lost...Cannot render Canvas.");
      }
   }

   public void updateView()
   {  this.drawGraphics();
   }


}


Thx for any help you could offer.  This is really driving me insane!

Thx again,
Jarrett
aka. Chisser98
14  Java Game APIs & Engines / Java 2D / BufferStrategy works with only 1 buffer...not 2 on: 2004-04-23 02:09:19
Hi again!

I'd like to thank trembovetski for helping me with my last post.  I finally got it working.  

But when I try to draw in my canvas, nothing works (this is with 2 buffers).  However, when I use 1 buffer it seems to work...Heres the code:

1  
2  
3  
4  
5  
6  
7  
//initialize the graphics when i create the canvas
public void initializeGraphics()
   {

      this.createBufferStrategy(this.numBuffers);
      this.bufferStrategy = this.getBufferStrategy();
   }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//draw the graphics on the canvas...called from a render loop
private void drawGraphics()
   {  
      try
      {  Graphics2D g2 =  (Graphics2D) this.bufferStrategy.getDrawGraphics();
         this.render(g2);
         this.bufferStrategy.show();
         g2.dispose();
      }  catch (Exception e)
      {  System.out.println("ERROR DRAWING GRAPHICS: " + e.toString());
      }

   }


the render(g2) method simply uses g2 to draw some rectangles.  

Now, when I initialize the graphics and call
1  
this.createBufferStrategy(this.numBuffers)
and
1  
this.numBuffers = 2
, nothing works (ie. the canvas is visible b/c I can see the background I set the canvas to display), but the canvas doesn't draw anything.  However, when I set
1  
this.numBuffers = 1
, then the canvas draws everything I want it too (albiet it flickers ALOT).  I'm assuming it flickers b/c there is only 1 buffer, and I'm drawing over the buffer everytime I call the render(g2) method.  

Does anyone know how I would get 2 buffers to work?

Thanks for all your help!

Sincerely,
Jarrett
aka. Chisser98
15  Java Game APIs & Engines / Java 2D / canvas with BufferStrategy in Fullscreen problem on: 2004-04-21 20:21:33
Howdy all,

I'm trying to draw on a canvas object using BufferStrategy, but I'm having some problems.

I first tried to set my BufferStrategy in the constructor of the canvas i was using:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class WorldView extends Canvas
{  private BufferStrategy strat

   public WorldView()
   {  super();

          this.layoutView();
          this.registerListeners();

          this.createBufferStrategy(2);
          this.strat = this.getBufferStrategy();
   }
}


However, when I ran my program i got this error:

java.lang.IllegalStateException: Component must have a valid peer

     at java.awt.Component$FlipBufferStrategy.createBuffers(Component.java:3039)

     at java.awt.Component$FlipBufferStrategy.<init>(Component.java:3014)

     at java.awt.Component.createBufferStrategy(Component.java:2923)

     at java.awt.Canvas.createBufferStrategy(Canvas.java:166)

     at java.awt.Component.createBufferStrategy(Component.java:2855)

     at java.awt.Canvas.createBufferStrategy(Canvas.java:141)

     at Dune2.View.WorldView.<init>(WorldView.java:60)

     at Dune2.View.TopLevelView.<init>(TopLevelView.java:37)

     at Dune2.Model.Start.main(Start.java:33)

I really didn't know what to make of this.  I found that exception type and its somthing like 'the method is being called at an inappropriate time'.  So, I decided to try to put the code for creating the bufferstrategy in my code for drawing the stuff on the screen:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
private void drawGraphics()  {  
      if (!this.buffersSet)
      {  this.createBufferStrategy(2);
         this.strategy = this.getBufferStrategy();
         this.buffersSet = true;
      }
      Graphics g = this.strategy.getDrawGraphics();
      this.render(g);
      g.dispose();
      this.strategy.show();
}



This doesn't work either.  I don't get an exception, but rather nothing draws and I don't see anything but light gray where my game should be :\  The method 'render(g)' is just my method that draws all the units (ie. g.drawImage(----)).  

Somthing else that I thought might be a problem was that in my render method, I'm converting the Graphics object g into a Graphics2D object (I need Graphics2D for AffineTransform) so that I could rotate the images I draw on the screen.  

Could anyone help me out here?

Thanks,
Chisser98
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!