help! I’m getting very distressed
I’ve been trying for a while to overlay some text onto a rendered scene with no success. So in a fit of desperation, I tried to get hold of the code for defining a complete font, example 8_2 of the OpenGL Programming Guide, unfortunatley it wasn’t where it said it should be in the book, so I keyed it in.
In order to get it to compile ( using VC++ ) I had to uninclude gl.h and glu.h - why I don’t know. However perhaps as a result, when I run this program, nothing appears on my screen!
I hoped this would be a simple library that I could steal and use to overlay text on my rendered scene, so if anyone can shed any light on why it’s not working, I would be most grateful.
Below is the code as I have keyed it in, I can’t see any significant differences ( aside from the fact that all my char’s are A ) between this and the book.
thanks in advance folks…
james
CODE:
OpenGL Programming Guide example 8_2 : Defining a complete font
//#include <Gl/gl.h>
//#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <string.h>
GLubyte space[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
GLubyte letters[][13] =
{
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 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 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 },
{ 0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18 }
};
GLuint fontOffset;
void makeRasterFont(void )
{
GLuint i,j;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
fontOffset = glGenLists(128);
for ( i = 0, j = 'A'; i < 26; i++, j++ )
{
glNewList(fontOffset + j , GL_COMPILE);
glBitmap(8,13,0.0,2.0,10.0,0.0,letters[i]);
glEndList();
}
glNewList(fontOffset + ' ' , GL_COMPILE);
glBitmap(8,13,0.0,2.0,10.0,0.0,space);
glEndList();
}
void init (void)
{
glShadeModel(GL_FLAT);
makeRasterFont();
}
void printString( char *s )
{
glPushAttrib(GL_LIST_BIT);
glListBase(fontOffset);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s );
glPopAttrib();
}
void display(void)
{
GLfloat white[3] = { 1.0,1.0,1.0 };
glClear(GL_COLOR_BUFFER_BIT);
glColor3fv(white);
glRasterPos2i(20,60);
printString("the quick brown fox jumps");
glRasterPos2i(20,40);
printString("over the lazy dog");
glFlush();
}
void reshape(int w, int h )
{
glViewport(0,0,(GLsizei) w, (GLsizei) h );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (0.0, w, 0.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(300,100);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}