Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Bitmap problem in OpenGL

  1. #1
    Member Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    93

    Bitmap problem in OpenGL

    Im trying to do a console OpenGL and have a 2D image display on the sceen at all times. My problem is that its garbled when it appears on the screen. my code is as follows:

    I declare the bitmap as follows:
    Code :
    GLubyte *scramble_bitmap;
    I read in the bitmap (stored as raw RGB data in a file):
    Code :
    //now read in the scramble bitmap
    	if( (input  = fopen("scramble2.raw", "r")) == NULL )
    	{
    		exit(0);
    	}
    	else
    	{
    		count = 0;
    		scramble_bitmap = (GLubyte *) calloc(7350, sizeof(GLubyte));//70x35x3 bytes, size of scramble bitmap
    		while (!feof(input))
    		{
    			scramble_bitmap[count] = getc(input);
    			count++;
     
    		}
     
    	}
     
    	fclose (input);
    And I draw the thing to screen by:
    Code :
    glRasterPos3f(0.0, 0.0, 6.0 );
    	glDrawPixels(70, 35, GL_RGB, GL_UNSIGNED_BYTE, scramble_bitmap);
    Anyone help?

  2. #2
    Member Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    93

    Re: Bitmap problem in OpenGL

    Maybe Im describing it wrong.
    Im trying to draw a bitmap image saved as a stripped header .raw file (only contains RGB values) on the bottom left hand corner of the camera viewpoint.
    I draw the scene as normal and point the camera. Now I want to draw the bitmap after this is done. And I cant find any good tutorials (or bad ones matter of fact ).
    so please can anyone point me in the right direction.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Bitmap problem in OpenGL

    This could be your problem: Is the size of your image in the power of 2?
    Look's like it is not, I know for a texture map's you have to do it this why....could be diffrent for bitmap image with drawpixels

    example: 64 x 64, 64 x 32, 256 x 128.

    Other thing could be that you are not reading in the file corectly.




    Code :
    GLubyte *scramble_bitmap;
    I read in the bitmap (stored as raw RGB data in a file):
    Code :
    //now read in the scramble bitmap
    	if( (input  = fopen("scramble2.raw", "r")) == NULL )
    	{
    		exit(0);
    	}
    	else
    	{
    		count = 0;
    		scramble_bitmap = (GLubyte *) calloc(7350, sizeof(GLubyte));//70x35x3 bytes, size of scramble bitmap
    		while (!feof(input))
    		{
    			scramble_bitmap[count] = getc(input);
    			count++;
     
    		}
     
    	}
     
    	fclose (input);
    And I draw the thing to screen by:
    Code :
    glRasterPos3f(0.0, 0.0, 6.0 );
    	glDrawPixels(70, 35, GL_RGB, GL_UNSIGNED_BYTE, scramble_bitmap);
    Anyone help?[/B]<HR></BLOCKQUOTE>



    [This message has been edited by nexusone (edited 04-16-2002).]

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Bitmap problem in OpenGL

    For some good tutor's:

    nehe.gamedev.net




    Originally posted by blood.angel:
    Maybe Im describing it wrong.
    Im trying to draw a bitmap image saved as a stripped header .raw file (only contains RGB values) on the bottom left hand corner of the camera viewpoint.
    I draw the scene as normal and point the camera. Now I want to draw the bitmap after this is done. And I cant find any good tutorials (or bad ones matter of fact ).
    so please can anyone point me in the right direction.


  5. #5
    Member Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    93

    Re: Bitmap problem in OpenGL

    Thanks nexusone, I resized the bitmap to 64x32 and changed the values accordingly in the program.
    But now it displays the bottom half of the bitmap correct only, while the top half is all black.
    WTF?

    [This message has been edited by blood.angel (edited 04-16-2002).]

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Bitmap problem in OpenGL

    Textures need to be a power of 2, but when using glDrawPixels, the dimensions don't matter.

    When you say that it's a bitmap file with the header stripped do you mean that you literally took a BMP and took out the header? If that's the case, I believe BMP files actually store their data in BGR format, not RGB.

    Also, you might want to try using the following...
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    Deiussum
    Software Engineer and OpenGL enthusiast

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Bitmap problem in OpenGL

    I'm not sure about it, but I believe fopen() will open the file in text mode if you don't explicitly tell it to open in binary mode. Try replace "r" in fopen() with "rb". Then, when reading the map, read the entire file in one go instead, since you know how large it is. Something like this.
    Code :
    if((input = fopen("scramble2.raw", "rb")) == NULL)
    {
    	exit(0);
    }
    else
    {
    	scramble_bitmap = (GLubyte *)calloc(7350, sizeof(GLubyte));
    	fread(scramble_bitmap, 7350, input);
    	fclose (input);
    }

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: Bitmap problem in OpenGL

    Just do some printf's to see if it is reading the data in correctly. To test you opengl code try and draw a ramp

    for(j=0;j<height;j++)
    for(i=0;i<width;i++)
    {
    image[(j*width) + i].r = (255/width) * i;
    image[(j*width) + i].g = 0;
    image[(j*width) + i].b = 0;
    }

  9. #9
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: Bitmap problem in OpenGL

    Yeah, when opening and reading a bitmap, you must do it as binary... In the case of .raw files, it is more standard to use binary, although in gamedev.net's tutorials are saved in plane text... Why? I dont know...

    fopen(file, "rb");

    fopen opens docs as plain text by default...

  10. #10
    Member Contributor
    Join Date
    Nov 2001
    Location
    Ireland
    Posts
    93

    Re: Bitmap problem in OpenGL

    Thanks bob and the rest of you.

    I got it sorted thanks to your help, but I find it weird. If I read the entire file in one go it works fine, but when I read it a byte at a time it only displays half the image and the rest black.

    Thank you again.

Page 1 of 2 12 LastLast

Similar Threads

  1. Funny Bitmap Problem
    By rmmlg in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-17-2005, 02:23 AM
  2. Problem: Opengl Fonts and Bitmap
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-14-2004, 10:05 AM
  3. Replies: 3
    Last Post: 01-16-2004, 08:33 AM
  4. Problem with Bitmap fonts in OpenGL!
    By flare in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-13-2004, 12:33 AM
  5. Replies: 4
    Last Post: 03-25-2001, 05:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean