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:
GLubyte *scramble_bitmap;
I read in the bitmap (stored as raw RGB data in a file):
//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++;
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.
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.
GLubyte *scramble_bitmap;
I read in the bitmap (stored as raw RGB data in a file):
//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++;
Originally posted by blood.angel:
[b]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.
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).]
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);
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.
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…
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.
When you say you read a byte at a time, do you use getc()?
Not sure about this either (abandoned C style I/O quite some time ago), but getc() may be a function related to text mode input, which can cause trouble with binary data.
Try read a byte at a time with fread(), with a size of 1 instead.
Raw files doesn’t have any header. They are, as the name says, raw data.
And it seems like you are talking about a specific format, without mention which format it is. Not all formats look the same, not all have an “offset” field in the header, and not all have a palette.