Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Printing characters: help a newb!

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2004
    Posts
    4

    Printing characters: help a newb!

    When I run this code:
    Code :
    #include <stdio.h>
    #include <cstdlib>
    #include <stdlib.h>
    #include <algorithm>
    #include <wchar.h>
    #include <string>
    #include <windows.h>
    #include <GL/glut.h>    
    #include <GL/gl.h>	
    #include <GL/glu.h>
    #include <game.hpp>
     
    using namespace std;
     
    // Non-specific functions
    int randomRange(int lowestNumber, int highestNumber)
    {
     if(lowestNumber > highestNumber)
      swap(lowestNumber, highestNumber);
     int range = highestNumber - lowestNumber + 1;
     return lowestNumber + int(range * rand()/(RAND_MAX + 1.0));
    }
     
    void printText(int startPosX, int startPosY, string text, float r, float g, float b) 
    {
     int y = startPosY;
     int x;
     int fontWidth = 8;
     for (int i=1; i<=text.length(); i++)
     {
      x = startPosX + (i-1)*(fontWidth);
      glColor3f(r,g,b);
      glRasterPos2i(x,y);
      glutBitmapCharacter(GLUT_BITMAP_8_BY_13, text[i-1]);
     }  
    }
    // End Non-specific functions
     
    void displayDifficulty(void)
    {
     glClear(GL_COLOR_BUFFER_BIT);
     string titleText("Asteroids - by Evan Patterson");
     string difficultyText("Press the coresponding number to select the difficulty");
     string difficulty1Text("1 -- What's Asteroids, anyway?");
     string difficulty2Text("2 -- I've played once or twice...");
     string difficulty3Text("3 -- I'm pretty darn good");
     string difficulty4Text("3 -- I'm master, bring it on!");
     printText(300, 150, titleText, 1.0, 1.0, 1.0);
     printText(300, 170, difficultyText, 1.0, 1.0, 1.0);
     printText(300, 180, difficulty1Text, 1.0, 1.0, 1.0);
     printText(300, 190, difficulty1Text, 1.0, 1.0, 1.0);
     printText(300, 200, difficulty1Text, 1.0, 1.0, 1.0);
     printText(300, 200, difficulty1Text, 1.0, 1.0, 1.0);
     glutSwapBuffers();
    }
     
    void keyboardDifficulty(unsigned char key, int x, int y)
    {
     if (key == 49)
      Game::Game theGame(1); 
     if (key == 50)
      Game::Game theGame(2);
     if (key == 51)
      Game::Game theGame(3);
     if (key == 52)
      Game::Game theGame(4);
     if (key == 27)
      exit(0);
    }
     
    void reshape(int w, int h)
    {
     glViewport (0, 0, (GLsizei) w, (GLsizei) h);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glOrtho(0, 800, 0, 600, 0, 0);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
    }
     
    void init(void)
    {
     glClearColor(0.0, 0.0, 0.0, 0.0);
     ShowCursor(FALSE);
     glutDisplayFunc(displayDifficulty);
     glutKeyboardFunc(keyboardDifficulty);
     glutReshapeFunc(reshape);
     glShadeModel(GL_FLAT);
    }
     
    int main(int argc, char** argv)
    {
     glutInit(&amp;argc, argv);
     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
     glutInitWindowSize(800, 600);
     glutInitWindowPosition(100, 100);
     glutCreateWindow("Asteroids by Evan Patterson");
     glutFullScreen();
     init();
     glutMainLoop();
     return 0;
    }
    I don't get an error, but the text is not displayed on the screen. I've used the printText function in previous programs and it has worked like a charm. Does anyone know how I might fix this problem?
    Thanks in advance.

  2. #2
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: Printing characters: help a newb!

    Try a range of depth values in the Ortho() call, like

    glOrtho(0, 800, 0, 600, -999, 999).

  3. #3
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: Printing characters: help a newb!

    Also, consider calling a function like this after a suspicious block of code. This may help you isolate problem code faster.

    Code :
    void checkGL( const char* msg = "GL ERROR" )
    {
        GLenum error = glGetError();
        if( error != GL_NO_ERROR )
            printf( "%s: %s\n", msg, gluErrorString(error) );
    }

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2004
    Posts
    4

    Re: Printing characters: help a newb!

    Thanks Q, got it working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •