0

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;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by MattEvans
0

Heh, that's the kind of error you don't see everyday.

Look at the arguments to specialFunc:

void specialFunc( int key, [b]int x[/b], int y)

Function argument scope beats global scope.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.