# Raster text rendering failing in freeglut

This topic is 3123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all. I'm new to low-level languages, C++, OGL, and glut; so doubtlessly this is just me making a newb mistake, but for the life of me I can't track that mistake down. I start a simple HelloWorld script to try and learn the glut raster text drawing system, and despite compiling without a fuss the text doesn't seem to want to render. Perhaps one of you kind programmers can point me in the right direction?
#include <GL/freeglut.h>
#include <stdlib.h>

/* GLUT callback Handlers */

static void
resize(int width, int height)
{
const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
}

/* The drawing bit */

static void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* Drawing the problem text */

glRasterPos2i(100,100);
glColor4b(0,0,0,255);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24,(const unsigned char*)"Hello, World!");

glutSwapBuffers();
}

/* To exit */
static void
key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
}

glutPostRedisplay();
}

static void
idle(void)
{
glutPostRedisplay();
}

int
main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("Txt0r");

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);

glClearColor(1,1,1,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glutMainLoop();

return EXIT_SUCCESS;
}


##### Share on other sites
Gah, spending more time with the code I see I've misunderstood where glRasterPos starts, rendering it off projection. In my defence, I started with glRasterPos2i[0,0], and it now looks like another unposted projection element stopped it from rending that time.

Anywho, newbie problem solved.

• 33
• 15
• 23
• 10
• 19