I want to animate a simple object using open GL. I want to move it across the window by changing its x,y and z properties and rotate it. I was thinking about using the method called in glutIdleFunc to change the values of x, y and z coordinates and the angle.. I am using visual studio c++ and i am not having the desired effects on the animation...
i am doing something like:
glfloat teapotPos[3] = {0,0,0};
glfloat teapotAngle = 0;
teapotMaterial[][4]= {{0.2f, 0.3f, 0.5f, 0.8f}, ...., {0.1f, 0.5f, 0.5f, 0.6f}};
void animate(){
/* Change x, y, z and angle of teapot*/
}
void display(){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
glRotated(angle, 0.0, 0.0, 1.0 );
glTranslatef(teapotPos[0], teapotPos[1], teapotPos[2]);
glColor3d(0.7, 0.9, 0.7);
glMaterialfv( GL_FRONT, GL_AMBIENT, teapotMaterial[0] );
glMaterialfv( GL_FRONT, GL_DIFFUSE, teapotMaterial[1]);
glMaterialfv( GL_FRONT, GL_SPECULAR, teapotMaterial[2] );
glMaterialf ( GL_FRONT, GL_SHININESS, 1.5f );
glutSolidTeapot(0.15);
glutSwapBuffers( );
}
int main( int argc, char** argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
glutInitWindowPosition( 50, 50 );
glutInitWindowSize( 512, 512 );
glutCreateWindow( "ANIMATION" );
glutDisplayFunc( display );
glutIdleFunc(animate);
glEnable( GL_DEPTH_TEST );
glutMainLoop( );
return 0;
}
I am using open GL and Visual Studio 2005....
Any comments to the code included or examples / simple tutorials or code examples are welcome...
openGL animation help needed
Started by javisam376, Jan 12 2009 02:01 PM
2 replies to this topic
#1
Posted 12 January 2009 - 02:01 PM
#2
Posted 12 January 2009 - 05:45 PM
Please use [code]...[/code] tags when you post code in the forum. It will keep the formatting and make the code easier to read.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 12 January 2009 - 06:14 PM
What are you expecting, and what are you getting instead?
"Stupid bug! You go squish now!!" - Homer Simpson
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











