DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Game Development (http://www.daniweb.com/forums/forum71.html)
-   -   Opengl problem transformation/rotating. (http://www.daniweb.com/forums/thread180776.html)

firstPerson Mar 9th, 2009 8:24 pm
Opengl problem transformation/rotating.
 
I am trying to rotate the object by a input of key.
I dont know why the object is not rotating.

I used glRotatef(x,0,0,1); //where x is declared as float :

here is my code :


#include<GL/glut.h>



GLfloat x = 10;

void initGL()
{
    glEnable(GL_DEPTH);
        glDepthFunc(GL_LEQUAL);
        glClearDepth(1.0f);

}

void reshape(int width,int height)
{
        glViewport(0,0,width,height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        gluPerspective(45.0,(float)width/(float)height,5.0,250.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
       
        glTranslatef(0,0,-10);
        glRotatef(x,0,1,0);
        glutSolidCube(1.0);

        glutSwapBuffers();
        glFlush();
        glutPostRedisplay();
       
}

void keyboard(unsigned char key, int x, int y)
{
        switch(key)
        {
        case 27: exit(0);break;
        case' ': x++;
        }

}

void specialFunc( int key, int x, int y)
{
        switch(key)
        {
        case  GLUT_KEY_UP : x+=1;break;
        case  GLUT_KEY_DOWN:
        case  GLUT_KEY_LEFT:
        case  GLUT_KEY_RIGHT:;
        }

}

int main(int argc, char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(300,200);
    glutCreateWindow("OPENGL");
   
        initGL();

    glutDisplayFunc(display);
       
        glutReshapeFunc(reshape);
       
        glutKeyboardFunc(keyboard);
        glutSpecialFunc(specialFunc);
 
        glutMainLoop();

        return 0;
}

MattEvans Mar 9th, 2009 11:15 pm
Re: Opengl problem transformation/rotating.
 
Heh, that's the kind of error you don't see everyday.

Look at the arguments to specialFunc:
void specialFunc( int key, int x, int y)
Function argument scope beats global scope.


All times are GMT -4. The time now is 11:58 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC