Jump to content
  • Advertisement
Sign in to follow this  
shanshanzg

OpenGL blank ppm image in glut window using DevIL

This topic is 3607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was using DevIL to load a ppm image which was rendered by a ray tracer. For testing purpose I set up a project only for presenting the image. Image loading was fine, however what the glut windows showed was only blank stuff. Can someone please tell how to fix this problem? Thanks! Please see include code: In displayImage.cpp: ILboolean displayImage::Setup() { glEnable (GL_TEXTURE_2D); glMatrixMode (GL_PROJECTION); glLoadIdentity (); ilutRenderer (ILUT_OPENGL); TexID = ilutGLBindTexImage(); ilDeleteImages(1, &ImgId); glOrtho(0, m_iWidth, m_iHeight, 0, -1, 1); // Set up an orthographic projection with OpenGL. return IL_TRUE; } void displayImage::CleanUp( void ) { if (!bCleaned) glDeleteTextures (1, &TexID); bCleaned = IL_TRUE; } void displayImage::loadImage( char *cFileName ) { m_cFileName = cFileName; if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION || iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION || ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) { printf ("DevIL library is out of date! Please upgrade\n"); } ilInit (); ilEnable (IL_CONV_PAL); ilutEnable (ILUT_OPENGL_CONV); ilGenImages (1, &ImgId); ilBindImage (ImgId); if (!ilLoadImage (m_cFileName)) { HandleDevILErrors (); } m_iWidth = ilGetInteger (IL_IMAGE_WIDTH); m_iHeight = ilGetInteger (IL_IMAGE_HEIGHT); if (m_iWidth > 0) { if (m_iWidth > MAX_X) { m_iWidth = MAX_X; m_iHeight = (ILuint)(MAX_X / (ILfloat)ilGetInteger(IL_IMAGE_WIDTH) * m_iHeight); } } if (m_iHeight > 0) { if (m_iHeight > MAX_Y) { m_iHeight = MAX_Y; m_iWidth = (ILuint)(MAX_Y / (ILfloat)ilGetInteger(IL_IMAGE_HEIGHT) * m_iWidth); } } HandleDevILErrors (); } void displayImage::drawImage() { glClear(GL_COLOR_BUFFER_BIT); glBindTexture (GL_TEXTURE_2D, TexID); glBegin (GL_QUADS); glTexCoord2f (0.0f, 0.0f); glVertex3i (0, 0, 0); glTexCoord2f (1.0f, 0.0f); glVertex3i (m_iWidth, 0, 0); glTexCoord2f (1.0f, 1.0f); glVertex3i (m_iWidth, m_iHeight, 0); glTexCoord2f (0.0f, 1.0f); glVertex3i (0, m_iHeight, 0); glEnd(); } ******************************************************************** In main.cpp: void init( int argc, char* * argv ) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition (100, 100); glutInitWindowSize (640, 480); } void DisplayFunc() { display.loadImage("out.ppm"); if (display.Setup() == IL_FALSE) { cout << "Display could not be set up!" << endl; exit; } display.drawImage(); glutSwapBuffers(); } int main(int argc, char* argv[]) { init(argc, argv); Window = glutCreateWindow("Shanshan's Display Test"); glutDisplayFunc(DisplayFunc); glutKeyboardFunc (KeyboardFunc); glutMainLoop(); display.CleanUp(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!