keyboard

I’m trying to use the standard glutKeyboardFunc to no avail. When I press a button my computer replies with the error chime… Any ideas? My code follows…

/* Program 2, October 21st, 2002
 * Author: Dennis Falling 
 * Purpose: To create a 3 dimensional world with fly-through camera. */

#include <GLUT/glut.h> // imports the necessary OpenGL files
#include <math.h>      // imports the sin,cos methods
#include <iostream>    // for testing purposes

typedef float point[4];   // new type (array of floats)
typedef float grid[4][4]; // new type (2-d array of floats) 

void clear()
{
    //glClear(GL_COLOR_BUFFER_BIT);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
} // end of clear method

void display()
{
    //call function to draw plane

glFlush();

}

void processNormalKeys(unsigned char key, int x, int y)
{
if (key == ‘a’)
std::cout << “‘a’ was pressed”; // this line will later be used for a camera control
else if (key == ‘d’)
std::cout << “‘d’ was pressed”;
else if (key == ‘q’)
exit(0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

display();

}

int main(int argc, char** argv)
{

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(500,500); // sets the size of the window
glutInitWindowPosition(50,450); // puts the window in a nice place on my screen...
glutCreateWindow("Program 2");

glutIdleFunc(display);

glutKeyboardFunc(processNormalKeys);

glClearColor(1.0,1.0,1.0,0.0); // white background
glColor3f(0.0,0.5,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0); // specifies dimensions of viewing region
gluPerspective(45,1,1,10);

glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(clear);


glutMainLoop();
return 0; //required for program to compile

} //end of main

Let me guess, you’re compiling under 10.2 using the Terminal.

It’s a bug. Apple knows about it.

In order to activate the window, your application must be properly bundled.

The easiest way to achieve this is to compile from within Project Builder. Use an “Application” target.

Nope, not using the terminal.

I created a C++ tool and am compiling in Project Builder. I’ve added Foundation, Glut, and OpenGL frameworks to the project and everything else works. The files do have a target too, “Program 2” (the name of my Project. Any ideas?

-Dogcow “moof!”
Visit The Underground

C++ Tool is the culprit (you don’t get an application bundle).

Use the Application target type.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.