Hello,
I am having trouble with the glBitmap() function. I have no problem when drawing bitmaps as outlined in the redbook chapter8. What I have problem with is rendering 3D meshes and drawing bitmaps. The seem to disappear permanently after certain glut calls. Here is an example:
GLubyte rasters[24] = {
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xff, 0x00,
0xff, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xff, 0xc0,
0xff, 0xc0};
void init(void) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0, 1.0, 1.0, 0.5);
glRasterPos2i(40, 40);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glFlush();
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, 0, h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27: exit(0);
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100, 100);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
This code will draw 3 bitmaps (F’s) onto the screen fine. The problem I am having however, is the gl state is in no condition to render 3d objects at this point. So after modifying the code slightly…
GLubyte rasters[24] = {
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xff, 0x00,
0xff, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xc0, 0x00,
0xff, 0xc0,
0xff, 0xc0};
void init(void) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void display(void) {
glViewport(0, 0, (GLsizei) 100, (GLsizei) 100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 100, 0, 100);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0, 1.0, 1.0, 0.5);
glRasterPos2i(40, 40);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
glFlush();
}
void reshape(int w, int h) {
if(h == 0) h = 1;
// Set Viewport to window dimensions
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(15.0f, (GLfloat)w / (GLfloat)h, 0.01f, 9999999.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27: exit(0);
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(100, 100);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Now the bitmaps will not show up. The only thing I am really changing is the init() function to set things up for a mesh render, and then I am trying to change the state back in the display function so I can rasterize the bitmaps.
If anyone can help me solve this problem you would be curing a major headache for a stranger.
Thanks!