SilentStrike
01-14-2001, 08:10 AM
I am just starting to Learn OpenGL. I read through the first 3 chapters of the Open GL Super Bible online, but unfortunetely, it doesn't let me get access to the CD that comes with it http://www.opengl.org/discussion_boards/ubb/frown.gif (guess they want me to buy it, no thx http://www.opengl.org/discussion_boards/ubb/wink.gif )
Anyway, I am trying to modify the 3rd section of code with the AuxKeyFunc function so that I can move a rectangle down when I press the d key. However, nothing happens when I press the key down. What is wrong with my code?
// bounce.c
// Bouncing square
#include <windows.h> // Standard windows include
#include <gl\gl.h> // OpenGL library
#include <gl\glaux.h> // AUX library
#include <iostream.h>
GLfloat windowHeight = 250.0f;
GLfloat windowWidth = 250.0f;
GLfloat x1 = 100;
GLfloat y1 = 100;
GLfloat rsize = 50;
void CALLBACK MoveDown(void) {
cout << "Yup, you pressed d" << endl;
if (y1 - rsize > 0)
y1--;
}
void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
// Prevent a divide by zero, when window is too short
// (you can’t make a window of zero width)
if(h == 0)
h = 1;
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Reset the coordinate system before modifying
glLoadIdentity();
// Keep the square square, this time, save calculated
// width and height for later use
if (w <= h)
{
windowHeight = 250.0f*h/w;
windowWidth = 250.0f;
}
else
{
windowWidth = 250.0f*w/h;
windowHeight = 250.0f;
}
// Set the clipping volume
glOrtho(0.0f, windowWidth, 0.0f, windowHeight, 1.0f, -1.0f);
}
// Called by AUX library to update window
void CALLBACK RenderScene(void)
{
// Set background clearing color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Set drawing color to red, and draw rectangle at
// current position.
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(x1, y1, x1 + rsize, y1 + rsize);
glFlush();
auxSwapBuffers();
}
// Main body of program
void main(void)
{
// AUX window setup and initialization
auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("Simple 2D Animation");
// Set function to call when window is resized
auxReshapeFunc(ChangeSize);
// Start main loop
auxMainLoop(RenderScene);
//Move Rect down when D is pressed
auxKeyFunc(AUX_d, MoveDown);
}
Anyway, I am trying to modify the 3rd section of code with the AuxKeyFunc function so that I can move a rectangle down when I press the d key. However, nothing happens when I press the key down. What is wrong with my code?
// bounce.c
// Bouncing square
#include <windows.h> // Standard windows include
#include <gl\gl.h> // OpenGL library
#include <gl\glaux.h> // AUX library
#include <iostream.h>
GLfloat windowHeight = 250.0f;
GLfloat windowWidth = 250.0f;
GLfloat x1 = 100;
GLfloat y1 = 100;
GLfloat rsize = 50;
void CALLBACK MoveDown(void) {
cout << "Yup, you pressed d" << endl;
if (y1 - rsize > 0)
y1--;
}
void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
// Prevent a divide by zero, when window is too short
// (you can’t make a window of zero width)
if(h == 0)
h = 1;
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Reset the coordinate system before modifying
glLoadIdentity();
// Keep the square square, this time, save calculated
// width and height for later use
if (w <= h)
{
windowHeight = 250.0f*h/w;
windowWidth = 250.0f;
}
else
{
windowWidth = 250.0f*w/h;
windowHeight = 250.0f;
}
// Set the clipping volume
glOrtho(0.0f, windowWidth, 0.0f, windowHeight, 1.0f, -1.0f);
}
// Called by AUX library to update window
void CALLBACK RenderScene(void)
{
// Set background clearing color to blue
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Set drawing color to red, and draw rectangle at
// current position.
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(x1, y1, x1 + rsize, y1 + rsize);
glFlush();
auxSwapBuffers();
}
// Main body of program
void main(void)
{
// AUX window setup and initialization
auxInitDisplayMode(AUX_DOUBLE | AUX_RGBA);
auxInitPosition(100,100,250,250);
auxInitWindow("Simple 2D Animation");
// Set function to call when window is resized
auxReshapeFunc(ChangeSize);
// Start main loop
auxMainLoop(RenderScene);
//Move Rect down when D is pressed
auxKeyFunc(AUX_d, MoveDown);
}