Hello, I have finished my code for a simple rotation program in glut. The problem is this: the program does not rotate!!!! Could you please help me by looking over my code? Thanks!!!
Code:
#include <GL/glut.h>
#include <iostream>
void enable (void) {
glEnable (GL_DEPTH_TEST); //enable the depth testing
glEnable (GL_LIGHTING); //enable the lighting
glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
glShadeModel (GL_SMOOTH); //set the shader to smooth shader
}
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);//Change the object color to red
glVertex3f(-2.0,-0.1,0.0);
glVertex3f(0.4,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glEnd();
glFlush();
}
void keyboard (unsigned char key, int x, int y) {
if (key==‘q’)
{
xrot += 1;
if (xrot >360) xrot -= 360;
}
if (key==‘z’)
{
xrot -= 1;
if (xrot < -360) xrot += 360;
}
if (key==‘w’)
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad)) ;
zpos -= float(cos(yrotrad)) ;
ypos -= float(sin(xrotrad)) ;
}
if (key==‘s’)
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad)) ;
ypos += float(sin(xrotrad));
}
if (key==‘d’)
{
yrot += 1;
if (yrot >360) yrot -= 360;
}
if (key==‘a’)
{
yrot -= 1;
if (yrot < -360)yrot += 360;
}
if (key==27)
{
exit(0);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(800,800);
glutCreateWindow("MynDrawn: An Open Source Alternative to Minecraft");
glutDisplayFunc(renderScene);
glutIdleFunc (display); //update any variables in display,
//display can be changed to anyhing, as long as you move the
variables to be updated, in this case, angle++;
glutReshapeFunc (reshape); //reshape the window accordingly
glutKeyboardFunc (keyboard); //check the keyboard
glutMainLoop (); //call the main loop
return 0;
}