// 3Dオブジェクトを描画(引数によって変化) void mySelectWire(int i){ switch(i){ case 0: glutWireSphere( 30.0, 10, 10); break; case 1: glutWireCube( 40.0 ); break; case 2: glScalef( 1.5, 1.5, 1.5 ); glutWireTorus( 10.0, 20.0, 20, 6); break; case 3: glScalef( 40.0, 40.0, 40.0 ); glutWireTetrahedron(); break; case 4: glTranslatef( 0.0, 0.0, 10.0 ); glRotatef( 90.0, 1.0, 0.0, 0.0 ); glutWireTeapot( 40.0 ); break; default: glutWireIcosahedron(); printf("EROOR: Wire_count\n"); break; } }
void displayWirePolyhedra (void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (0.0, 0.0, 1.0); gluLookAt (5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //draw cube glScalef (1.5, 2.0, 1.0); glutWireCube (1.0); //draw d12 glScalef (0.8, 0.5, 0.8); glTranslatef (-6.0, -5.0, 0.0); glutWireDodecahedron (); //draw d4 glTranslatef (8.6, 8.6, 2.0); glutWireTetrahedron (); //draw d8 glTranslatef (-3.0, -1.0, 0.0); glutWireOctahedron (); //draw d20 glScalef (0.8, 0.8, 1.0); glTranslatef (4.3, -2.0, 0.5); glutWireIcosahedron (); glFlush (); }
void displayFcn(void) { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(x0, yO, z0, 0, 0, 0, 0, 1, 0); glColor3f(color[0], color[1], color[2]); if (toggle) glRotatef(rotTheta += 3, 0.0, 1.0, 0.0); glScalef(scale, scale, scale); if (solid) { switch (poly) { case 1: glutSolidCube(1.0); break; case 2: glutSolidDodecahedron(); break; case 3: glutSolidTetrahedron(); break; case 4: glutSolidOctahedron(); break; case 5: glutSolidIcosahedron(); break; case 6: glutSolidIcosahedron(); break; } } else { switch (poly) { case 1: glutWireCube(1.0); break; case 2: glutWireDodecahedron(); break; case 3: glutWireTetrahedron(); break; case 4: glutWireOctahedron(); break; case 5: glutWireIcosahedron(); break; case 6: glutWireIcosahedron(); break; } } glPopMatrix(); glutSwapBuffers(); glFlush(); }
//------------------------------------------------------------------------------ void npGlutPrimitive (int primitive) { switch (primitive) { case kNPgeoCubeWire : glScalef (0.6f, 0.6f, 0.6f); glutWireCube(2.0f); glScalef (1.666667f, 1.666667f, 1.666667f); break; case kNPgeoCube : glScalef (0.6f, 0.6f, 0.6f); glutSolidCube(2.0f); glScalef (1.666667f, 1.666667f, 1.666667f); break; case kNPgeoSphereWire : glutWireSphere( 1.0f, 24, 12); break;//15, 15 ); break; case kNPgeoSphere : glutSolidSphere( 1.0f, 24, 12 ); break; case kNPgeoConeWire : glutWireCone( 1.0f, 2.0f, 24, 1 ); break; case kNPgeoCone : glutSolidCone( 1.0f, 2.0f, 24, 1 ); break; case kNPgeoTorusWire : glutWireTorus(kNPtorusRadius * 0.1f, kNPtorusRadius, 7, 16); break; case kNPgeoTorus : glutSolidTorus(kNPtorusRadius * 0.1f, kNPtorusRadius, 7, 16); break; case kNPgeoDodecahedronWire : glScalef (0.6f, 0.6f, 0.6f); glutWireDodecahedron(); glScalef (1.666667f, 1.666667f, 1.666667f); break; case kNPgeoDodecahedron : glScalef (0.6f, 0.6f, 0.6f); glutSolidDodecahedron(); glScalef (1.666667f, 1.666667f, 1.666667f); break; case kNPgeoOctahedronWire : glutWireOctahedron(); break; case kNPgeoOctahedron : glutSolidOctahedron(); break; case kNPgeoTetrahedronWire : glutWireTetrahedron(); break; case kNPgeoTetrahedron : glutSolidTetrahedron(); break; case kNPgeoIcosahedronWire : glutWireIcosahedron(); break; case kNPgeoIcosahedron : glutSolidIcosahedron(); break; // case kNPglutWireTeapot : glutWireTeapot( 2.0f ); break; // case kNPglutSolidTeapot : glutSolidTeapot( 2.0f ); break; default : glutWireTetrahedron(); break; } }
void Display(void) { glClear(GL_COLOR_BUFFER_BIT); //用当前背景色填充窗口 glMatrixMode(GL_MODELVIEW); //制定设置模型视图变换参数 glLoadIdentity(); //消除以前的变换 glRotatef(xRot,1.0f,0.0f,0.0f); //绕X轴旋转图形 glRotatef(yRot,0.0f,1.0f,0.0f); //绕y轴旋转图形 switch(iMode) { case 1: glutWireTetrahedron();break; //绘制线框正四面体 case 2: glutSolidTetrahedron();break; //绘制实体正四面体 case 3: glutWireOctahedron();break; //绘制线框正八面体 case 4: glutSolidOctahedron();break;//绘制实体正八面体 case 5: glutWireSphere(1.0f,15,15);break; //绘制线框球 case 6: glutSolidSphere(1.0f,15,15);break;//绘制实体球 case 7: glutWireTeapot(1.0f);break; //绘制线框茶壶 case 8: glutSolidTeapot(1.0f);break;//绘制实体茶壶 case 9: gluSphere(obj,1.0f,15,15);break; //绘制二次曲面(球) case 10: gluCylinder(obj,1.0f,0.0f,1.0f,15,15);break;//绘制二次曲面(圆锥) case 11: gluPartialDisk(obj,0.3f,0.8f,15,15,30.0f,260.0f);break; //绘制二次曲面(圆环) default: break; } }
void menu (int valor) { switch (valor) { case 1: { glutWireTorus(0.5, 1.0, 20, 20); break; } case 2: { glutWireTeapot(1); break; } case 3: { glutWireIcosahedron(); break; } case 4: { glutWireCone(1.0, 1.0, 10, 10); break; } case 5: { glutWireOctahedron(); break; } case 6: { glutWireTetrahedron(); break; } case 7: exit(0); } }
/* * Class: gruenewa_opengl_GLUT__ * Method: glutWireTetrahedron * Signature: ()V */ JNIEXPORT void JNICALL Java_gruenewa_opengl_GLUT_00024_glutWireTetrahedron (JNIEnv * jenv, jobject jobj) { glutWireTetrahedron(); }
// DRAW //------------------------------------------------- void Object3D::Draw () { // daca nu este vizibil, nu-l desenam if(!Visible) return; glPushMatrix(); // translatie glTranslatef( translation.x , translation.y , translation.z ); // rotatie glRotatef( rotation.x , 1.0 , 0.0 , 0.0 ); glRotatef( rotation.y , 0.0 , 1.0 , 0.0 ); glRotatef( rotation.z , 0.0 , 0.0 , 1.0 ); // scalare glScalef( scale.x , scale.y , scale.z); // setari de material : // daca nu este selectat if( !selected ) { // culoare normala glColor3f(color.x,color.y,color.z); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,(Vector4D(color.x,color.y,color.z,1)).Array()); } else { // culoarea atunci cand obiectul este selectat glColor3f(SelectedColor.x, SelectedColor.y, SelectedColor.z); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,(Vector4D(SelectedColor.x,SelectedColor.y,SelectedColor.z,1)).Array()); } // culoare speculara, default glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,(Vector4D(0.1,0.1,0.1,1)).Array()); //culoae emisiva if(emission==true) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Vector4D(Vector4D(color.x,color.y,color.z,1)).Array()); else glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Vector4D(0, 0, 0, 0).Array()); // daca este wireframe if( Wireframe ) switch( Type ) { // cub wireframe case Cube : glutWireCube(1.0); break; // sfera wireframe case Sphere : glutWireSphere(1.0, levelOfDetail, levelOfDetail); break; // ceainic wireframe case MyTeapot: glutWireTeapot(1); break; // lampa wireframe case MyLamp: glutWireCone(1.0,2.0,(int)levelOfDetail,(int)levelOfDetail); break; // inamic wireframe case MyEnemy: glutWireDodecahedron(); break; // extra inamic wireframe case ExtraEnemy: glutWireTetrahedron(); break; // orice alt obiect, specificat de programator case Custom : customDraw(); } // daca nu este wireframe else switch( Type ) { // cub solid case Cube : glutSolidCube(1.0); break; // sfera solida case Sphere : glutSolidSphere(1.0, levelOfDetail, levelOfDetail); break; // ceainic solid case MyTeapot: glutSolidTeapot(1); break; // lampa solida case MyLamp: glutSolidCone(1.0,2.0,(int)levelOfDetail,(int)levelOfDetail); break; // inamic solid case MyEnemy: glutSolidDodecahedron(); // extra inamic solid case ExtraEnemy: glutSolidTetrahedron(); break; // orice alt obiect, specificat de programator case Custom : customDraw(); } glPopMatrix(); }
static void hugsprim_glutWireTetrahedron_8(HugsStackPtr hugs_root) { glutWireTetrahedron(); hugs->returnIO(hugs_root,0); }
static void drawWireTetrahedron(void) { glutWireTetrahedron (); }
/** WireTetrahedron () -> None */ static int glut_wire_tetrahedron(lua_State *L) { glutWireTetrahedron(); }
void displayFunc(void) { static int shape = 1; fprintf(stderr, " %d", shape); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); switch (shape) { case 1: glutWireSphere(1.0, 20, 20); break; case 2: glutSolidSphere(1.0, 20, 20); break; case 3: glutWireCone(1.0, 1.0, 20, 20); break; case 4: glutSolidCone(1.0, 1.0, 20, 20); break; case 5: glutWireCube(1.0); break; case 6: glutSolidCube(1.0); break; case 7: glutWireTorus(0.5, 1.0, 15, 15); break; case 8: glutSolidTorus(0.5, 1.0, 15, 15); break; case 9: glutWireDodecahedron(); break; case 10: glutSolidDodecahedron(); break; case 11: glutWireTeapot(1.0); break; case 12: glutSolidTeapot(1.0); break; case 13: glutWireOctahedron(); break; case 14: glutSolidOctahedron(); break; case 15: glutWireTetrahedron(); break; case 16: glutSolidTetrahedron(); break; case 17: glutWireIcosahedron(); break; case 18: glutSolidIcosahedron(); break; default: printf("\nPASS: test16\n"); exit(0); } glutSwapBuffers(); shape += 1; sleep(1); glutPostRedisplay(); }
void display_2(void) { char *p; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear the screen glMatrixMode (GL_PROJECTION); // Tell opengl that we are doing project matrix work glLoadIdentity(); // Clear the matrix glOrtho(-8.0, 8.0, -8.0, 8.0, 0.0, 30.0); // Setup an Ortho view glMatrixMode(GL_MODELVIEW); // Tell opengl that we are doing model matrix work. (drawing) glLoadIdentity(); // Clear the model matrix glColor3f(1.0, 1.0, 1.0); if (shape == 0) Sprint(-3, -7 ,"Wire Cube"); if (shape == 1) Sprint(-3, -7 ,"Wire Cone"); if (shape == 2) Sprint(-3, -7 ,"Wire Sphere"); if (shape == 3) Sprint(-3, -7 ,"Wire Torus"); if (shape == 4) Sprint(-3, -7 ,"Wire Dodecahedron"); if (shape == 5) Sprint(-3, -7 ,"Wire Octahedron"); if (shape == 6) Sprint(-3, -7 ,"Wire Tetrahedron"); if (shape == 7) Sprint(-3, -7 ,"Wire Icosahedron"); if (shape == 8) Sprint(-3, -7 ,"Wire Teapot"); // Setup view, and print view state on screen if (view_state == 1) { glColor3f( 1.0, 1.0, 1.0); Sprint(-2, 4, "Perspective view"); glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluPerspective(60, 1, 1, 30); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }else { glColor3f( 1.0, 1.0, 1.0); Sprint(-2, 4, "Ortho view"); } glColor3f( 0.0, 0.0, 1.0); // Cube color // Lighting on/off if (light_state == 1) { glDisable(GL_LIGHTING); // Turn off lighting glDisable(GL_COLOR_MATERIAL); // Turn off material, which needs lighting to work }else { glEnable(GL_LIGHTING); // Turn on lighting glEnable(GL_COLOR_MATERIAL); // Turn on material settings glColorMaterial(GL_FRONT, GL_AMBIENT); glColor4f(0.65, 0.65, 0.65, 0.4); glColorMaterial(GL_FRONT, GL_EMISSION); glColor4f(0.10, 0.10, 0.10, 0.0); glColorMaterial(GL_FRONT, GL_SPECULAR); glColor4f(0.5, 0.5, 0.5, 0.4); glColorMaterial(GL_FRONT, GL_DIFFUSE); glColor4f(0.85, 0.85, 0.85, 0.4); } gluLookAt( 0, 0, 20, 0, 0, 0, 0, 1, 0); //glRotatef( 45, 1.0, 1.0, 0.0); // rotate cube glRotatef( spin++, 1.0, 1.0, 1.0); // spin cube if (shape == 0) glutWireCube(10); // Draw a cube if (shape == 1) glutWireCone(5,10, 16,16); // Draw a Cone if (shape == 2) glutWireSphere(5, 16,16 ); // Draw a Sphere if (shape == 3) glutWireTorus( 2.5, 5, 16, 16); if (shape == 4) { glScalef( 3.5, 3.5, 3.5); glutSolidDodecahedron(); } if (shape == 5) { glScalef( 5.0, 5.0, 5.0); glutWireOctahedron(); } if (shape == 6) { glScalef( 5.0, 5.0, 5.0); glutWireTetrahedron(); } if (shape == 7) { glScalef( 5.0, 5.0, 5.0); glutWireIcosahedron(); } if (shape == 8) glutWireTeapot( 5 ); glutSwapBuffers(); }
//------------------------------------------------------------------------- // Draws our object. //------------------------------------------------------------------------- void drawObject () { // Draw the object only if the Draw check box is selected if (draw) { // Push the current matrix into the model view stack glPushMatrix (); // Apply the translation glTranslatef (translate_xy[0], translate_xy[1], -translate_z); // Apply the rotation matrix glMultMatrixf (rotation_matrix); // Apply the scaling glScalef (scale, scale, scale); // Get the id of the selected object int selected_object = (radiogroup_item_id * 2) + 1 - wireframe; switch (selected_object) { // draw glut wire cube case GLUT_WIRE_CUBE: glutWireCube (0.5); break; // draw glut solid cube case GLUT_SOLID_CUBE: glutSolidCube (0.5); break; // draw glut wire sphere case GLUT_WIRE_SPHERE: glutWireSphere (0.5, 50, 50); break; // draw glut solid sphere case GLUT_SOLID_SPHERE: glutSolidSphere (0.5, 50, 50); break; // draw glut wire Cone case GLUT_WIRE_CONE: glutWireCone (0.5, 0.5, 50, 50); break; // draw glut solid cone case GLUT_SOLID_CONE: glutSolidCone (0.5, 0.5, 50, 50); break; // draw glut wire Torus case GLUT_WIRE_TORUS: glutWireTorus (0.15, 0.25, 20, 20); break; /// draw glut solid Torus case GLUT_SOLID_TORUS: glutSolidTorus (0.15, 0.25, 20, 20); break; // draw a wire dodecahedron.. The reason why I'm dividing // by 2 * radical (3) when I'm scaling it because I want to fit // the dodecahedron which is centered at the modeling // coordinates origin with a radius of radical (3). case GLUT_WIRE_DODECAHEDRON: glScalef (1 / sqrt (12), 1 / sqrt (12), 1 / sqrt (12)); glutWireDodecahedron (); break; // draw a solid dodecahedron case GLUT_SOLID_DODECAHEDRON: glScalef (1 / sqrt (12), 1 / sqrt (12), 1 / sqrt (12)); glutSolidDodecahedron (); break; // draw a wire octahedron.. The reason why I'm dividing // by 2 when I'm scaling is because I want to fit // the octahedron which is centered at the modeling // coordinates origin with a radius of 1. case GLUT_WIRE_OCTAHEDRON: glScalef (0.5, 0.5, 0.5); glutWireOctahedron (); break; // draw a solid tetrahedron case GLUT_SOLID_OCTAHEDRON: glScalef (0.5, 0.5, 0.5); glutSolidOctahedron (); break; // draw a wire tetrahedron.. case GLUT_WIRE_TETRAHEDRON: glScalef (1 / sqrt(6), 1 / sqrt(6), 1 / sqrt(6)); glutWireTetrahedron (); break; // draw a solid tetrahedron case GLUT_SOLID_TETRAHEDRON: glScalef (1 / sqrt(6), 1 / sqrt(6), 1 / sqrt(6)); glutSolidTetrahedron (); break; // draw a wire icosahedron.. The reason why I'm dividing // by 2 when I'm scaling is because I want to fit // the icosahedron which is centered at the modeling // coordinates origin with a radius of 1. case GLUT_WIRE_ICOSAHEDRON: glScalef (0.5, 0.5, 0.5); glutWireIcosahedron (); break; // draw a solid icosahedron case GLUT_SOLID_ICOSAHEDRON: glScalef (0.5, 0.5, 0.5); glutSolidIcosahedron (); break; // draw Wire Teapot case GLUT_WIRE_TEAPOT: glutWireTeapot (0.5); break; // draw a solid Teapot case GLUT_SOLID_TEAPOT: glutSolidTeapot (0.5); break; // Do Nothing default: break; } // Pop our matrix from the model view stack after we finish drawing glPopMatrix (); } }
//显示回调函数 void renderScreen(void){ //将窗口颜色清理为黑色 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //将模板缓冲区值全部清理为1 glClearStencil(1); //使能模板缓冲区 glEnable(GL_STENCIL_TEST); //把整个窗口清理为当前清理颜色:黑色。清除深度缓冲区、模板缓冲区 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //将当前Matrix状态入栈 glPushMatrix(); //坐标系绕x轴旋转xRotAngle glRotatef(xRotAngle, 1.0f, 0.0f, 0.0f); //坐标系绕y轴旋转yRotAngle glRotatef(yRotAngle, 0.0f, 1.0f, 0.0f); //进行平滑处理 glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH, GL_NICEST); glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH, GL_NICEST); glEnable(GL_POLYGON_SMOOTH); glHint(GL_POLYGON_SMOOTH, GL_NICEST); //白色绘制坐标系 glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINES); glVertex3f(-9.0f, 0.0f, 0.0f); glVertex3f(9.0f, 0.0f, 0.0f); glVertex3f(0.0f, -9.0f, 0.0f); glVertex3f(0.0f, 9.0f, 0.0f); glVertex3f(0.0f, 0.0f, -9.0f); glVertex3f(0.0f, 0.0f, 9.0f); glEnd(); glPushMatrix(); glTranslatef(9.0f, 0.0f, 0.0f); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); glutSolidCone(0.3, 0.6, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, 9.0f, 0.0f); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); glutSolidCone(0.3, 0.6, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, 0.0f, 9.0f); glRotatef(90.0f, 0.0f, 0.0f, 1.0f); glutSolidCone(0.3, 0.6, 10, 10); glPopMatrix(); //设置绘画颜色为金色 glColor3f(0.0f, 1.0f, 0.0f); switch (iModel){ //球 case SPHERE: if (bWire){ glutWireSphere(8.0f, 20, 20); } else{ glutSolidSphere(8.0f, 20, 20); } break; //锥体 case CONE: if (bWire){ glutWireCone(4.0f, 8.0f, 20, 20); } else{ glutSolidCone(4.0f, 8.0f, 20, 20); } break; //立体 case CUBE: if (bWire){ glutWireCube(8.0f); } else{ glutSolidCube(8.0f); } break; //甜圈 case TORUS: if (bWire){ glutWireTorus(3.0f, 6.0f, 20, 20); } else{ glutSolidTorus(3.0f, 6.0f, 20, 20); } break; //十六面体,默认半径1.0 case DODECAHEDRON: glScalef(6.0f, 6.0f, 6.0f);//x,y,z轴均放大6倍 if (bWire){ glutWireDodecahedron(); } else{ glutSolidDodecahedron(); } break; //茶壶 case TEAPOT: if (bWire){ glutWireTeapot(8.0f); } else{ glutSolidTeapot(8.0f); } break; //八面体,默认半径1.0 case OCTAHEDRON: glScalef(6.0f, 6.0f, 6.0f);//x,y,z轴均放大6倍 if (bWire){ glutWireOctahedron(); } else{ glutSolidOctahedron(); } break; //四面体,默认半径1.0 case TETRAHEDRON: glScalef(6.0f, 6.0f, 6.0f);//x,y,z轴均放大6倍 if (bWire){ glutWireTetrahedron(); } else{ glutSolidTetrahedron(); } break; //二十面体,默认半径1.0 case ICOSAHEDRON: glScalef(6.0f, 6.0f, 6.0f);//x,y,z轴均放大6倍 if (bWire){ glutWireIcosahedron(); } else{ glutSolidIcosahedron(); } break; default: break; } //恢复压入栈的Matrix glPopMatrix(); //交换两个缓冲区的指针 glutSwapBuffers(); }
// Clears the window and draws the torus. void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(rotate_x, 1.0, 0.0, 0.0); glRotatef(rotate_y, 0.0, 1.0, 0.0); glScaled(zoom, zoom, zoom); // Draw a white torus of outer radius 3, inner radius 0.5 with 15 stacks // and 30 slices. glColor3f(1.0, 1.0, 1.0); glutWireTorus(0.5, 3, 15, 30); // WireSphere glPushMatrix (); glTranslatef (3.0, 3.0, 1.0); glColor3f(1.0, 1.0, 0.0); glutWireSphere(0.75, 20, 20); glPopMatrix (); // Square glBegin (GL_LINE_LOOP); glColor3f(1.0, 0.0, 1.0); glVertex2iv (square[0]); glVertex2iv (square[1]); glVertex2iv (square[2]); glVertex2iv (square[3]); glEnd (); // Top-face glBegin(GL_QUADS); // of the color cube glColor3f(0.0f, 1.0f, 0.0f); // green glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); // Bottom-face glColor3f(1.0f, 0.5f, 0.0f); // orange glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(1.0f, -1.0f, -1.0f); // Front-face glColor3f(1.0f, 0.0f, 0.0f); // red glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); // Back-face glColor3f(1.0f, 1.0f, 0.0f); // yellow glVertex3f(1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(1.0f, 1.0f, -1.0f); // Left-face glColor3f(0.0f, 0.0f, 1.0f); // blue glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right-face glColor3f(1.0f, 0.0f, 1.0f); // magenta glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glEnd(); // of the color cube // Draw a red x-axis, a green y-axis, and a blue z-axis. Each of the // axes are ten units long. glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(10, 0, 0); glColor3f(0, 1, 0); glVertex3f(0, 0, 0); glVertex3f(0, 10, 0); glColor3f(0, 0, 1); glVertex3f(0, 0, 0); glVertex3f(0, 0, 10); glEnd(); // WireSphere, BOUNDARY REPRESENTATION glPushMatrix (); glTranslatef (1.0, -0.5, 2.8); glutWireSphere (0.7, 2.0, 7.6); glPopMatrix (); // Tetrahedron glPushMatrix (); glColor3f (0.5, 1.0, 0.0); glTranslatef (3.4, 2.6, -2.9); glutWireTetrahedron (); glPopMatrix (); // Cylinder using Parametric representation GLUquadricObj *cylinder; glPushMatrix (); glTranslatef (-1.0, 1.2, 2.8); cylinder = gluNewQuadric (); glColor3f (1,0.3, 0.3); gluQuadricDrawStyle (cylinder, GLU_LINE); gluCylinder (cylinder, 0.6, 0.6, 1.5, 6, 4); glPopMatrix (); /* Sweep representation of Solids * Hour Glass * */ float d = 1.0; float theta = 45.0; glPushMatrix (); glTranslatef (3.0, 0.0, 0.0); for(int phi=0 ;phi < 360 ; phi++) { glBegin(GL_LINES); glColor3f(1,0,0); double x = d*sin(toRad(theta))*cos(toRad(phi)); double y = d*cos(toRad(theta)); double z = d*sin(toRad(theta))*sin(toRad(phi)); glVertex3d(x,y,z); glColor3f(0,1,0); glVertex3d(-x,-y,-z); glEnd(); } glPopMatrix (); glFlush(); glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); switch(iShape) { case 1: glutWireSphere(1.0f, 25, 25); break; case 2: glutWireCube(1.0f); break; case 3: glutWireCone(0.30f, 1.1f, 20, 20); break; case 4: glutWireTorus(0.3f, 1.0f, 10, 25); break; case 5: glutWireDodecahedron(); break; case 6: glutWireOctahedron(); break; case 7: glutWireTetrahedron(); break; case 8: glutWireIcosahedron(); break; case 9: glutWireTeapot(1.0f); break; case 11: glutSolidSphere(1.0f, 25, 25); break; case 12: glutSolidCube(1.0f); break; case 13: glutSolidCone(0.30, 1.1f, 20, 20); break; case 14: glutSolidTorus(0.3f, 1.0f, 10, 25); break; case 15: glutSolidDodecahedron(); break; case 16: glutSolidOctahedron(); break; case 17: glutSolidTetrahedron(); break; case 18: glutSolidIcosahedron(); break; default: glutSolidTeapot(1.0f); break; } // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); }