I am trying to setup some textured quads that are in one class, while I initialize the texture in another class. Basicly I have 2 classes, Block and Map. The Block class holds the draw info, while the textures are loaded in the init of the Map class. I declare the texture array global(I know, bad me), and call the extern to access them in the Block class. When ever it comiles and runs though, the textures do not show up. I have verified the textures do load and are in the correct file path. Here is the code.
Block (important parts of class)
extern Texture blockTexture[8];
...
//Draw block
void Block::drawBlock()
{
glSetupTexture(blockTexture[text].ID);
enginelog.Write(2, "%d", text);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(box[0].x+position.x, box[0].y+position.y, 1.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(box[1].x+position.x, box[1].y+position.y, 1.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(box[2].x+position.x, box[2].y+position.y, 1.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(box[3].x+position.x, box[3].y+position.y, 1.0f);
glEnd();
glDeleteTex();
}
//Set Texture Unit
void Block::setTexture(int image)
{
text = image;
}
Map (important part of class)
Texture blockTexture[8];
//Map Constructor
Map::Map()
{
Vector4 color;
Vector4 position;
color.x = 0.0f;
color.y = 0.0f;
color.z = 0.0f;
position.x = 0.0f;
position.y = 0.0f;
for (int r = 0;r < MAPSIZER; r++)
{
for (int c =0;c < MAPSIZEC;c++)
{
level[r][c].setColor(color);
level[r][c].setPosition(position);
}
}
if(!blockTexture[0].LoadTGAFile("data/red.tga"))
{MessageBox(NULL, "Cannot Load data/red.tga", "Error", MB_OK);}
if(blockTexture[0].textureExist)
{MessageBox(NULL, "Loaded red.tga::Red Block", "Texture", MB_OK);}
if(!blockTexture[1].LoadTGAFile("data/green.tga"))
{MessageBox(NULL, "Cannot Load data/green.tga", "Error", MB_OK);}
if(!blockTexture[2].LoadTGAFile("data/blue.tga"))
{MessageBox(NULL, "Cannot Load data/blue.tga", "Error", MB_OK);}
if(!blockTexture[3].LoadTGAFile("data/orange.tga"))
{MessageBox(NULL, "Cannot Load data/orange.tga", "Error", MB_OK);}
if(!blockTexture[4].LoadTGAFile("data/pink.tga"))
{MessageBox(NULL, "Cannot Load data/pink.tga", "Error", MB_OK);}
if(!blockTexture[5].LoadTGAFile("data/yellow.tga"))
{MessageBox(NULL, "Cannot Load data/yellow.tga", "Error", MB_OK);}
if(!blockTexture[6].LoadTGAFile("data/grey.tga"))
{MessageBox(NULL, "Cannot Load data/grey.tga", "Error", MB_OK);}
if(!blockTexture[7].LoadTGAFile("data/blank.tga"))
{MessageBox(NULL, "Cannot Load data/blank.tga", "Error", MB_OK);}
}
//Map File Parser
Block Map::parseInput(char input, int r, int c)
{
Block temp;
Vector4 color;
Vector4 position;
int alive;
int solid;
int text;
switch(input)
{
case '0':
color.x = 0.0f;
color.y = 0.0f;
color.z = 0.0f;
text = 7; // Blank
alive = 0;
solid = 0;
break;
case 'S': // Grey Solid Block
color.x = 0.4f;
color.y = 0.4f;
color.z = 0.4f;
text = 6;
alive = 1;
solid = 1;
break;
case 'R': // Red Block
color.x = 1.0f;
color.y = 0.0f;
color.z = 0.0f;
text = 0;
alive = 1;
solid = 0;
break;
case 'G': // Green Block
color.x = 0.0f;
color.y = 1.0f;
color.z = 0.0f;
text = 1;
alive = 1;
solid = 0;
break;
case 'B': // Blue Block
color.x = 0.0f;
color.y = 0.0f;
color.z = 1.0f;
text = 2;
alive = 1;
solid = 0;
break;
case 'Y': // Yellow Block
color.x = 1.0f;
color.y = 1.0f;
color.z = 0.0f;
text = 5;
alive = 1;
solid = 0;
break;
case 'P':
color.x = 0.0f; // Pink Block
color.y = 1.0f;
color.z = 1.0f;
text = 4;
alive = 1;
solid = 0;
break;
case 'O': // Orange Block
color.x = 1.0f;
color.y = 0.5f;
color.z = 0.5f;
text = 3;
alive = 1;
solid = 0;
break;
default: // Default NO BLOCK
color.x = 0.0f;
color.y = 0.0f;
color.z = 0.0f;
text = 7;
alive = 0;
solid = 0;
}
position.x = -c;
position.y = -r;
temp.setColor(color);
temp.setPosition(position);
temp.setAlive(alive);
temp.setSolid(solid);
temp.setTexture(text);
return temp;
}
I have run checks to make sure the correct texture unit is being called, and all seems to be going good, but it just draws the blocks as white.
By the way my texture setup functions just enables texture2d and binds the texture.
dimebag