I’ve been looking at a number of online resources for how to draw textures in 2D with opengl / glut. They all seem to say the same thing and I can’t see what I’m doing wrong.
Here’s a picture showing what’s going wrong:
Here’s the relevant code:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowSize(600, 600);
glutInitWindowPosition(-1, -1);
glutCreateWindow("glut");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 600, 600, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glutTimerFunc(0, update_func, 0);
glutTimerFunc(0, draw_func, 0);
glEnable(GL_TEXTURE_2D);
...
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, row_pointers);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
...
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex2f(64.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex2f(64.0, 64.0);
glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 64.0);
glEnd();
The image I loaded was a 64 x 64 png file with an alpha channel. As far as I know I’m loading it with libpng correctly as I inspected the row data and found it to be accurate. Any ideas?