Jump to content
  • Advertisement
Sign in to follow this  
mello

Textured square

This topic is 4272 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

Hello community, I've a really simple function to draw a square with a white pavement texture:
void draw_square(float size[], float translation[])
{    
     glPushMatrix();
     glTranslatef(translation[0], translation[1], translation[2]);

     glColor3ub(255,0,0); //just to force OpenGL to draw in RED 
     glDisable(GL_COLOR_MATERIAL); //supposely, the RED color should be disabled

     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, 1]); //bind a WHITE pavement texture
     int rep = 5; 
     glBegin(GL_POLYGON);
        glNormal3d(0.0, 1.0, 0.0);
	glTexCoord2f(0.0,0.0); glVertex3d(-size[0]/2, size[1]/2, size[2]/2);
	glTexCoord2f(rep,0.0); glVertex3d(size[0]/2, size[1]/2, size[2]/2);
	glTexCoord2f(rep,rep); glVertex3d(size[0]/2, size[1]/2, -size[2]/2);
	glTexCoord2f(0.0,rep); glVertex3d(-size[0]/2, size[1]/2, -size[2]/2);
     glEnd();
     
     glDisable(GL_TEXTURE_2D);
     glEnable(GL_COLOR_MATERIAL);  //OpenGL should draw in RED again

     glPopMatrix;
}
The problem is that I get a RED textured square and not a WHITE. It seems that the glDisable(GL_COLOR_MATERIAL); is not working at all! Actually, if I comment that line I get the same results! Any ideas on how to solve this color problem? Thanks a lot, mello

Share this post


Link to post
Share on other sites
Advertisement
The GL_COLOR_MATERIAL state controls whether or not a glColor call updates the current material state, not whether the current object is rendered with the current material colour. In pseudocode:
void glColor(colour)
{
current_colour = colour;
if (GL_COLOR_MATERIAL is enabled)
{
current_material.colour = colour;
}
}

So disabling GL_COLOR_MATERIAL after you set the colour is too late. The material colour has already been set to red. You probably want to either ignore GL_COLOR_MATERIAL and just set the colour to white before rending your textured quad, explicitly set the material colour to white separately using glMaterial, or disable GL_COLOR_MATERIAL before any colour changes.

Σnigma

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!