I have a doubt trying to understand and use glBitmap function. I started from this example and trying to draw a 40x40 "bitmap" and avoiding a situation like this I tried this:
40 x 40 is 1600 bits -> so I need 200 bytes of info (1600/8)
GLubyte rasters[ 200 ] =
{
0xff, 0xff, //.. and so on 200 times
};
// main code calling the function below
void display(x, y)
{
float size = 40.0;
glColor3f( 0.0, 1.0, 0.0 );
glRasterPos2i(x, y );
glBitmap(size, size, 0.0, 0.0, 0.0, 0.0, rasters );
}
I was expected to draw a fully green square 40 x 40 pixel. Turns out that I met the unwanted situation instead with the dirty upper part of the square. It seems that raster[200]
is enough to draw only a 32 x 32 bitmap. So what I would like to ask:
You missed to set the alignment. By default OpenGL assumes that the start of each row of the raster is aligned to 4 bytes. This is because the GL_UNPACK_ALIGNMENT
parameter by default is 4. Each row in the raster has 5 bytes (40 / 8 = 5). Therefore you need to change the alignment to 1:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBitmap(size, size, 0.0, 0.0, 0.0, 0.0, rasters);