Hi I am trying to display bitmap image in opengl using glut library. this is main code.
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow(“yrBMP”);
glutReshapeFunc(OnSize);
glutDisplayFunc(OnDraw);
std::cout<<"Enter filename:";
std::string fname;
std::cin>>fname;
BMPClass bmp;
BMPLoad(fname,bmp);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,3,bmp.width,bmp.height,0,GL_RGB,GL_UNSIGNED_BYTE,bmp.bytes);
glutReshapeWindow(bmp.width,bmp.height);
glutMainLoop();
return 0;
}
void OnSize(int x,int y)
{
glViewport(0,0,x,y);
glDrawBuffer(GL_BACK);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,1,1,0);
glMatrixMode(GL_MODELVIEW);
}
void OnDraw()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2d(0,1); glVertex2d(0,0);
glTexCoord2d(1,1); glVertex2d(1,0);
glTexCoord2d(1,0); glVertex2d(1,1);
glTexCoord2d(0,0); glVertex2d(0,1);
glEnd();
glutSwapBuffers();
}
Code works fine with 24 bit bitmap image.
But when I tried it 8bit bitmap images (images using colour palette) .Sometimes I see distorted images and sometimes correct images. I have attached original image and distorted image using printscreen.You can see original image in 1.png and distorted image in 2.png. I m sure that I have read the image data right. I think problem is mostly in display functions used in main.cpp .Please help me. Sorry for my english.