Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem with OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 DoubleT   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 December 2001 - 03:25 PM

I''m looking to get into some game programming. I know I''m starting a little late since I''m already a college student. I just finished my first class in computer graphic and we covered OpenGL extensively. In fact we even built our own ray tracer. But my problem lies in this. I''m working on my first game which is a Tetris clone. I decided to write it using just text characters and then use graphics. I''m up to the graphics point right now. My problem is with the main game loop. I don''t understand how to implement in conjunction with the GLUT glutMainLoop() function. This is not a Win32 program since I only use Linux so it''s like a console app if you''re using MSVC. Any help would be greatly appreciated. Double T Roy.Ens@ttu.edu

Sponsor:

#2 bpj1138   Members   -  Reputation: 113

Like
Likes
Like

Posted 09 December 2001 - 05:58 PM

I think what you''re asking is how to implement a program in this awkward environment where GLUT calls your display callback or animate callback. Well, basicly you have to maintain a "state" for your program. Ignoring user input for now, say your tetris game just keeps dropping pieces down the screen, and they eventually fill up the screen and the game ends. There are two states in this case, one where the game is in play and one where the game has ended. So in your game loop, or GLUT callback in this case, you''d do something like:

int gameState; // this is a global

void animateCallback() {
if (gameState == GAME_PLAYING) {
movePieces();
}
else {
showGameOverScreen();
}
}

Now, there are other "states" in the game, like when the pieces are moving, you have to save their position and orientation, so the movePieces() function might look like this:

int x, y, angle; // these are globals

void movePieces() {
x += playerInputX; // x position is controlled by player
y += 1; // y always moves down
if (y > SCREEN_HEIGHT) { // actually if the piece stopped
currentPiece = rand(); // generate new piece
x = 0; y = 0; // reset coordinates
}
}

you also have some callbacks for the keyboard, so the function above will interact with the keyboard callback like this:

void keyboardCallback(int key) {
switch (key) {
case GLUT_LEFT:
playerInputX = -1;
break;
case GLUT_RIGHT:
playerInputX = 1;
break;
}
}

hope that helps..



#3 DoubleT   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 December 2001 - 06:34 PM

Ok, that makes a lot of sense. I''ve tried implementing something similar and it''s starting to work now.

Double T
Roy.Ens@ttu.edu


#4 DoubleT   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 December 2001 - 06:34 PM

Ok, that makes a lot of sense. I''ve tried implementing something similar and it''s starting to work now.

Double T
Roy.Ens@ttu.edu





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS