Jump to content
  • Advertisement
Sign in to follow this  
Nigholith

Raster text rendering failing in freeglut

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

If you intended to correct an error in the post then please contact us.

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);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

/* 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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!