Rendered Scene Code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPopMatrix();
glEnable(GL_TEXTURE_2D);
Texture t = Texture();
int i = t.LoadBitmapW("c:/b.bmp");
glBindTexture(GL_TEXTURE_2D, i);
//DRAW THE BACKGROUND
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0);glVertex3f(0.0,0.0,0.0);
glTexCoord2f(1.0,0.0);glVertex3f(1.0,0.0,0.0);
glTexCoord2f(1.0,1);glVertex3f(1.0,1,0.0);
glTexCoord2f(0.0,1);glVertex3f(0.0,1,0.0);
glEnd();
glPopMatrix();
glSwapBuffers();
glFlush();
Main Code:
void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,600);
glutCreateWindow("Example");
glutDisplayFunc(renderScene);
// glutIdleFunc(renderScene);
glutReshapeFunc(changeSize);
glutSpecialFunc(processSpecialKeys);
// enable depth testing
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}
Texture Loading Code:
int Texture::LoadBitmap(char *filename)
{
unsigned char *l_texture;
int i, j=0;
FILE *l_file;
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
RGBTRIPLE rgb;
num_texture++;
if( (l_file = fopen(filename, "rb"))==NULL) return (-1);
fread(&fileheader, sizeof(fileheader), 1, l_file);
fseek(l_file, sizeof(fileheader), SEEK_SET);
fread(&infoheader, sizeof(infoheader), 1, l_file);
l_texture = (BYTE *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);
glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
{
fread(&rgb, sizeof(rgb), 1, l_file);
l_texture[j+0] = rgb.rgbtRed; // Red component
l_texture[j+1] = rgb.rgbtRed; // Green component
l_texture[j+2] = rgb.rgbtBlue; // Blue component
l_texture[j+3] = 255; // Alpha value
j += 4; // Go to the next position
}
fclose(l_file);
glBindTexture(GL_TEXTURE_2D, num_texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
free(l_texture);
return num_texture;
}
Screen View Code:
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
// Reset the coordinate system before modifying
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0,0, w, h);
// Set the correct perspective.
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.5,0.5,1.2, 0.5,0.5,0.0, 0.0,1.0,0.0);
Right theres the simplified version of the code because the real code is very long.
This is the ouput I get when i run the program
Image 1
This is the texture getting mapped
Image 2
As i said thats the basic version of the code but its still giving pale images.
And my apologies for the lack of info during my first post. I thought the reason why I was getting pale images was due to the Variables I was using in the original code which were decreasing image quality for faster performance and i thought that someone could quickly point where i was going wrong from the code i posted.
Hope this helps, if not explain what else you require
Thanks for your help