Help with Texture Manager

Started by
1 comment, last by Dustino 20 years, 3 months ago
I'm having a trouble finding what's wrong with the following code, it's supposed to render a textured tilemap that's loaded in memory. It loads the map and renders the quads correctly, but the quads aren't textured. NOTE: Whenever I read in the textures from the map file I put them into a class (CTexture) and push them into a vector. The constructor for the CTexture class generates a texname (OGL) and stores it in the class. I'm sure I've done something stupid somewhere. Anyways here's the code: Map Rendering code:

    int dataIndex = 0;
    int Data;

    for (int rowIndex = 0; rowIndex < Maps[0].getRows(); rowIndex++) {
        for (int colIndex = 0; colIndex < Maps[0].getCols(); colIndex++) {          
            Data = Maps[0].getData(dataIndex);  
            Render->drawQuad(QUAD_ISO, Maps[0].getTexture(Data));
            Render->setRenderPosition(1.0, -0.5, 0.0);
            dataIndex++;
        }
        Render->setRenderPosition((float)(((Maps[0].getCols())*-1.0)-1), (float)(((Maps[0].getCols())*0.5)-0.5), 0.0);
  }
Map Functions:
         
CTexture *CMap::getTexture(int ID) {
    for (int texIndex = 0; texIndex < texNum; texIndex++) {
        if (Textures[texIndex].getID()) { return(&Textures[texIndex]); }
    }

    return(&Textures[0]);
}

int CMap::getData(int Cell) {    
    return(Data[Cell]);
}
Quad Rendering:
         
void CRender::drawQuad(int Type, CTexture *Texture) {
    glBindTexture(GL_TEXTURE_2D, Texture->getGID());
    switch (Type) {
        case QUAD_TILE:
            glBegin(GL_QUADS);
                glTexCoord2f(0.0, 0.0f); glVertex3f(0.0f, 0.0f,  0.0f);
                glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 0.0f,  0.0f);
                glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f,  0.0f);
                glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f,  0.0f);
            glEnd();
            break;
        case QUAD_ISO:
            glBegin(GL_QUADS);
                glTexCoord2f(0.0, 0.0f); glVertex3f(1.0f, 0.0f,  0.0f);
                glTexCoord2f(1.0f, 0.0f); glVertex3f(2.0f, 0.5f,  0.0f);
                glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f,  0.0f);
                glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.5f,  0.0f);
            glEnd();
            break;
        default:break;
    }
}
Maps is a vector of CMap classes Textures is a member of CMap and is vector of CTexture classes Data is a member of CMap, and is vector of integers [edited by - Dustino on January 5, 2004 11:46:47 AM]
Advertisement
Well, don't shoot me for this, but this code is not very readable:

for (int colIndex = 0; colIndex < Maps[0].getCols(); colIndex++) {  Render->drawQuad(QUAD_ISO, Maps[0].getTexture(Maps[0].getData(dataIndex)));            Render->setRenderPosition(1.0, -0.5, 0.0);            dataIndex++;        }        Render->setRenderPosition((float)(((Maps[0].getCols())*-1.0)-1), (float)(((Maps[0].getCols())*0.5)-0.5), 0.0);    }


I can't see what the error is, but here's a list of common mistakes:
- Textures are not sized 2^n
- Texturing is not enabled
- Lighting is incorrect (texture appears black)
- glTexEnv is not set correct

Are you sure your texture pointers aren't NULL?

Edo

[edited by - edotorpedo on January 5, 2004 6:29:31 AM]
Edo
Please, please, please choose a better title for your thread next time. Thank you.

This topic is closed to new replies.

Advertisement