Jump to content
  • Advertisement
Sign in to follow this  
CodeMonkey2000

OpenGL Binding PCX images in openGL (with SDL)

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

Hey guys. I'm trying to bind PCX images in openGL. I load the image with SDL_image. But when I try to bind it, it doesn't work, I just get blank polygons. When I change the third parameter of glTexImage2D to 3, I get an error. I know that SDL_image can load PCX, since I have already loaded them, and blit them. All other image formats work except for PCX. Tga,bmp ad jpeg work fine. Here is how I load the image.
    SDL_Surface *TextureImage;
    TextureImage=IMG_Load(name);
    if (TextureImage!=NULL)
    {
	    glGenTextures( 1, &texture);
	    glBindTexture( GL_TEXTURE_2D, texture);
	    glTexImage2D( GL_TEXTURE_2D, 0, 0,
                    TextureImage->w,
                    TextureImage->h,
                    0, GL_RGB,
                    GL_UNSIGNED_BYTE,
                    TextureImage->pixels );

	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    }
    SDL_FreeSurface( TextureImage);
Anyone know why openGL dislikes PCX loaded from SDL? [Edited by - CodeMonkey2000 on August 2, 2008 10:57:11 AM]

Share this post


Link to post
Share on other sites
Advertisement
 SDL_Surface *TextureImage;
TextureImage=IMG_Load(name);
SDL_PixelFormat *fmt;
fmt=TextureImage->format;

cout<<(int)fmt->BitsPerPixel<<"\n";


Ok, I found out that PCX images have 8 bpp. All the other formats have 24 or more, so using GL_BGR access invalid memory locations.

SIDE NOTE: Now that I look at it, the PCX loader from cone3D doesn't work on my computer either. It just freezes, doesn't give me an error.

[Edited by - CodeMonkey2000 on August 2, 2008 1:11:22 PM]

Share this post


Link to post
Share on other sites
PCX uses a 8bit color index "system", and the image file should contain a look-up table for the 256 colors available to index.

I think OpenGL might support color indexed textures, but I have never used it. If not, it is possible to generate 24 bit rgb data from the 8bit indicies and the lookup table...

Or you could just convert the PCX files in an image converter to something more useful

Share this post


Link to post
Share on other sites
Ok I converted all my images. Most of them work. But now openGL doesn't like the images with widths and heights that aren't a power of 2 (eg 400x200 =bad). Anyone know how to fix that?

Share this post


Link to post
Share on other sites
GL_TEXTURE_2D only supports sizes that are power of 2. The easyest way to fix that is to rescale your images before you upload them to OpenGL.

You could also use padding; for a 400x200 image, make a 512x256 and just ignore the unused pixels. If you do this, you must modify your texture coordinates, and tiling in no longer possible.

Alternatively, you could use GL_TEXTURE_RECT which supports any size, however there are restrictions:

* First of all, texture coordinates are different. GL_TEXTURE_2D uses 0~1 range regardless of the actual size. GL_TEXTURE_RECT uses 0~[(width or height in pixels)].

* Some cards may not support GL_LINEAR and mipmaps. Fragment shaders will also have to be modified, e.g. cg shaders will use texRECT instead of tex2D.

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!