Original Post
ok, i started of by tring to make a texture class, you know, pass in the file name in it''s constructor and there ya go, have all your texture stuff encapsulated so yo don''t mess with it. It didn''t work, all i got were white cubes, so i caved in and just added the functions normaly.
now i try to make a cube class. I''m working on a game that uses alot of cubes, so i figured a class would be a good addition to the engine. Now i run into the same problem. i think it has something to do with textures being stored in the class, but i have no idea why it doesn''t work. I''m useing Nehe''s code (of course) for LoadGLTexture.
here''s the code if you want to check it out.
Thanx in advance for any help.
-------------------------------------------------
Don''t take life too seriously, you''''ll never get out of it alive. -Bugs Bunny
class CCube
{
public:
CCube(float fsize, char *Filename)
{
glEnable(GL_TEXTURE_2D);
LoadGLTexture(texture, Filename);
MySize = fsize;
Location.x = 0.0f;
Location.y = 0.0f;
Location.z = 0.0f;
SphereRad = (float)2*sqrt(MySize*MySize + MySize*MySize); //calcultae spherical volume for fustrum culling
};
~CCube(){};
void SetLoc(CVector newLoc)
{
Location.x = newLoc.x;
Location.y = newLoc.y;
Location.z = newLoc.z;
};
void SetLoc(float newx, float newy, float newz)
{
Location.x = newx;
Location.y = newy;
Location.z = newz;
};
void Draw()
{
glBindTexture(GL_TEXTURE_2D, texture[0] );
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + MySize);
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + MySize);
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + MySize);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + MySize);
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + -MySize);
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + -MySize);
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + MySize);
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + MySize);
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + -MySize);
// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + MySize);
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + MySize);
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + -MySize);
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + -MySize);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + MySize, Location.y + MySize, Location.z + MySize);
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + MySize, Location.y + -MySize, Location.z + MySize);
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + -MySize);
glTexCoord2f(1.0f, 0.0f); glVertex3f(Location.x + -MySize, Location.y + -MySize, Location.z + MySize);
glTexCoord2f(1.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + MySize);
glTexCoord2f(0.0f, 1.0f); glVertex3f(Location.x + -MySize, Location.y + MySize, Location.z + -MySize);
glEnd(); // Done Drawing Quads
};
private:
GLuint texture[1];
float MySize;
CVector Location;
float SphereRad;
};
|