Hello again JGO community. Rather than write tutorials this time i’m here asking for YOUR help. I’m having a rendering issue thats been ongoing for about 3 months now… We have a Game Engine that can be used to write both Android games via openGL ES 1.0 (or GL10) and as of 3 months ago also launch the same games on PC via LWJGL. I’m having a really hard time with the PC Renderer, i’ve tried different methods in the past week but i’m running out of options. This may be mainly due to my inexperience with openGL, so I may be doing something wrong.
I’ll try to dissect the rendering as much as possible and provide screenshot of what is actually happening.
At the moment - Rendering goes something like this.
try {
PixelFormat pixelFormat = new PixelFormat();
Display.setDisplayMode(new DisplayMode(graphics.getWidth(), graphics.getHeight()));
Display.setTitle("Halfway Engine");
Display.setFullscreen(fullScreen);
Display.create(pixelFormat);
}
catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
This is the “loop”
while (!Display.isCloseRequested()) {
if (state == RUNNING) {
float deltaTime = (System.nanoTime() - startTime) / 1000000000.0f;
startTime = System.nanoTime();
fixedUpdateCall += deltaTime;
if (fixedUpdateCall >= 100.0f) {
fixedUpdateCall -= 100.0f;
screen.fixedUpdate();
}
// update the screen - the logic code
screen.update(deltaTime);
// present the screen - rendering
screen.present(deltaTime);
}
if (state == PAUSED) {
screen.pause();
}
Display.update();
Display.sync(120);
}
As far as rendering goes - this is rendering code for openGL simplified
public void setGLContext() {
camera.setViewport();
graphics.glDisable(Graphics.GL_DEPTH_TEST);
graphics.glEnable(Graphics.GL_BLEND);
graphics.glBlendFunc(Graphics.GL_SRC_ALPHA, Graphics.GL_ONE_MINUS_SRC_ALPHA);
graphics.glEnable(Graphics.GL_TEXTURE_2D);
graphics.glLoadIdentity();
}
And at beginning of every new frame - this code is called from the scene (present) method
public void setNewFrameContext() {
graphics.glClear(Graphics.GL_COLOR_BUFFER_BIT/* | Graphics.GL_DEPTH_BUFFER_BIT*/);
graphics.glClearColor(clearColor.getX(), clearColor.getY(), clearColor.getZ(), 1.0f);
graphics.glLoadIdentity();
}
The issues i’m having is that Android rendering works fine, all of the openGL ES functions are mapped onto their equivalent LWJGL function calls via the graphics interface so as far as rendering goes, its exact same code for both platforms.
- I use a Sprite Batching technique to draw all sprites at same time
- I use multiple texture atlas
- I may bind multiple textures, but only one at a time. Process is, bind a texture -> Draw the contents of Sprite Batcher -> unbind the texture
- glError returns 0 (no error)
// texture binding code
graphics.glBindTexture(Graphics.GL_TEXTURE_2D, textureID);
// texture unbind code
graphics.glBindTexture(Graphics.GL_TEXTURE_2D, 0);
Below are some screenshots of the rendering artifacts i’m getting.
Error 1 - Note the Artifacts around the letters. The Buttons are from one texture atlas and letters from another
Error 2 - This is a normal scene - you control that rectangular thing, as soon as it passes over the circles, they are
destroyed and removed from the scene.
And this is what happens when I run them over with the paddle
It leaves a trail of the paddle at the paddles location as soon as a ball is destroyed. I’ve double and tripple checked, as far
as the renderer is concerned, no instance or reference of the ball exists in the renderer. If i destroyed all the balls, only the
paddles reference would remain (only renderable) and the text aswell, but thats not part of the “game” world.
Any and all help would be appreciated, I’m trying to get to the bottom of this so I can move onto implementing other features,
I can post code snippets as requested. Like I mentioned before, all openGL calls are directly mapped from Android to LWJGL and Android rendering works fine.