Jump to content
  • Advertisement
Sign in to follow this  
mbanghart

OpenGL C++ OpenGL

This topic is 3804 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, Does anyone know what the numerical values that represent keyboard keys are? (example escape = 27) I am looking for pageup, pagedown and the arrow keys. I am trying to move around in an OpenGL 3D world. Thank you! Marc

Share this post


Link to post
Share on other sites
Advertisement
What are you using to handle window creation and event handling? SDL, freeglut, X11, Win32, Cocoa, Carbon, SFML, GLFW, or something else?

Share this post


Link to post
Share on other sites
not sure what you mean but my project is in C++. Here is an example of how I use the escape sequence to exit (and it works):

//quit
case 27 : exit(0); //Escape
break;

Share this post


Link to post
Share on other sites
Ok, and what value are you using in the switch statement? Where did that value come from.

Neither OpenGL or C++ have any direct way to receive window input (as in keypresses). You are using another library somewhere, even if you aren't aware of it. We need to know what library that is to help you.

Try posting any code you have that involves input if you aren't sure.

Share this post


Link to post
Share on other sites
#include <cstdlib>
#include <GL/glut.h>
#include <fstream>
#include <iostream>
#include <list>
#include <stdlib.h>

using namespace std;

//Function that executes when keyboard key is pressed
void keypress(unsigned char k, int x, int y)
{
switch(k)
{
case 'q' : exit(0);
break;

case 27 : exit(0); //Escape
break;

default : return;
}//switch
}//void

int main(int argc, char** argv)
{
glutInit(&argc,argv);
//Check for input filename
if (argc < 2) //no file on input line
{
char tech;
string filename;
cout << "Welcome to Marc's Simulator!" << endl;
cout << "\nPlease enter an input map file. If the file is not located in the current" << endl;
cout << "directory please specify the entire path. If the file is located in the" << endl;
cout << "current directory enter the full filename including the extension.\n" << endl;
cout << ">> ";
cin >> filename;
readFile(filename);
}
else
{
readFile(argv[1]);
}

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(400,500);

//Position on screen
GLint windowPosx = (glutGet (GLUT_SCREEN_WIDTH) - 400)/2;
GLint windowPosy = (glutGet (GLUT_SCREEN_HEIGHT) - 500)/2;
glutInitWindowPosition(windowPosx,windowPosy);

glutCreateWindow("Marc Banghart - CSE 7382 - Program 1");
glutKeyboardFunc(keypress); //Exit program when q or ESC is pressed
createMenu();

glutDisplayFunc(display);
myInit();
glutMainLoop();

return 0;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!