maybe something here will help i tried to stick to fairly relevent code
from mygl.h
#ifndef MyGL_H
#define MyGL_H
void renderStrokeString(float x, float y, float z, void *font, char
*input)
{
char *c;
glPushMatrix();
glTranslatef(x, y,z);
for (c=input; *c != '\0'; c++)
{
glutStrokeCharacter(font, *c);
}
glPopMatrix();
}
void renderBitmapString(float x, float y, float z, void *font, char
*input)
{
char *c;
glRasterPos3f(x, y, z);
for (c=input; *c != '\0'; c++)
{
glutBitmapCharacter(font, *c);
}
}
void renderBitmapString(float x, float y, float z, void *font, string
input)
{
glRasterPos3f(x, y, z);
for (int c = 0; input[c] != '\0'; c++)
{
glutBitmapCharacter(font, input[c]);
}
}
int bitmapStringWidth(void *font, char *input)
{
char *c;
int x = 0;
for (c=input; *c != '\0'; c++)
{
x += glutBitmapWidth(font, *c);
}
return x;
}
int bitmapStringWidth(void *font, string input)
{
int x = 0;
for (int c = 0; input[c] != '\0'; c++)
{
x += glutBitmapWidth(font, input[c]);
}
return x;
}
void delay(int milliseconds)
{
int oldTime = glutGet(GLUT_ELAPSED_TIME);
int newTime = glutGet(GLUT_ELAPSED_TIME);
int difference = newTime - oldTime;
while(difference < milliseconds)
{
newTime = glutGet(GLUT_ELAPSED_TIME);
difference = newTime - oldTime;
}
}
#endif
from myclasses.h
class button
{
public:
int x, y, height, width;
char *text;
void *font;
int text_x, text_y;
void centertext() { text_x = x + ( (width -
bitmapStringWidth(font,
text)) )/2; text_y = y + 20; }
bool mouse_over;
button() { set_coords(0, 0); set_text(GLUT_BITMAP_HELVETICA_18,
"Default"); height = 30; width =
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, text) + 20; }
button(int x1, int y1, void *font1, char *text1) {
set_coords(x1,
y1); set_text(font1, text1); height = 30; width =
bitmapStringWidth(font, text) + 20; }
void buttons(int x1, int y1, void *font1, char *text1)
{ set_coords(x1, y1); set_text(font1, text1); height = 30; width =
bitmapStringWidth(font, text) + 20; }
void set_coords(int x1, int y1) { x = x1; y = y1; }
void set_text(void *font1, char *input) { text = input, font =
font1; width = bitmapStringWidth(font, text) + 20; centertext(); }
void draw();
};
void button::draw()
{
glColor3f(0.0, 1.0, 0.0);
if( mouse_over == false)
{
glBegin(GL_LINE_LOOP);
glVertex2f(x, y);
glVertex2f(x, (y + height) );
glVertex2f( (x + width), (y + height) );
glVertex2f( (x + width), y);
glEnd();
renderBitmapString(text_x, text_y, 0, font, text);
}
else if(mouse_over == true)
{
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x, (y + height) );
glVertex2f( (x + width), (y + height) );
glVertex2f( (x + width), y);
glEnd();
glColor3f(0.0, 0.0, 0.0);
renderBitmapString(text_x, text_y, 0, font, text);
}
glColor3f(0.0, 1.0, 0.0);
}
#endif
from chase.h
. . .
void initgame();
char *itoa(int n);
void printboard();
void thirdroundtests();
//Globals:
ifstream ifile;
ofstream ofile;
const unsigned int ARRAY_COLUMNS = 11, ARRAY_ROWS = 11;
char board[ARRAY_ROWS][ARRAY_COLUMNS], character = 'o';
string names[10], names2[10], new_highscore = "", final_name = "";
int board2[ARRAY_ROWS][ARRAY_COLUMNS][2], pos[10], elapsedtime = 0,
restarttime = 0, wintime = 0, wini = 0,
highscores[10], highscores2[10], numhighscores = 0, place,
counter_name = 0;
bool round1comp = false, round2comp = false, gun = false, choice =
'\0', instructions = false, gameover = false,
restart = false, win = false, menu = true, game = false,
show_highscores = false, accepting_input = false, highscore = false,
prevhigh = false;
button button1( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"New Game") )/2, 180, GLUT_BITMAP_HELVETICA_18, "New Game"),
button2( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Instructions") )/2, 220, GLUT_BITMAP_HELVETICA_18, "Instructions"),
button3( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "High
Scores") )/2, 260, GLUT_BITMAP_HELVETICA_18, "High Scores"),
button4( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Quit") )/2, 300, GLUT_BITMAP_HELVETICA_18, "Quit"),
button5( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Back") )/2, 410, GLUT_BITMAP_HELVETICA_18, "Back"),
button6( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Menu") )/2, 320, GLUT_BITMAP_HELVETICA_18, "Menu"),
button7( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Restart") )/2, 360, GLUT_BITMAP_HELVETICA_18, "Restart"),
button8( (639 - bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
"Quit") )/2, 400, GLUT_BITMAP_HELVETICA_18, "Quit"),
button9( 450 + ( (640 - 450) -
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Menu") )/2, 320,
GLUT_BITMAP_HELVETICA_18, "Menu"),
button10( 450 + ( (640 - 450) -
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Restart") )/2, 360,
GLUT_BITMAP_HELVETICA_18, "Restart"),
button11( 450 + ( (640 - 450) -
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Quit") )/2, 400,
GLUT_BITMAP_HELVETICA_18, "Quit");
//:Globals
char* itoa (int n)
{
int i=0,j;
char* s;
char* u;
s= (char*) malloc(17);
u= (char*) malloc(17);
do{
s[i++]=(char)( n%10+48 );
n-=n%10;
}
while((n/=10)>0);
for (j=0;j<i;j++)
u[i-1-j]=s[j];
u[j]='\0';
return u;
}
void initgame()
{
for(int i = 0; i < ARRAY_ROWS; i++)
{
for(int j = 0; j < ARRAY_COLUMNS; j++)
{
board[i][j] = ' ';
}
}
/*
rand positions are used in the following order:
round 1 goal,
player,
round 2 goal 1,
round 2 goal 2,
round 3 goal
*/
for(int i = 0; i < 9; i += 2)
{
pos[i] = rand()%ARRAY_COLUMNS;
pos[i+1] = rand()%ARRAY_ROWS;
}
board[pos[0]][pos[1]] = '*';
board[pos[2]][pos[3]] = character;
choice = rand()%2;
for(int i = 0;(pos[i] == pos[2]) && (pos[i+1] == pos[3]); i+=2)
{
board[i][i+1] == ' ';
if(i == 2)
{
i += 2;
}
pos[i] = rand()%ARRAY_COLUMNS;
pos[i+1] = rand()%ARRAY_ROWS;
board[pos[0]][pos[1]] = '*';
}
for(int i = 0, y2 = 25; i < ARRAY_ROWS; i++, y2 += 40)
{
for(int j = 0, x2 = 30; j < ARRAY_COLUMNS; j++, x2 += 40)
{
board2[i][j][0] = x2;
board2[i][j][1] = y2;
}
}
}
. . .
end chase.h
taken from display()
. . .
else if(show_highscores == true)
{
int x[10], x1[10], y[10];
glBegin(GL_LINE_LOOP);
glVertex2f( 200, 11);
glVertex2f( 460, 11);
glVertex2f( 460, 400 );
glVertex2f( 200, 400 );
glEnd();
for(int i = 0, j = 41; i < 10; i++, j += 35)
{
y[i] = j;
}
for(int i = 0; i < 10; i++)
{
renderBitmapString( 205, y[i], 0,
GLUT_BITMAP_HELVETICA_18, itoa(i
+1));
x[i] = bitmapStringWidth( GLUT_BITMAP_HELVETICA_18,
itoa(i+1));
renderBitmapString( (205 + x[i]), y[i], 0,
GLUT_BITMAP_HELVETICA_18, ".) ");
x[i] += bitmapStringWidth( GLUT_BITMAP_HELVETICA_18,
".) ");
}
for(int i = 0; i < numhighscores; i++)
{
renderBitmapString( 205 + x[i] + 10, y[i], 0,
GLUT_BITMAP_HELVETICA_18, names[i]);
x1[i] = bitmapStringWidth( GLUT_BITMAP_HELVETICA_18,
names[i]);
renderBitmapString( 205 + x[i] + x1[i] + 50, y[i], 0,
GLUT_BITMAP_HELVETICA_18, itoa(highscores[i]));
}
if( prevhigh == true)
{
button5.set_text(GLUT_BITMAP_HELVETICA_18, "Menu");
prevhigh = false;
}
button5.draw();
button5.set_text(GLUT_BITMAP_HELVETICA_18, "Back");
}
else if(win == true)
{
place = numhighscores;
game = false;
wini++;
if(wini == 1)
{
wintime = elapsedtime - restarttime;
}
renderBitmapString(10 + (639 -
bitmapStringWidth(GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!") )/2, 200,
0, GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!");
int x = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You
finished
in");
renderBitmapString( (639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2, 230, 0,
GLUT_BITMAP_HELVETICA_18, "You finished in");
renderBitmapString( ((639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x +
10), 230, 0, GLUT_BITMAP_HELVETICA_18, itoa(wintime));
int x1 = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
itoa(wintime));
renderBitmapString( ((639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x + x1
+ 20), 230, 0, GLUT_BITMAP_HELVETICA_18, "Seconds");
button6.draw();
button7.draw();
button8.draw();
for(int i = numhighscores; i >= 0; i--)
{
if( wintime < highscores[i])
{
place--;
}
}
if(place != 10)
{
if(numhighscores < 10)
{
numhighscores++;
}
highscore = true;
win = false;
accepting_input = true;
}
}
else if(highscore == true)
{
glBegin(GL_LINE_LOOP);
glVertex2f( 200, 50);
glVertex2f( 460, 50);
glVertex2f( 460, 90 );
glVertex2f( 200, 90 );
glEnd();
renderBitmapString(250, 31, 0, GLUT_BITMAP_HELVETICA_18,"New
Highscore");
renderBitmapString(210, 119, 0, GLUT_BITMAP_HELVETICA_18,"(type
Your
name and hit return)");
renderBitmapString(145, 75, 0, GLUT_BITMAP_HELVETICA_18,"Name:
");
renderBitmapString(210, 75, 0, GLUT_BITMAP_HELVETICA_18,
new_highscore);
renderBitmapString(10 + (639 -
bitmapStringWidth(GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!") )/2, 200,
0, GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!");
int x = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You
finished
in");
renderBitmapString( (639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2, 230, 0,
GLUT_BITMAP_HELVETICA_18, "You finished in");
renderBitmapString( ((639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x +
10), 230, 0, GLUT_BITMAP_HELVETICA_18, itoa(wintime));
int x1 = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18,
itoa(wintime));
renderBitmapString( ((639 -
(bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x + x1
+ 20), 230, 0, GLUT_BITMAP_HELVETICA_18, "Seconds");
button5.set_text(GLUT_BITMAP_HELVETICA_18,"Menu");
button5.draw();
button5.set_text(GLUT_BITMAP_HELVETICA_18,"Back");
place = place;
if(accepting_input == false)
{
place = place;
highscores[place] = wintime;
place = place;
names[place] = final_name;
for(int i = (place+1); i < numhighscores; i++)
{
highscores[i] = highscores2[i-1];
names[i] = names2[i-1];
}
ofile.open("High Scores.txt");
for(int i = 0; i < numhighscores; i++)
{
if(i > 0)
{
ofile << endl;
}
ofile << highscores[i] << endl;
ofile << names[i];
}
ofile.close();
ifile.open("High Scores.txt");
string input_string = "";
numhighscores = 0;
for(int i = 0; !ifile.eof() && i < 10; i++,
numhighscores++)
{
getline(ifile, input_string);
stringstream(input_string) >> highscores[i];
getline(ifile, names[i]);
}
for(int i = 0; i < numhighscores; i++)
{
highscores2[i] = highscores[i];
names2[i] = names[i];
}
ifile.close();
highscore = false;
show_highscores = true;
prevhigh = true;
}
}
. . .
end display()
void keyboard(unsigned char key, int x, int y)
{
if(accepting_input == true )
{
if(key == 13 || key == 10 || key == '\n' || key == 12 || key ==
3)
{
final_name = new_highscore;
accepting_input = false;
}
else if( (key == '\b' || key == 127 || key == '\x7f') &&
counter_name > 0)
{
counter_name--;
new_highscore[counter_name] = '\0';
}
else
{
new_highscore[counter_name] = key;
counter_name++;
}
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
srand(time(NULL));
initgame();
ifile.open("High Scores.txt");
string input_string;
numhighscores = 0;
for(int i = 0; !ifile.eof() && i < 10; i++, numhighscores++)
{
getline(ifile, input_string);
stringstream(input_string) >> highscores[i];
getline(ifile, names[i]);
}
for(int i = 0; i < numhighscores; i++)
{
highscores2[i] = highscores[i];
names2[i] = names[i];
}
ifile.close();
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("Chase Game");
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (0, glutGet( GLUT_WINDOW_WIDTH ),
glutGet( GLUT_WINDOW_HEIGHT ), 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glutKeyboardFunc(keyboard);
glutSpecialFunc(arrows);
glutMouseFunc(MouseButton);
glutPassiveMotionFunc(MousePassiveMotion);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
}
On Oct 5, 2008, at 9:57 AM, Tyler Littlefield wrote:
> Just post the relevant functions.
> This might also help you clean up code--yahoogroups doesn't accept
> attachments, or this list doesn't, anyway.
> You can just section things off in to functions which might help,
> but also look at what I asked before. "If you turn on all warnings,
> do you get warnings?"
>
> When i turn on all warnings i still don't get any complaints from
> the compiler not a single warning
>
>
[Non-text portions of this message have been removed]