question about animation
i am attempting to move 3d objects based on variables that are changed on keypress or on a timer loop, this seems pretty standard, but im missing something, and i figured you kind folks could help me out...
This is a piece of code that represents the problem im having... im probably missing something simple, but here goes.
I have printed the variables to the console from just about every location, and i have confirmed that they are changing but gl doesnt seem to want to use them
#include <iostream>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
using namespace std;
////////////////////////////
//PROTOTYPES
////////////////////////////
void display(void);
void keyboard(unsigned char key, int x, int y);
void update(int value);
////////////////////////////
static GLfloat x;
void display()
{
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glVertex3f(x,1,-14);
glVertex3f(x+1,1,-14);
glVertex3f(x+1,2,-14);
glVertex3f(x,2,-14);
glEnd();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
}
void update(int value)
{
x = x + 1;
cout << x << endl;
glutPostRedisplay();
glutTimerFunc(1000,update,0);
}
void changeSize(int w, int h) {
if(h == 0)
h = 1;
float ratio = 1.0* w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}
int main(int argc, char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("Game");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutTimerFunc(1000,update,0);
glutReshapeFunc(changeSize);
glClearColor(0.0,0.0,0.0,1.0);
glutMainLoop();
return 0;
}
I have printed the variables to the console from just about every location, and i have confirmed that they are changing but gl doesnt seem to want to use them.
It seems to move it when i resize the window or minimize it, so my guess is the screens not updating
Thanks in advance for all your help!!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement