GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


"fix" code by baldurk
1
 
class Tile
{
    public:
        Texture floortex, rooftex, walltex;
        String name;
        int direction;
        bool floor, roof, walls, organic, stream, river;
};

Tile *Tiles[5];

for(int i=0; i < 5; i++)
    Terrain.Tiles[i] = new Tile;

// 0 <= ID < 5, otherwise it'd be easy and it'd crash here :(.
    if(tiles[ID]->floor)
            {
                tiles[ID]->floortex.Bind();
                glBegin(GL_QUADS);
                glTexCoord2f(0.0f, 0.0f);glVertex3f(0.0f, 0.0f, 0.0f);
                glTexCoord2f(1.0f, 0.0f);glVertex3f(size, 0.0f, 0.0f);
                glTexCoord2f(1.0f, 1.0f);glVertex3f(size, 0.0f, size);
                glTexCoord2f(0.0f, 1.0f);glVertex3f(0.0f, 0.0f, size);
                glEnd();
            }

            if(tiles[ID]->roof)
            {
                tiles[ID]->rooftex.Bind();
                glBegin(GL_QUADS);
                glTexCoord2f(0.0f, 0.0f);glVertex3f(0.0f, size, 0.0f);
                glTexCoord2f(1.0f, 0.0f);glVertex3f(size, size, 0.0f);
                glTexCoord2f(1.0f, 1.0f);glVertex3f(size, size, size);
                glTexCoord2f(0.0f, 1.0f);glVertex3f(0.0f, size, size);
                glEnd();
            }
            
            if(tiles[ID]->walls)
            {
                tiles[ID]->walltex.Bind();
                
                glBegin(GL_QUADS);
                if(x == 0 || !tiles[texarray[z*dep + x - 1]] ||
                   !tiles[texarray[z*dep + x - 1]]->walls)
                {
                    glTexCoord2f(0.0f, 1.0f);glVertex3f(0.0f, size, 0.0f);
                    glTexCoord2f(0.0f, 0.0f);glVertex3f(0.0f, 0.0f, 0.0f);
                    glTexCoord2f(1.0f, 0.0f);glVertex3f(0.0f, 0.0f, size);
                    glTexCoord2f(1.0f, 1.0f);glVertex3f(0.0f, size, size);
                }
                if(x == wid-1 || !tiles[texarray[z*dep + x + 1]] ||
                   !tiles[texarray[z*dep + x + 1]]->walls)
                {
                    glTexCoord2f(0.0f, 1.0f);glVertex3f(size, size, 0.0f);
                    glTexCoord2f(0.0f, 0.0f);glVertex3f(size, 0.0f, 0.0f);
                    glTexCoord2f(1.0f, 0.0f);glVertex3f(size, 0.0f, size);
                    glTexCoord2f(1.0f, 1.0f);glVertex3f(size, size, size);
                }
                if(z == dep-1 || !tiles[texarray[z*dep + x + dep]] ||
                   !tiles[texarray[z*dep + x + dep]]->walls)
                {
                    glTexCoord2f(0.0f, 1.0f);glVertex3f(0.0f, size, size);
                    glTexCoord2f(0.0f, 0.0f);glVertex3f(0.0f, 0.0f, size);
                    glTexCoord2f(1.0f, 0.0f);glVertex3f( size, 0.0f, size);
                    glTexCoord2f(1.0f, 1.0f);glVertex3f( size, size, size);
                }
                if(z == 0 || !tiles[texarray[z*dep + x - dep]] ||
                   !tiles[texarray[z*dep + x - dep]]->walls)
                {
                    glTexCoord2f(0.0f, 1.0f);glVertex3f(0.0f, size, 0.0f);
                    glTexCoord2f(0.0f, 0.0f);glVertex3f(0.0f, 0.0f, 0.0f);
                    glTexCoord2f(1.0f, 0.0f);glVertex3f( size, 0.0f, 0.0f);
                    glTexCoord2f(1.0f, 1.0f);glVertex3f( size, size, 0.0f);
                }
                glEnd();
            }