I’d like to apply a multiplier to every texel of a texture while displaying it on a 2D rectangle. This would be trivial if I used a fragment program, but I’m trying to do this with minimal OpenGL extension support.
It seems to me that I could just use the ambient light to achieve this if the texture property is GL_MODULATE. However, I haven’t yet gotten it working, which leads me to suspect I’m forgetting some glEnable() or missing some other obscure setting.
Here’s what I’m doing now:
// init time
float ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
// Allocate the texture
glGenTextures(1,&e->projection.texhandle);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, e->projection.texhandle);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_INTENSITY8,
e->width, e->height, 0,
GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
// Setup lighting
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
glEnable(GL_LIGHTING);
// Setup display list
e->projection.dlisthandle = glGenLists(1);
glNewList(e->projection.dlisthandle, GL_COMPILE);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,e->projection.texhandle);
glColor4d(1.0,1.0,1.0,1.0);
glBegin(GL_QUADS);
glTexCoord2d(0,0);
glVertex2d(0,0);
glTexCoord2d(e->width,0);
glVertex2d(e->width,0);
glTexCoord2d(e->width,e->height);
glVertex2d(e->width,e->height);
glTexCoord2d(0,e->height);
glVertex2d(0,e->height);
glEnd();
glEndList();
// render
float ambient[] = {e->projection.intensity, e->projection.intensity, e->projection.intensity, 1.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
glCallList(e->projection.dlisthandle);
I’m seeing the image, but it isn’t being brightened appropriately.
Any ideas?