I’ve been observing a strange behavior that I’ve managed to capture in a very watered-down version of my program. Basically, I have the line:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
in a part of the code that generates, binds, and loads a texture. When I comment out that line, the rotating square generated in the Render function is bright blue. When the line is not commented out, the square dims to a dark blue. In my other program the effect was on all the colors on the entire screen. Here is the initialization, Projection setup, and render function of my program.
bool BaseVisualEngine::Initialize()
{
// clear to black background
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
m_angle = 0.0f;
p_temp_bitmap = new MyBitmap;
if(p_temp_bitmap->load_24_bit_bitmap("C:\\CppPrograms\\New Interface\\Res\\grey.bmp"))
{
glGenTextures(1, &temp_image);
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glBindTexture(GL_TEXTURE_2D, temp_image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
/******************************************************/
// The following line causes global color dimming :( //
/******************************************************/
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, p_temp_bitmap->width, p_temp_bitmap->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, p_temp_bitmap->p_data);
}
return true;
}
void BaseVisualEngine::SetupProjection(int width, int height)
{
if (height == 0) // don't want a divide by zero
{
height = 1;
}
glViewport(0, 0, width, height); // reset the viewport to new dimensions
glMatrixMode(GL_PROJECTION); // set projection matrix current matrix
glLoadIdentity(); // reset projection matrix
// calculate aspect ratio of window
gluPerspective((GLdouble)m_view_angle,(GLfloat)width/(GLfloat)height,(GLdouble)m_near_z,(GLdouble)m_far_z);
glMatrixMode(GL_MODELVIEW); // set modelview matrix
glLoadIdentity(); // reset modelview matrix
m_windowWidth = (GLfloat)width;
m_windowHeight = (GLfloat)height;
}
void BaseVisualEngine::Render()
{
// clear screen and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Draw the game screen
glPushMatrix();
// move back 5 units and rotate about all 3 axes
glTranslatef(0.0, 0.0, -5.0f);
glRotatef(m_angle, 1.0f, 0.0f, 0.0f);
glRotatef(m_angle, 0.0f, 1.0f, 0.0f);
glRotatef(m_angle, 0.0f, 0.0f, 1.0f);
// green color
glColor3f(0.5f, 5.0f, 1.0f);
// draw the triangle such that the rotation point is in the center
glBegin(GL_QUADS);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();
glPopMatrix();
SwapBuffers(hDC);
}
The line in question is in the initialization function.
The “grey.bmp” bitmap is just a 64 by 64 solid dark grey 24 bit bitmap. I know the bitmap is being loaded correctly, because I can render it on screen without difficulty. As you’ll notice, in this version of the program, I don’t even render it and the weird color glitch still occurs.
Anyone know why the color dims when the line is uncommented?