Ok, here is what I have so far. And it doesn’t work the way I want it to.
#include <windows.h> /* must include this before GL/gl.h /
#include <GL/gl.h>
#include <GL/glut.h> / OpenGL utilities header file */
//#include <stdio.h>
//#include <string.h>
float ambientlightsource[] = {0.3, 0.3, 0.45, 1.0};
float source_light[] = {0.9, 0.8, 0.8, 1.0};
float light_pos[] = {7.0, 0.0, 0.0, 1.0};
void teapot(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0f,0.0f, -7.0f);
glColor3f(1.0, 0.0, 0.0);
glutSolidTeapot(2.0);
glPopMatrix();
}
void myInit(void)
{
glEnable ( GL_LIGHTING );
glLightModelfv ( GL_LIGHT_MODEL_AMBIENT, ambientlightsource );
glLightfv ( GL_LIGHT0, GL_DIFFUSE, source_light );
glLightfv ( GL_LIGHT0, GL_POSITION, light_pos );
glEnable ( GL_LIGHT0 );
glEnable ( GL_COLOR_MATERIAL );
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
//glEnable ( GL_CULL_FACE );
// glMatrixMode(GL_PROJECTION);
//glClearColor ( 0.0, 0.0, 0.0, 0.0 );
glEnable ( GL_DEPTH_TEST );
}
void mouse ( int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && x > 520 && x < 600 && y > 280 && y < 300 ) {
glRotatef(15,1.0,0.0,0.0);
teapot();
glutPostRedisplay();
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
teapot();
glutSwapBuffers();
}
void
reshape(int w, int h)
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
if ( h==0 )
gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(640, 480);
glutInitWindowPosition(100,150);
glutCreateWindow("");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc (mouse);
myInit();
glutMainLoop();
return 0;
}
When I click on an area on the right of the screen, the teapot rotates on its X axis, just once, and not on it’s own axis either. I want it so that it revolves on its z axis, on the spot, and also to get the area where i am clicking to be more specific. Because where i click (bottomish right), is not where i have said (x > 520 && x < 600 && y > 280 && y < 300). Any ideas?
Thanx