Original Post
I am trying to load a texture on a quad and if I do not use glGenTextures() in the following code it works fine while if do use glGenTextures() the texture does not get mapped on the quad and I just get a red quad. Why does it work if I remove the glGenTextures()? [Edited by - Fella on April 30, 2006 7:24:16 AM]
const int TEX_NUM = 1; // number of textures
const int GROUND_TEX = 0; // ground texture
GLuint textures[ TEX_NUM ]; // holds allocated names of texture objects
const char* textureFileNames[ TEX_NUM ] = { "texture.tga" };
// initializes OpenGL state
void setupRC()
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); // set clearing color
GLubyte* pLoadedTGA; // pointer to loaded TGA texture
GLint width, height; // number of color components in the texture
GLint internalFormat; // texture propreties
GLenum format; // format of the texture ( RGB etc.)
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glGenTextures( TEX_NUM, textures );
for ( int texObj = 0; texObj < TEX_NUM; texObj++ )
{
glBindTexture( GL_TEXTURE_2D, textures[ texObj ] );
pLoadedTGA = gltLoadTGA( textureFileNames[ texObj ], &width, &height, &internalFormat, &format );
gluBuild2DMipmaps( GL_TEXTURE_2D, internalFormat, width, height, format, GL_UNSIGNED_BYTE, pLoadedTGA );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
free( pLoadedTGA );
}
glEnable( GL_DEPTH_TEST );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0f, 800/600, 1, 500 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
void render()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glColor3fv( 1.0f, 0.0f, 0.0f );
glTranslatef( 0.0f, 0.0f, -30.0f );
glRotatef( 10.0f, 1.0f, 0.0f, 0.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, GROUND_TEX );
glBegin( GL_QUADS );
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -2000.0f, 0.0f, 2000.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 2000.0f, 0.0f, 2000.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 2000.0f, 0.0f, -2000.0f);
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -2000.0f, 0.0f, -2000.0f);
glEnd();
glDisable( GL_TEXTURE_2D );
glPopMatrix();
glutSwapBuffers();
}