glBitmap or glRasterPos problem?

Hi,

I have a program as attached. My purpose is to test glRasterPos. It turns out the result at

http://www.geocities.com/shaobin_tao/glRasterPos.bmp

is wrong. According to the docs, I should get the right pixels instead of the left one. Am I mistaken? Thanks very much for your help.

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

GLubyte fire[8] = { 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xff };

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);

glRasterPos2f(8.0,8.0);
glBitmap( 8, 8, 0, 0, 20, 20, fire );
glFlush();
}

void myinit (void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void myReshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, 0, h);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}
int main(int argc, char** argv)
{
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
glutInitWindowPosition (0, 0);
glutInitWindowSize(100,100);
glutCreateWindow(argv[0]);
myinit();
glutReshapeFunc(myReshape);

glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Try adding glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) to your “myInit” function (the default is 4).

Here’s the spec on glBitmap:
http://www.mevis.de/~uwe/opengl/glBitmap.html

Note the dependency on glPixelStore :wink:

Graham:

it works. thanks for your help. BTW, how do I determine the alighment type?

[QUOTE]Originally posted by graham:
[QB]Try adding glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) to your “myInit” function (the default is 4).

For most any state in OpenGL, glGet* is the ticket.

For unpack, use:

GLint alignment;
glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );

Graham, Hi:

I guess I did not explain well. My question is why I should use 1 for GL_UNPACK_ALIGNMENT instead of 4 for
GLubyte fire[8] = { 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff, 0xff }?

Does the alignment refers to my image data size? if I define GLint fire[8]={…}, should GL_UNPACK_ALIGNMENT be 4 then(assuming sizeof(int) = 4)?

Originally posted by graham:
[b]For most any state in OpenGL, glGet* is the ticket.

For unpack, use:

GLint alignment;
glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );[/b]

Hey TSB, As for the unpack stuff, it’s easier (for me, anyway :slight_smile: ) if you simply read the spec on this stuff. There are several factors that affect pixel rectangles, and they’re all beautifully summerized in the OpenGL 2.0 specification (the unpack stuff starts on page 129). Get used to reading this thing, you’ll be spending a lot of time in it :wink:

[edit: correction]

I’m working on one mental leg tonight, so I’ll bid you a very good night my friend.