image format

This is a discussion on image format within the Game Programming forums, part of the General Programming Boards category; I know I just asked eariler about bmps and said that I din't want to use SDL, well png's were ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    image format

    I know I just asked eariler about bmps and said that I din't want to use SDL, well png's were annoying me because of the lack of documentation on the function I needed so I started sdl. I want to load a heightmap, the picture I want to use is a tga. I said screw that and converted it to bmp. I loaded the code from NeHe using the SDL_LoadBMP function(it works on their picture), but it seg faults on my picture. I even wrote my own bmp and cut the image from the tga and then pasted it on my bmp. gimp said its thing and did the conversion. No avail. Here is the code that doesn't work on my image, but on Nehe's it does
    Code:
    int tl(void){
            int status=0;
            SDL_Surface *TextureImage[1];
            if((TextureImage[0]=SDL_LoadBMP("/home/michael/temp/lesson-6/lesson06/da
    ta/nehe.bmp"))){/*their picture*/
                    status=1;
                    glGenTextures(1,&texture[0]);
                    glBindTexture(GL_TEXTURE_2D,texture[0]);
                    glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->w,TextureImage[0
    ]->h,0,GL_BGR,GL_UNSIGNED_BYTE,TextureImage[0]->pixels);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
            }
            if(TextureImage[0])
            SDL_FreeSurface(TextureImage[0]);
            return status;
    }
    I feel like a beginner, where hello world doesn't work. If anything does anyone here have a heightmap that is a bmp?
    [edit]If i edit out the glTexImage2D function it doesn't seg, but of course no texture. What would cause it?
    Last edited by linuxdude; 08-07-2004 at 03:34 PM.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    perhaps gimp is being intelligent and storing your BMP as an 8-bit (gray-scale) image (it doesnt have colours, right?). your telling OGL that each pixel has 3 colours, when there may be just 1.

    either try explicitly making gimp store the image as a 24-bit bmp, or try loading the texture as an 8-bit bmp, something like this maybe...

    glTexImage2D(GL_TEXTURE_2D, 0 , 1, TextureImage[0]->w,TextureImage[0]->h,0,GL_BGR,GL_UNSIGNED_BYTE,TextureImage[0]->pixels);

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    the GL_LUMINANCE(1) worked. thanks

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    i hate file formats, why are they so complicated. Well here is where I am now. I want to go through an image pixel by pixel with SDL their structure is like this SDL_Surface now They have a snippet of code to do what I want but it doesn't work
    Code:
         SDL_Surface *surface;
         SDL_PixelFormat *fmt;
         SDL_Color *color;
         Uint8 index;
         /* Create surface */
         fmt=surface->format;
         /* Check the bitdepth of the surface */
         if(fmt->BitsPerPixel!=8){
              fprintf(stderr, "Not an 8-bit surface.\n");
              return(-1);
         }
         /* Lock the surface */
         SDL_LockSurface(surface);
         /* Get the topleft pixel */
         index=*(Uint8 *)surface->pixels;
         color=fmt->palette->colors[index]; /*this line(the one i need doesn't work*/
         /* Unlock the surface */
         SDL_UnlockSurface(surface);
         printf("Pixel Color-> Red: %d, Green: %d, Blue: %d. Index: %d\n",
                   color->r, color->g, color->b, index);
    SDL_Color *colors; is a pointer to type SDL_Color, it isn't even an array of poitners(for each pixel) What do I do?

  5. #5
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    i hate file formats, why are they so complicated.
    the formats are usually complicated in the interest of being expandable and adding features people might want to use. for example the TGA format is fairly easy , but in the latter versions at the end of file there are fields of bytes dedicated to the identification of the maker of the TGA image(i.e. copyright info) and other somewhat useful features. By far if you want a simple image format BMP is it. only has two headers and then you only have to remember that in order to use a bmp it has to be DWORD padded(padded so that each line is DWORD divisible).

    Also I gather from the link you gave that an instance of SDL_Surface is automatically configured to have the right format/pixel pointers? Also , what exactly is your problem with the code beyond the fact that it apparently doesnt work?
    there used to be something here, but not anymore

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    There is no need to store 3 color values per pixel in a heightmap. You only need 1 value so store them as 8-bit RAW files. Heck you could make up your own RAW file format where the first two DWORDs of information would be the height and width followed by the RAW height values.

    If your height values are bytes then this would make for some very small files and very fast load times. Also it would make smoothing and bilinear filtering of the heights a lot faster. And note that your heights should be BYTEs not WORDs or DWORDs. Your perspective projection will bring out the slight differences in height, plus you can scale the heights into WORDs or DWORDs later.


    I store all my heightmaps as RAW images, including the ones I used for my polygon terrain and my voxel terrain.
    BMPs are only useful for the textures and/or color maps if you are using one. Even using 8-bit BMPs is a pain in the arse although not really hard...just a pain. Simplify it and move to RAW.


    You want to store your heights as grey scale images in planar mode. Convert your height maps into 8-bit grey-scales and save as a planar RAW file with no header information. Some programs allow you to specify empty bytes prior to the image information so you can insert your own header.
    Last edited by VirtualAce; 08-09-2004 at 10:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 05:17 AM
  2. What image format to use?
    By Kennedy in forum Tech Board
    Replies: 21
    Last Post: 10-16-2006, 09:10 AM
  3. Convert Pdf to Image format!
    By Dilmerv in forum C# Programming
    Replies: 4
    Last Post: 05-22-2006, 11:31 PM
  4. Reading text in an Image format
    By loko in forum C Programming
    Replies: 0
    Last Post: 09-29-2005, 07:38 PM
  5. Replies: 4
    Last Post: 03-02-2003, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21