im trying to get the square thats being drawn to move left or right when the r or s key is pressed, its not really working and i know the solution is simple im just not seeing it at the moment. heres the code.
/*
- Main.h
- Core
*/
#include <stdlib.h>
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
float x;
/*
- Main.cpp
*/
#include “Main.h”
void reshape(int width, int height)
{
glViewport(0,0,width,height);
}
void display(void)
{
glLoadIdentity();
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glLightfv(GL_LIGHT0, GL_POSITION, const GLfloat(30.0f, 30.0f, 30.0f));
glBegin(GL_QUADS);
glColor3f(0.0f , 0.0f, 1.0f);
glVertex3f(-0.1f + x, -0.1f, 0.1f);
glColor3f(0.0f , 1.0f, 0.0f);
glVertex3f(-0.1f + x, 0.1f, 0.1f);
glColor3f(1.0f , 0.0f, 0.0f);
glVertex3f(0.1f + x, 0.1f, 0.1f);
glColor3f(1.0f , 1.0f, 0.0f);
glVertex3f(0.1f + x, -0.1f, 0.1f);
glEnd();
glFlush();
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case ‘s’:
case ‘S’:
x++;
glutPostRedisplay();
break;
case ‘r’:
case ‘R’:
x++;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}
void idle(void)
{
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640,480);
glutCreateWindow("Core Engine Test");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
[/b]