Jump to content
  • Advertisement
Sign in to follow this  
D3truire

LWJGL exported JAR; Texture Flickering

This topic is 1094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a game in development that uses LWJGL to draw textures for tiles at locations in a grid. Then I draw textures for Objects on top of the grid; either characters or interactable items.

 

I exported the file to a JAR then used jarsplice to include lwgjl.jar and slick.jar in the same jar file.

 

The textures all draw where they are supposed to but sometimes textures (that either are on, or have been on the screen at some point) flicker in seemingly random locations (not necessarily the location that they appeared at). These flickers can occur while the object is still being drawn in the proper location. The flickers occur at an increasing rate which eventually leads to a game crash.

 

The weirdest part is that the bug does show, in even the slightest way, while the game is run in eclipse. It only shows up when the program is run as a JAR file.

 

Any ideas or solutions?

Edited by D3truire

Share this post


Link to post
Share on other sites
Advertisement

Sounds like some sort of z-buffer trashing problem. Are you by any chance doing something like adding more and more objects at the exact same location without removing the old ones? Also, try drawing the layers at an offset to each other (ie object layer few units higher than tile layer on the z-axis).

 

As for the crash, sounds like you're running out of memory (which is why I suspect that your object generation is out of control). Try monitoring the memory consumption.

Edited by Stani R.

Share this post


Link to post
Share on other sites
	public static void DrawQuadTex(float x, float y, float width, float height, Texture tex) {
		tex.bind();
		glTranslatef(x, y, 0);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(0, 0);
		glTexCoord2f(1, 0);
		glVertex2f(width, 0);
		glTexCoord2f(1, 1);
		glVertex2f(width, height);
		glTexCoord2f(0, 1);
		glVertex2f(0, height);
		glEnd();
		glLoadIdentity();
	}

The memory usage from my program does seem to be ridiculous. Upwards of 300mb at times. I checked if I was making multiple objects, and I wasn't, so I thought maybe there was a problem with my drawing method. Is there a flaw with this?

 

This is my first experience with LWJGL so this is essentially copy pasted from a tutorial, though I did my best to make sense of it.

Share this post


Link to post
Share on other sites
	public static void DrawQuadTex(float x, float y, float width, float height, Texture tex) {
		tex.bind();
		glTranslatef(x, y, 0);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(0, 0);
		glTexCoord2f(1, 0);
		glVertex2f(width, 0);
		glTexCoord2f(1, 1);
		glVertex2f(width, height);
		glTexCoord2f(0, 1);
		glVertex2f(0, height);
		glEnd();
		glLoadIdentity();
	}

The memory usage from my program does seem to be ridiculous. Upwards of 300mb at times. I checked if I was making multiple objects, and I wasn't, so I thought maybe there was a problem with my drawing method. Is there a flaw with this?

 

This is my first experience with LWJGL so this is essentially copy pasted from a tutorial, though I did my best to make sense of it.

 

 

Other than the fact that you're using immediate mode (Which pretty much became obsolete in 1997 when OpenGL 1.1 was released) and that you probably shouldn't combine binding a texture with the drawing (if you draw using the same texture multiple times it is unnecessary to bind before each draw), it would also be a good idea to push and pop the matrix rather than calling loadidentity if you absolutely must manipulate the transformation matrix inside the function.

 

Nothing in there should cause flickering though, only worse than necessary performance and a bit of inflexibility.

Edited by SimonForsman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!