I am trying desperately to texture a simple quad using known examples but I always get a white quad with no texture. I tried creating the texture by myself and still nothing !
My initialization is :
// Initialize display mode to be double buffered, with RGBA color model and with a depth buffer
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
// Initialize window position and size
glutInitWindowPosition(-1, -1); // OS dependent
glutInitWindowSize(500, 400);
// Initialize the GLUT library
glutInit(&argc, args);
// Initialize opengl
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
// Bind and generate the texture
glGenTextures(1, &g_uiTextureId);
glBindTexture(GL_TEXTURE_2D, g_uiTextureId);
unsigned char *data;
data = (unsigned char *)malloc(256 * 256 * 3);
// Should create a red texture
for (int i = 0; i < 256 * 256 * 3; i += 3) {
data = 255;
data[i+1] = 0;
data[i+2] = 0;
}
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
if (glGetError() != GL_NO_ERROR)
printf("ERROR!"); // Never reached here
Rendering :
// Clear drawing buffer and depth buffer
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
// Reset world matrix and set world position for a triangle
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6.0f);
glBindTexture(GL_TEXTURE_2D, g_uiTextureId);
// Render a textured cube
glBegin(GL_QUADS);
// Front face
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
glFlush();
// Display frame
glutSwapBuffers();
thx.
[Edited by - DesignerX on June 19, 2009 12:40:17 PM]
There is nothing that can't be solved. Just people that can't solve it. :)