Multiple Textures in One scene, One per mesh?

Hi guys,
I have a scene in which there is a background mesh, and two other meshes. All these meshes are textured with different textures and each texture has a transparent background. I already got it so the meshes that are textured are transparent and the textures still show up correctly(with alpha and everything.) but when I render all the meshes and texture them, it seems to render each each texture, one superimposed on the last. I can’t seem to figure out why?

Here is the Rendering and Texturing code:


void RenderAll()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    Texture(BOARD);
    b->Render();

    Texture(CHAR_X);
    c->Render(CHAR_X);

    Texture(CHAR_O);
    c->Render(CHAR_O);

    g->Switch(hDC);
}

void Texture(int ID)
{
    switch(ID)
    {
        case BOARD:
        {
            glBindTexture(GL_TEXTURE_2D, tex[0]);
            break;
        }

        case CHAR_X:
        {
            glBindTexture(GL_TEXTURE_2D, tex[1]);
            break;
        }

        case CHAR_O:
        {
            glBindTexture(GL_TEXTURE_2D, tex[2]);
            break;
        }
    }
}

void LoadTextures()
{
    GLint width, height, components;
    YsRawPngDecoder *png = new YsRawPngDecoder();

    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_RGBA);

    //LOAD THE ACTUALL IMAGES

    for(int i = 0; i < 3; ++i)
    {
        GLubyte *data;
        glBindTexture(GL_TEXTURE_2D, tex[i]);
        
        if(i == 0)
        {
            png->Decode("Art/Board_Basic.png");
            data = png->rgba;
            width = png->wid;
            height = png->hei;
        }

        else if(i == 1)
        {
            png->Decode("Art/X_Basic.png");
            data = png->rgba;
            width = png->wid;
            height = png->hei;
        }

        else
        {
            png->Decode("Art/O_Basic.png");
            data = png->rgba;
            width = png->wid;
            height = png->hei;
        }

        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); 

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    }
}

The main application is Win32, but rendering, I/O, user interaction, etc. is all done abstractly from the OS in C++.

“b” , “c” , and “g” are all classes

it seems to render each each texture, one superimposed on the last

You will have to be more precise, and/or show more code (ie. blend mode ? depth buffer ? etc)

I’ve included an Image so you can see what I mean.

I also forgot to specify that each texture is rendered on a quad I specify the quads like so:


glBegin(GL_QUADS);
        glTexCoord2d(0, 0);
        glVertex2d(0, 0);

        glTexCoord2d(1, 0);
        glVertex2d(<width>, 0);

        glTexCoord2d(1, 1);
        glVertex2d(<width>, <height>);

        glTexCoord2d(0, 1);
        glVertex2d(0, <height>);
    glEnd();

I’m using the following blending:


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

it is global, meaning that it applies to ALL my OpenGL meshes and operations.

If you wish me to, I’ll archive all my code so that you can look at it and see if the problem is something else.

Seems good on the GL side, but avoid drawing several quads with different textures at the same place ?

Hmmm, ok. So essentially, I should change the Z-Postion of each quad so they aren’t in the same Z space?

No, just only draw what you need, ie. cross OR circle, not both at the same xy place.

Ok. I did happen to figure it out. Thank you for the help!!!

And the solution was …?