#include #include #include GLint Sonne; GLint Mond; GLint Erde; GLint Station; GLfloat viewpoint[3]; GLfloat light_ambient[] = {0.2,0.2,0.2,1.0}; GLfloat light_diffuse[] = {1.0,1.0,1.0,1.0}; GLfloat light_specular[] = {1.0,1.0,1.0,1.0}; GLfloat light_position[] = {-0.8,0.0,0.5,1.0}; GLfloat mat1_specular[] = {1.0,1.0,1.0,1.0 }; GLfloat mat1_shininess[] = {20.0 }; GLfloat mat1_diffuse[] = {1.0,1.0,0.0,1.0 }; GLfloat mat2_specular[] = {1.0,1.0,1.0,1.0 }; GLfloat mat2_shininess[] = {20.0 }; GLfloat mat2_diffuse[] = {2.3, 2.5, 1.0,1.0 }; GLfloat mat3_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat3_shininess[] = {20.0}; GLfloat mat3_diffuse[] = {0.0, 0.0, 1.0,1.0}; GLfloat mat4_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat4_shininess[] = {20.0}; GLfloat mat4_diffuse[] = {0.0, 0.0, 0.0,1.0}; static void GLUTCALLBACK myinit(void) { GLUquadricObj *son, *mon, *erd, *stat; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor (1.0, 1.0, 1.0, 1.0); Sonne= 1; glNewList(Sonne,GL_COMPILE); glMaterialfv(GL_FRONT, GL_SPECULAR, mat1_specular); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat1_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, mat1_shininess); son = gluNewQuadric(); gluQuadricDrawStyle(son, GLU_FILL); gluSphere(son, 0.3,16,16); glEndList(); Mond = 2; glNewList(Mond,GL_COMPILE); glMaterialfv(GL_FRONT, GL_SPECULAR, mat2_specular); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat2_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, mat2_shininess); glShadeModel(GL_FLAT); mon = gluNewQuadric(); gluQuadricDrawStyle(mon, GLU_FILL); gluSphere(mon, 0.05,16,16); glEndList(); Erde = 3; glNewList(Erde,GL_COMPILE); glMaterialfv(GL_FRONT, GL_SPECULAR, mat3_specular); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat3_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, mat3_shininess); glShadeModel(GL_SMOOTH); erd = gluNewQuadric(); gluQuadricDrawStyle(erd, GLU_FILL); gluSphere(erd, 0.2, 40, 40); glEndList(); Station = 4; glNewList(Station,GL_COMPILE); glMaterialfv(GL_FRONT, GL_SPECULAR, mat4_specular); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat4_diffuse); glMaterialfv(GL_FRONT, GL_SHININESS, mat4_shininess); glShadeModel(GL_SMOOTH); stat = gluNewQuadric(); gluQuadricDrawStyle(stat, GLU_FILL); // gluCylinder(stat, 0.02,0.01, 6, 6, 1,1); gluSphere(stat, 0.03, 10, 10); glEndList(); } static void GLUTCALLBACK myReshape(int w, int h) { /* Callback function to handle window dimensions and size changes */ glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); /* specifies the current matrix */ glLoadIdentity(); /* Sets the currant matrix to identity */ /* Sets the clipping rectangle extends */ gluPerspective(30.0, 1.0, 0.1, 20.0); gluLookAt(1.0, 2.0, 4.0, 0, 0, 0, 0.0, 1, 0.0); } static void GLUTCALLBACK RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT1, GL_POSITION, light_position); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glEnable(GL_LIGHTING); glEnable(GL_LIGHT1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-0.9, -0.5, -0.3); glCallList(Sonne); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(+0.6, 0.2, +0.0); glCallList(Mond); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(+0.9, -0.5, -0.3); glCallList(Erde); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(+0.65, -0.8, -0.3); glCallList(Station); glFlush(); } void ProcessPlanet(GLuint *pSelectBuff) { GLuint names, *ptr; ptr =(GLuint*) pSelectBuff; names =*ptr; ptr+=3; printf("names: %d, ptr= %d", names, *ptr); } #define BUFSIZE 10 void ProcessSelection(int xPos, int yPos) { GLuint puff[BUFSIZE]; GLint ziel; glIndexMask(*puff); glSelectBuffer(BUFSIZE, puff); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glPushMatrix(); // hier muss was rein glPopMatrix(); ziel =glRenderMode(GL_RENDER); ProcessPlanet(ziel, puff); } void myMouse(int button, int state, int mouseX, int mouseY) { if(button == GLUT_LEFT_BUTTON && state == GLUT_UP) ProcessSelection(mouseX, mouseY); } void main(int argc, char** argv){ glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH); glutInitWindowPosition (0, 0); glutInitWindowSize(700, 500); glutInit(&argc, argv); glutCreateWindow (argv[0]); glutMouseFunc(myMouse); //glutKeyboardFunc(myKeyboard); //glutSpecialFunc(mySpecial); myinit(); glutReshapeFunc (myReshape); glutDisplayFunc(RenderScene); glutMainLoop(); }