Jump to content
  • Advertisement
Sign in to follow this  
pjs

Displaying bmp files with OpenGL and SDL

This topic is 4849 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

Totally frustrated. Here's the simplified code: // Load the graphic; convert to display surface's format. SDL_Surface *bfile; bfile = SDL_LoadBMP("test.bmp"); bfile = SDL_DisplayFormat(bfile); // Set the GL raster position and draw the image. glRasterPos2i(100,100); glDrawPixels(bfile->w, bmpfile->h, GL_RGB, GL_BYTE, bfile->pixels); The image I see on the screen is upside down (and perhaps mirrored). In addition, the color is all wrong. I have the admit that the "GLenum type" parameter to glDrawPixels() was a complete guess. I really have no idea what to put there, although it *seems* like I should be requesting that information from SDL, since (after the call to SDL_DisplayFormat) SDL knows what the display format for the SDL_Surface holding the image is (it's the same as the display format for the main window). But suppose I *hadn't* converted the format of bfile to the format of the main window. How could I possibly know the pixel type if I'm not the author of the bmp file? Do all bmp files have the same pixel format? This seems like it should be easy. Help? Thanks! Pete

Share this post


Link to post
Share on other sites
Advertisement
Using glDrawPixels will propably result in horrible performance. You should rather just texture a quad if you want to display images. Here's NeHe's OpenGL Lesson #6, where he shows how to texture things. You can download the Linux/SDL code to see how it would be done with SDL. I don't know what OS you use, but the Linux/SDL code should work on all OS's with SDL. Hope this is of any help to you.

Share this post


Link to post
Share on other sites
Point taken, but I guess I'm more interested in really getting a good understanding of OpenGL and SDL than taking the pragmatic approach. :)

The NEHE lesson did reveal (partially) why the bmp is mirrored, although his "fix" is to swap coordinates in glTexCoord2f() rather than re-express the file with the correct pixel format.

Share this post


Link to post
Share on other sites
For the image format, try GL_BGR_EXT. Bitmaps are stored in BGR order, and SDL may not be fixing that.

You'll might an extension loader or glext.h in order to access GL_BGR_EXT, and if so, I suggest GLee.

Share this post


Link to post
Share on other sites
the other way is to place glPixelZoom function with -1 for y factor and 1 for x factor:

glPixelZoom(1, -1);

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
For the image format, try GL_BGR_EXT. Bitmaps are stored in BGR order, and SDL may not be fixing that.

You'll might an extension loader or glext.h in order to access GL_BGR_EXT, and if so, I suggest GLee.


Alternatively you could use the SDL_GL_GetProcAddress() function to load extensions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Will F
Alternatively you could use the SDL_GL_GetProcAddress() function to load extensions.


That won't help. It's a #define'd constant. There are no extension functions to request the address of.

Share this post


Link to post
Share on other sites
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!