I'm trying to display a 128x128 array of floats (0.0 -> 1.0) as a texture of green on black within a legacy FLTK application. The rest of the application uses immediate mode for all it's drawing, so I don't want to change the way it works. From reading tutorials, I've come up with the following calls that should be sufficient to load the texture into graphics memory, and draw it to the current context (managed by FLTK). However, all I can get it to do is draw a black square where the texture should be, drawing over anything else that has been drawn there (GL_LINES).
Is there anything basic that I'm missing here? some initialization step that I've neglected? Thanks in advance. Here the code that I'm trying to get running:
// Part of class init
glGenTextures(1, &tex);
// As far as I can tell, this is optional with FLTK having already
// set these parameters. Omitting them does not change output.
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODEL);
glLoadIdentity();
// This is the meat of the problem. reports no GL errors.
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_GREEN, GL_FLOAT, &image);
glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex2f(-0.9,-0.9);
glTexCoord2d(0,1); glVertex2f(-0.9, 0.9);
glTexCoord2d(1,0); glVertex2f( 0.9,-0.9);
glTexCoord2d(1,1); glVertex2f( 0.9, 0.9);
glEnd();
glDisable(GL_TEXTURE_2D);
// Again, busywork.
glPopMatrix();