Thread: Glut Error: No rotation

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    37

    Unhappy Glut Error: No rotation

    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;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Where's the rest of the code - say any code which USES xrot when calling Glut drawing functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Glut Camera/stray error: need tutorial/advice
    By drewtoby in forum C++ Programming
    Replies: 7
    Last Post: 05-21-2011, 07:44 PM
  2. OpenGL: glut.h error
    By reaperman in forum C++ Programming
    Replies: 2
    Last Post: 10-29-2008, 12:09 PM
  3. Rotation
    By peckitt99 in forum Windows Programming
    Replies: 4
    Last Post: 03-25-2007, 06:46 AM
  4. animating rotation in glut/open gl
    By chris285 in forum Game Programming
    Replies: 0
    Last Post: 12-09-2003, 05:03 AM
  5. rotation
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-10-2002, 03:34 PM