8Bit Bitmaps Problem

This is a discussion on 8Bit Bitmaps Problem within the Game Programming forums, part of the General Programming Boards category; I found a function on the 'net which is supposed to load an 8bit bitmap and display it. I think ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    8Bit Bitmaps Problem

    I found a function on the 'net which is supposed to load an 8bit bitmap and display it. I think the problem is it loads it but doesn't display it - if this is the case, could somebody tell me how I should display it?

    Here it is:

    Code:
    /* LoadBMP(): Loads an 8bit Bitmap */
    int LoadBMP (char *filename)
    {
    	 FILE *BMPFile;
    	  unsigned char c, Palette[256][4];
    	  unsigned int  offset, lines, paddedWidth;
    
    	  /* This checks for the file */
    	  BMPFile = fopen(filename, "rb");
    
    	  if (BMPFile == NULL)
    	  {
    			printf("Cant open file.");
    			return 1;
    	 }
    
    	 /* Read the header information */
    	  fread(&Header, 54, 1, BMPFile);
    
    	  if (Header.bfType != 19778 || Header.bfReserved != 0 || Header.biPlanes != 1)
    	{
    			    /* Not a valid bitmap file - don't display */
    			printf("Not a valid bitmap.");
    			fclose(BMPFile);
    			return 1;
    	}
    
    	  if (Header.biCompression != 0)
    	  {
    			/* Compressed file - don't display */
    			printf("Compressed file.");
    			fclose(BMPFile);
    			return 1;
    	 }
    
    	  if (Header.biBitCount != 8)
    	  {
        			/* If the file is other than 8-bit dont read. */
    			printf("Not an 8-bit bitmap.");
    			fclose(BMPFile);
    			return 1;
    	 }
    
    	  if (Header.biWidth > 320 || Header.biHeight > 200)
    	  {
    			 /* If its larger than 320*200 dont load. */
    			printf("Size too large.");
    			fclose(BMPFile);
    			return 1;
    	 }
    
    	  /* Load the palette info */
    	  fread(&Palette, 1024, 1, BMPFile);
      
    	  for (c = 0; c < 255; c++)
    			SetDAC(c, Palette[c][2] >> 2, Palette[c][1] >> 2, Palette[c][0] >> 2);
    	
    	    offset = (100 + (Header.biHeight >> 1)) * 320 + 160 - (Header.biWidth >> 1);
    	  lines = 0;
    	  paddedWidth = Header.biWidth & 0xFFFC;
      
    	  if (Header.biWidth != paddedWidth)
    			   paddedWidth += 4;
    
    	 /* Loop for reading lines */
    	  while (lines < Header.biHeight)
    	  {
    			 fread(VideoRAM + offset, paddedWidth, 1, BMPFile);
    			offset -= 320;
    			lines++;
    	 }
    
    	  fclose(BMPFile);
    	  return 0;
    }
    Sorry about the spazzy layout, I copied and pasted it from my IDE.
    It's probably a really n00bish problem
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    http://nehe.gamedev.net/lesson.asp?index=02

    8bit Bitmaps arent supported by OpenGL
    only 64 128 and 256 no wait oops talkin bout image sizes dumb but in case you wanna know you have to MipMap to get around that
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I'm not programming in OpenGL, it's DOS Mode 13h [320x200x256].
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Then try here.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  2. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 07:34 PM

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