Screen clearing problem

Hey,

I’m using openGL through LWJGL and have my window which does not seem to be clearing its contents before rendering so moving a quad causes it to redraw over the top of what was there before.

This is my opengl init code:


		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
		glMatrixMode(GL_MODELVIEW);

This is my mainLoop:


	public void mainLoop() {
		while (!Display.isCloseRequested()) {
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			
			update();
			render();

			Display.sync(fps);
			Display.update();
			
		}
		Display.destroy();
	}

Make sure you’ve set up the clear color and clear depth correctly (do you even have a depth buffer?). Also if you have the scissor test enabled it affects the cleared area. If that doesn’t solve it, make a minimal test program and see if that works. If it doesn’t, post it here so I can test it. :wink:

I fixed whatever was happening by rewriting the way i was rendering. Before, i was determining the offset for each tile in the screen class which was somehow causing problems when rendering the player. My tile class now controls everything and the screen just calls their render method. The design is now more rigid.
Thanks for your help though.

I figured it was some problem with your code, which is why just doing a more simple test and let your code evolve from it is a good idea for graphics programming, since there’s a big chance that if you f*ck something up you’re going to end up with a black screen and a hard time debugging your code (especially with OpenGL 3+).