Opengl problem transformation/rotating.

Reply

Join Date: Dec 2008
Posts: 959
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 125
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Posting Shark

Opengl problem transformation/rotating.

 
0
  #1
Mar 9th, 2009
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: Opengl problem transformation/rotating.

 
0
  #2
Mar 9th, 2009
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.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Game Development Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC