This topic is now archived and is closed to further replies.


OpenGL OpenGL homemade BMP - problem with the width ?

Recommended Posts

Ive been playing with bitmaps in opengl lately but theres one thing that is really frustrating me. First of all, I was able to open a bmp file and display it correctly using glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, bmpData); here, the width and height were both 256, since that was the size of the bitmap on my computer. I wanted to grab a sub-chunk of the above loaded bitmap and display it separetly. For example, the top left quadrant of the bitmap, which would be 128 x 128 pixels. I wrote code to store the bitmap data in an array that was 128*128*3 bytes big. (the 3 is because its a 24 bit bitmap, and each pixel actually needs 3 bytes of data to store the color info). After this array was completed, I again made a call to glDrawPixels in an attempt to draw this newly generated bitmap part. However it displays the bitmap with all kinds of wierd horizontal lines as if each row was off by one or more pixels. I found that the only way to display my bitmap correctly was to use either 128-1 for the width OR 128-1 for the height. For example: glDrawPixels(width - 1, height, GL_RGB, GL_UNSIGNED_BYTE, bmpData); This is really frustrating because I thought I understood what I was doing, and now thats all gone out the window. Why in the world would I need to subtract one from the width (or height), like I am doing? Many thanks to anyone who can help me!

Share this post

Link to post
Share on other sites