Original Post
I've just hit a brick wall here... Ok so I have a GUI class with an array size 5 holding CGUIBtn objects: and GUI calls LoadTexture to set each texture in each of the 5 buttons. Rigth after loading all those I load another texture. The problem is: all the polygons are textured with the very last texture which I've loaded... In CTexture the function seems to be the source of the problem because glGenTextures ALWAYS sets ID to 1... What could possibly be causing it to do this??? I'm using GLUT and here's my init function: glGUI.LoadTextures() loads all the textures, i put it at the very end so everything should be enabled right? PS Sorry if I'm asking so many questions.
class CGUIBtn
{
public:
CGUIBtn(void);
CGUIBtn(char *file);
~CGUIBtn(void);
CTexture m_TexOff;
CTexture m_TexOver;
int m_Height;
int m_Width;
bool LoadTexture(int state, char * file);
void Render(float yPos);
};
void CTexture::GenerateTexture()
{
// Generate the texture and text the id to the images id.
glGenTextures(1, &ID);
// Here we bind the texture and set up the filtering.
glBindTexture(GL_TEXTURE_2D, ID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, type, imageWidth, imageHeight, 0, type, GL_UNSIGNED_BYTE, image);
gluBuild2DMipmaps(GL_TEXTURE_2D, type, imageWidth, imageHeight, type, GL_UNSIGNED_BYTE, image);
}
void CFGapp::Init(int argc, char *argv[])
{
///////////////////////////////////////////////////////////////////////////
// GLUT Initialisation
///////////////////////////////////////////////////////////////////////////
glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); // Size the window
// Center Window
glutInitWindowPosition((GetSystemMetrics(SM_CXSCREEN)-SCREEN_WIDTH)/2,
(GetSystemMetrics(SM_CYSCREEN)-SCREEN_HEIGHT)/2);
glutInitWindowPosition(0,0);
glutInit(&argc, argv); // Initialise GLUT
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH ); // Set display mode
// Create a normal window if we're debuging
glutCreateWindow("Space Combat Arena");
char dispModeStr[64];
sprintf(dispModeStr, "%dx%d:%d@%d", SCREEN_WIDTH, SCREEN_HEIGHT, 16, 60);
glutGameModeString(dispModeStr);
glutEnterGameMode();
///////////////////////////////////////////////////////////////////////////
// GLUT now ready...
// Some of our own GL setup
///////////////////////////////////////////////////////////////////////////
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Clear the screen to the specified color.
glShadeModel(GL_SMOOTH); // Smooth shading in our scenes.
glEnable(GL_DEPTH_TEST); // Enable desth testing for hidden surface removal.
glEnable(GL_TEXTURE_2D); // Enable texture mapping.
// Light properties for the diffuse light, specular light, and light position.
float diffuseLight[] = {0.8f, 0.8f, 0.8f, 1.0f};
float specularLight[] = {1.0f, 1.0f, 1.0f, 1.0f};
float LightPosition[] = {0.0f, 0.0f, 8.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 10.0f);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 75.0f);
// Set up the material information for our objects. Again this is just for show.
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight);
glMateriali(GL_FRONT, GL_SHININESS, 128);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_ALPHA);
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); // resets the viewport to new dimensions.
glMatrixMode(GL_PROJECTION); // Sets the projection matrix.
glLoadIdentity(); // Reset the modelview matrix.
// Calculate the aspect ratio of the window.
gluPerspective(45.0f, (GLfloat)SCREEN_WIDTH/(GLfloat)SCREEN_HEIGHT, 0.1f, 1000.0f);
glutDisplayFunc(RenderGLUT_CB); // Our display function...
glutSetCursor(GLUT_CURSOR_NONE);
glMatrixMode(GL_MODELVIEW); // Sets the projection matrix.
glLoadIdentity(); // Reset the modelview matrix.
glGUI.LoadTextures();
}