PDA

View Full Version : glBitmap or glRasterPos problem?



zero_t9
04-07-2005, 05:54 PM
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;
}

plasmonster
04-08-2005, 06:24 PM
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 ;)

zero_t9
04-08-2005, 07:06 PM
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).

plasmonster
04-08-2005, 07:10 PM
For most any state in OpenGL, glGet* is the ticket.

For unpack, use:

GLint alignment;
glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );

zero_t9
04-08-2005, 07:15 PM
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:
For most any state in OpenGL, glGet* is the ticket.

For unpack, use:

GLint alignment;
glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );

plasmonster
04-08-2005, 08:41 PM
Hey TSB, As for the unpack stuff, it's easier (for me, anyway :) ) 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 ;)

[edit: correction]

plasmonster
04-08-2005, 09:04 PM
I'm working on one mental leg tonight, so I'll bid you a very good night my friend.