Blending trouble

Started by Brush, January 16, 2005, 19:02:04

Previous topic - Next topic

Brush

I'm not sure if this goes in here or in the openGL forum but anyway...

I'm writing a simple game to learn openGL and I'm having some problems with blending.
I render my menu which is just a couple of textured quads. Those textures have alpha channels so I enabled blending.
I use the following function to render those quads:
public void renderSprite(Sprite spr)
	{
		GL11.glLoadIdentity();
		spr.texture.bind();
		float x=spr.location.x;
		float y= spr.location.y;
		float width=spr.texture.width;
		float height=spr.texture.height;
		GL11.glBegin(GL11.GL_QUADS);
		// Display the top left vertex
		GL11.glTexCoord2f(0.0f, 0.0f);
		GL11.glVertex3f(x, y, 0);
		// Display the bottom left vertex
		GL11.glTexCoord2f(0.0f, 1.0f);
		GL11.glVertex3f(x,y-height,0.0f);
		// Display the bottom right vertex
		GL11.glTexCoord2f(1.0f, 1.0f);
		GL11.glVertex3f(x+width,y-height,0.0f);
		// Display the top right vertex
		GL11.glTexCoord2f(1.0f, 0.0f);
		GL11.glVertex3f(x+width,y,0.0f);
		GL11.glEnd();
}


This works fine, but there's a problem when I start a game. Seeing as I haven't done any art for the game I just want to render a solid quad without any texture on it.
I use this function:
public void renderRectangle(float x, float y, float width,float height)
	{
		GL11.glDisable(GL11.GL_BLEND);
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex3f(x,y,0.0f);
		GL11.glVertex3f(x,y+height,0.0f);
		GL11.glVertex3f(x+width,y+height,0.0f);
		GL11.glVertex3f(x+width,y,0.0f);
		GL11.glEnd();
		GL11.glFlush();
		GL11.glEnable(GL11.GL_BLEND);
}


It clears the colorbuffer and renders the quad just fine, but when I want to go back to my menu, my menu won't render anymore.

this code is exectued when I return to the menu:
private void renderMenu()
	{
		camera.clearScene(0.0f,0.0f,0.0f);
		//and call the rendersprite function
		camera.renderSprite(newGame);
		camera.renderSprite(highScores);
		camera.renderSprite(exit);
		camera.update();
}


It clears the scene, but the sprites aren't showing up for some reason.
I tried disabling and enabling texture mapping, but they're not showing up.
So now I want to know what exactly it is that I'm doing wrong.
I know I could just render a temp textured quad and be done with it, but I want to know why this isn't working.

tomb

It's really hard to say. It can be anything. Have you disabled the depth buffer before rendering the menu?

Brush

Ok I figured out what the problem was. The spirtes rendered fine at first, but when I drew a normal "filled" rect I changed the draw colour to black (to contrast with the white background).
If I change the draw colour to white when I draw a sprite it works fine.

princec

You probably left colour modulation on (glTexEnvi with GL_MODULATE instead of GL_REPLACE)

Cas :)