GlColor paints all textures

I am new to OpenGL, so perhaps the answer will be obvious. I'm currently trying to make a blue circle using GL_TRIANGLE_FAN in C ++. My problem is that when I set the color with glColor4f, it sets blue for all my other textures on top of them, as shown below (it should be silver metal).

I draw textures using the method shown below.

glLoadIdentity();
glTranslatef(x,y,0);

glBindTexture(GL_TEXTURE_2D, this->texture); 

glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0,0,0);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(width,0,0);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(width,height,0);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0,height,0);   
glEnd();

I'm not sure I just need to clear the flag to make it work, but I've been stuck for several days now.

+4
source share
4 answers

Untie the texture and return the color to white after drawing is complete:

glLoadIdentity();
glTranslatef(x,y,0);

glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, this->texture); 

glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0,0,0);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(width,0,0);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(width,height,0);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0,height,0);   
glEnd();

glColor4f(1, 1, 1, 1);
glBindTexture(GL_TEXTURE_2D, 0);

, :

glDisable( GL_TEXTURE_2D );
+6

( ) glColor4f(1.f, 1.f, 1.f, 1.f);. , ( ) , ( = * ).

+7

glEnable (GL_COLOR_MATERIAL) glColor, . , (glColor ).

, - glColor : glColor4f (1.0, 1.0, 1.0, 1.0). , . REPLACE - ! ( , , !) , GL_COLOR_MATERIAL , glColor Ambient Diffuse - , (). , , , (, , ), glEnable (GL_COLOR_MATERIAL), :

glDisable(GL_COLOR_MATERIAL); //disable color influence
GLfloat ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; //default material has this ambient color!
GLfloat diffuse[] = { 0.8f ,0.8f ,0.8f, 1.0f }; //default material has this diffuse color!
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); //restore default material ambient color
glMaterialfv(GL_FRONT, GL_AMBIENT, diffuse); //restore default material diffuse color

, ! .

, , , ( ). , , , , .

+1

. , , , . - :

glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, this->texture); 

glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0,0,0);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(width,0,0);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(width,height,0);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0,height,0);   
glEnd();

glDisable( GL_TEXTURE_2D );
0

All Articles