When I run this 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(&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.