openGL animation

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...

Comments

  • you say that you are not getting the desired effect.

    What do you see, and what are you expecting?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion