Sign in to follow this  
FunLogic

Resetting render states

Recommended Posts

I've just been in the process of converting my texture code from supporting TGA files to Direct Draw Surfaces. When I came to test the DDS loader I noticed something strange about the final rendered image. Here's the render function:
void render_scene(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glTranslatef(0.0f, 0.0f, -3.0f);

    glBindTexture(GL_TEXTURE_2D, texture->id);

    glBegin(GL_QUADS);

        glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.5f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, 0.5f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);

    glEnd();

    glInterleavedArrays( GL_C4UB_V3F, 0, g_lineVertices );
    glDrawArrays( GL_LINES, 0, 6 );


    glFinish();
    SwapBuffers(dc);
}

Earlier in my program, I load the Texture from a DDS file and enable Texturing via glEnable(GL_TEXTURE_2D); the thing is, unless I enable texturing again in the rendering function and then disable it immediately after drawing my textured quad the colors of the axis lines that I draw using the interleaved arrays are distorted (they look darker). Is it really necessary that I enable and disable texturing within my rendering function every time? Also, when drawing the vertex array the current color is set using glColor3ub(0, 0, 255). When the function is called again the texture is tinged blue - do I just have to make a call to glColor**() again and set it to white?

Share this post


Link to post
Share on other sites
OpenGL is a state machine. If you enable texturing, it's on until you turn it off. When you set a color, that color is your active color forever until you change it again.

When you are done with the color, reset it to 1,1,1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this