Page 1 of 1

Textured and untextured quads

Posted: Sat Oct 01, 2011 5:52 am
by BugInTheSYS
Hi folks,
I'm having problems using textures in OpenGL. Basically what happens is I'm trying to draw one textured quad, and the whole rest should not be textured but just colored. According to Ginto's explanation last evening, I use this code (actually not quite, I filled in the variables for better reading), after entering GL_QUADS, for the textured and the following, had-better-not-be-textured quad:

Code: Select all

    // Textured quad
    glBindTexture( GL_TEXTURE_2D, texture );
    glTexCoord2f( 0.0f, 1.0f );
    glVertex3f( -1.0f, -1.0f, -1.1f );
    glTexCoord2f( 0.0f, 0.0f );
    glVertex3f( -1.0f, 1.0f, -1.1f );
    glTexCoord2f( 1.0f, 0.0f );
    glVertex3f( 1.0f, 1.0f, -1.1f );
    glTexCoord2f( 1.0f, 1.0f );
    glVertex3f( 1.0f, -1.0f, -1.1f );
    glBindTexture( GL_TEXTURE_2D, 0 );

    // Untextured one
    glColor4ub( 200, 200, 200, 255 );
    glVertex3f( 1.0f, -1.0f, -1.1f );
    glVertex3f( 1.0f, 1.0f, -1.1f );
    glVertex3f( 1.0f, 1.0f, -1.0f );
    glVertex3f( 1.0f, -1.0f, -1.0f );
But it won't work. Instead, what I get is one textured quad with stars, and the rest are BLACK quads. The last glTexCoord2f I'm calling up there refers to such a black pixel. When I'm replacing the texture by a white image, the rest is drawn correctly, when using a grey one I'm getting the rest somewhat dark, so the texture has influence on the scene. But shouldn't glBindTexture( GL_TEXTURE_2D, 0 ) prevent OpenGL from applying textures to the other objects?

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 6:09 am
by N64vSNES
I'm not sure I completely understand your question but:

If you want that second quad to be none-textured and colored then forget calling glBindTexture(GL_TEXTURE_2D,0), it's a waste of time. Just call glDisable(GL_TEXTURE_2D) and then any form of texturing is not allowed.

If you want to grantee textures will not be applied then just disable it.

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 6:12 am
by BugInTheSYS
The code is working fine now, since I had glBindTexture inside glBegin()...glEnd() last time, which apparently does not work. Pulling it out of there did the trick.

Code: Select all

// Textured quad
  glBindTexture( GL_TEXTURE_2D, texture );
  glBegin( GL_QUADS );
    glTexCoord2f( 0.0f, 1.0f );
    glVertex3f( -1.0f, -1.0f, -1.1f );
    glTexCoord2f( 0.0f, 0.0f );
    glVertex3f( -1.0f, 1.0f, -1.1f );
    glTexCoord2f( 1.0f, 0.0f );
    glVertex3f( 1.0f, 1.0f, -1.1f );
    glTexCoord2f( 1.0f, 1.0f );
    glVertex3f( 1.0f, -1.0f, -1.1f );
  glEnd();
  glBindTexture( GL_TEXTURE_2D, 0 );
  glBegin( GL_QUADS );

    // Untextured one
    glColor4ub( 200, 200, 200, 255 );
    glVertex3f( 1.0f, -1.0f, -1.1f );
    glVertex3f( 1.0f, 1.0f, -1.1f );
    glVertex3f( 1.0f, 1.0f, -1.0f );
    glVertex3f( 1.0f, -1.0f, -1.0f );

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 6:14 am
by BugInTheSYS
N64vSNES wrote:I'm not sure I completely understand your question but:

If you want that second quad to be none-textured and colored then forget calling glBindTexture(GL_TEXTURE_2D,0), it's a waste of time. Just call glDisable(GL_TEXTURE_2D) and then any form of texturing is not allowed.

If you want to grantee textures will not be applied then just disable it.
Well calling glDisable for textures in the render loop will make me have to enable it again each time, isnt that time-consuming?

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 7:26 am
by szdarkhack
BugInTheSYS wrote:Well calling glDisable for textures in the render loop will make me have to enable it again each time, isnt that time-consuming?
Actually no, binding the texture is more time consuming than enabling and disabling. Binding sets pointers on you graphics card, it might even move data around. Enabling/disabling just tells the driver whether it should use the textures or not, nothing else. By the way, if you don't disable GL_TEXTURE_2D when drawing untextured quads, in most implementations you'll get black quads as a result, not the color you assign to them. I hope this helps.

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 7:39 am
by BugInTheSYS
okay, thank you.

Re: Textured and untextured quads

Posted: Sat Oct 01, 2011 10:01 am
by Teser0ck
Thank you, this solved my problem too :)