So I’ve decided to play around with LWJGL. To start with something simple, I wrote a standard ‘ball bouncing around the screen’…
Here’s how I initialize the display:
Display.setDisplayMode(new DisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT));
Display.setFullscreen(false);
Display.setVSyncEnabled(true);
Display.setTitle("TestField");
Display.create();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
Here’s how I draw things in the main loop:
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
field.draw();
Display.update();
Display.sync(100);
And here’s how I draw one single ball in field.draw():
texture.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x, y);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(x + texture.getTextureWidth(), y);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(x + texture.getTextureWidth(), y + texture.getTextureHeight());
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(x, y + texture.getTextureHeight());
GL11.glEnd();
And here’s the result how it looks:
http://i63.photobucket.com/albums/h134/Nejiro/glitch.png
As you can see, the ball appears quite glitchy…
Here’s the entire netbeans project folder:
http://www.speedyshare.com/uKHSZ/FieldTreeTest.zip
So, what’s the problem there? I can’t find why the ball is drawn incorrectly… :’(