Textured and untextured quads

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Textured and untextured quads

Post 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?
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Textured and untextured quads

Post 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.
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: Textured and untextured quads

Post 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 );
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: Textured and untextured quads

Post 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?
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
szdarkhack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 61
Joined: Fri May 08, 2009 2:31 am

Re: Textured and untextured quads

Post 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.
User avatar
BugInTheSYS
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 88
Joined: Mon Feb 07, 2011 4:16 pm
Current Project: Vintage Roads
Favorite Gaming Platforms: PC
Programming Language of Choice: C++, Delphi
Location: Pinneberg, Germany
Contact:

Re: Textured and untextured quads

Post by BugInTheSYS »

okay, thank you.
Someday, everything will go to /dev/null. - Bug's prophecy 13:37
User avatar
Teser0ck
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 35
Joined: Mon Aug 29, 2011 12:59 pm
Current Project: Platformer game, Map editor, Particle system
Programming Language of Choice: C++
Location: Czech Republic

Re: Textured and untextured quads

Post by Teser0ck »

Thank you, this solved my problem too :)
Post Reply