Skip to main content
GameDev.net gamedev.net
🔒 Locked

Noob question

Started by Mortizar Jun 4, 2006 at 5:10 PM 0 replies 400+ views
Original Post
Mortizar
Mortizar
I am doing a win32 windowed app that renders in openGL. The problem i run into deals with rendering a 3D triangle after i render a texture onto a 2D quad. Befor i draw the quad the triangle is white, however after i render the 2D textured quad it becomes grey. Once this happens even if i put in glColor and set it to be white again it turns grey anyways. I am not real sure why this is and any hlep as to whats happening would be welcome. below is some of the drawing code.


void DrawGL(void) {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(camera.Position.x, camera.Position.y, camera.Position.z,
		  camera.View.x, camera.View.y, camera.View.z,
		  camera.Up_Vector.x, camera.Up_Vector.y, camera.Up_Vector.z);

	
	if(!terrain.IsDataEmpty()) {
			
			Begin2D();
				glBegin(GL_QUADS);
					glBindTexture(GL_TEXTURE_2D, 1);
					glTexCoord2f(0.0f, 1.0f);
					glVertex2f(WindowRect.left, WindowRect.top);
					glTexCoord2f(0.0f, 0.0f);
					glVertex2f(WindowRect.left + 200, WindowRect.top);
					glTexCoord2f(1.0f, 0.0f);
					glVertex2f(WindowRect.left + 200, WindowRect.top + 200);
					glTexCoord2f(1.0f, 1.0f);
					glVertex2f(WindowRect.left, WindowRect.top + 200);

				glEnd();
			End2D();
	}//end !IsDataEmpty if


	glBegin(GL_TRIANGLES);
		glVertex3f(0, 3, -1);
		glVertex3f(-1, 0, -1);
		glVertex3f(1, 0, -1);
	glEnd();

	SwapBuffers(hdc);

}//end DrawGL



Enigma
Enigma
OpenGL is a state machine. When you set a state (i.e. texture coordinate) that state applies to all future relevant operations. When you enable texturing it remains enabled and applies to all future polygons until you explicitly disable it.

So what is happening is that you are rendering your triangle with texturing enabled and with all three vertices using the last set texture coordinate, which means you just sample a single texel from the texture. You should call glDisable(GL_TEXTURE_2D); before drawing the triangle (or after drawing the quad) and glEnable(GL_TEXTURE_2D); after drawing the triangle (or before drawing the quad).

You also need to move your glBindTexture call outside of the glBegin/glEnd pair. OpenGL does not allow textures to be bound between glBegin and glEnd.

Σnigma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.