Advertisement

non-textured quad next to a bunch of quads...

Started by July 12, 2005 02:32 PM
3 comments, last by eSCHEn 19 years, 2 months ago
ok, basically after going through lesson 6, I decided to play around a bit and make a hallway with a door at the end. I decided not to try for multiple textures just yet, and so instead of loading a second texture decided I'd make the door a green square. Here's what my drawing portion of the code looks like

int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	glLoadIdentity();									// Reset The Current Modelview Matrix
	glTranslatef(-0.0f,0.0f,-10.0f);                      // z,y,z
	glBindTexture(GL_TEXTURE_2D, texture[0]);           // Select the Texture
    glRotatef(xrot, 0.0f, 10.f, 0.0f);
    glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
        // Right face 1
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		// Right face 2
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -3.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -3.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
        // Right face 3
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -5.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -5.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -3.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -3.0f);	// Bottom Left Of The Texture and Quad
        // Left Face 1
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad  
	    // Left Face 2
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -3.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -3.0f);	// Top Left Of The Texture and Quad 
	    // Left Face 3
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -5.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -3.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -3.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -5.0f);	// Top Left Of The Texture and Quad 
		// Back Face 3
		glColor3f(0.0f,1.0f,0.0f);
        glVertex3f(-1.0f, -1.0f, -5.0f);	// Bottom Right Of The Texture and Quad
		glVertex3f(-1.0f,  1.0f, -5.0f);	// Top Right Of The Texture and Quad
		glVertex3f( 1.0f,  1.0f, -5.0f);	// Top Left Of The Texture and Quad
		glVertex3f( 1.0f, -1.0f, -5.0f);	// Bottom Left Of The Texture and Quad
    /*	// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad */
		glEnd();
	
	xrot+=0.1f;								// X Axis Rotation
	yrot+=0.2f;								// Y Axis Rotation
	zrot+=0.4f;								// Z Axis Rotation
	
	return TRUE;										// Everything Went OK
}
With this for some reason, everything is green instead of just that one square. I'm guessing I have to "drop" the texture or something like that, could someone explain to me how to do that/explain to me how to accomplish my goal of everything else being textured & having one non-textured green square? Thanks in advance.
call glEnable(GL_TEXTURE_2D) when you bind your texture and glDisable(GL_TEXTURE_2D) when you have drawn the geometry that you want to be textured.
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
Advertisement
OpenGL is a state machine, that is to say whatever state you set will stay the same until you change it. In your code snippet the colour is initially white, which is default, then as soon as the glColor3f(0.0f, 1.0f, 0.0f) is executed then everything on from that point will be green until you tell it to change, this includes the lines before it on the next loop though the function. Try putting a call to glColor3f(1.0f, 1.0f, 1.0f) after the bit you want green and that should do it.

Also, if you want the green item untextured then as Vexator states, you should disable texturing before it and enable it afterwards.

Before you get any hassle for it, if you're going to post more than a few lines of code then you should enclose it within [ source ][ /source ] tags and you'll get a nice monospaced box thus:

10 PRINT "Hello World!"20 GOTO 10


Have fun :)
--
Cheers,
Darren Clark
ok, thanks for the replies... about the code bit... i tried posting them in actually since I've seen that on other BBS's... I'll make sure to post in [ source ] from now on when I post code.
Feel free to use tags for short sections but yeah, [ source ] tags for longer stuff :) Actually there's a lot of options I didn't notice we could do, have a <a href="http://www.gamedev.net/community/forums/faq.asp">gander</a>.
--
Cheers,
Darren Clark

This topic is closed to new replies.

Advertisement