void lighthouse() { glBegin(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); glColor3f(0.5, 0.35, 0.05); glTranslatef(0.0, 0.0, 1.0); glutSolidDodecahedron(); glTranslatef(1.0, 0.0, 1.0); glutSolidDodecahedron(); glTranslatef(3.0, 0.0, 1.0); glutSolidDodecahedron(); glTranslatef(3.0, 0.0, 1.0); glutSolidDodecahedron(); glTranslatef(0.0, 0.0, 0.0); glutSolidDodecahedron(); glutSolidCube(3); glTranslatef(0.0, 0.0, 0.0); GLUquadricObj * quadObj; quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, GL_LINE); glColor3f(1.0, 1.0, 1.0); glRotatef(-90.0, 1.0, 0.0, 0.0); gluDisk(quadObj, 0.0, 1.0, 35.0, 1.0); gluCylinder(quadObj, 1.0, 1.0, 8.0, 33.0, 1.0); glTranslatef(0.0, 0.0, 2.0); gluCylinder(quadObj, 1.0, 1.0, 3.0, 33.0, 1.0); gluDisk(quadObj, 0.0, 1.0, 35.0, 1.0); glTranslatef(0.0, 0.0, -2.0); glRotatef(90.0, 1.0, 0.0, 0.0); glRotatef(animate,0,1,0); glColor3f(0.0, 0.0, 1.0); glTranslatef(0,8.8,0); glPushMatrix(); glRotatef(90,1,0,0); glutSolidCube(1.6); glBegin(GL_LIGHT_MODEL_AMBIENT); glColor3f(1.0, 1.0, 0.0); glTranslatef(0.0,1.0,0.0); glutSolidSphere(0.6,30,3.0); glColor3f(1.0, 0.0, 0.0); glRotatef(-180,1,10,0); glTranslatef(-0.3,-1.0,0.9); glutSolidCone(1.0,2.0,40.0,10.0); glColor3f(1.0, 1.0, 1.0); glTranslatef(0.0,10.0,10.0); glutSolidSphere(1.0,30.0,8.0); glPopMatrix(); glEnd(); glFlush(); }
void drawSceneObjects(void) { glPushMatrix(); // red cube glTranslatef(0.0f, 0.0f, 0.0f); glColor4f(1.0, 0.0, 0.0, 1.0); glutSolidCube(0.1); glPopMatrix(); glPushMatrix(); // blue sphere glTranslatef(0.0f, 0.0f, -2.0f); glColor4f(0.0, 0.5, 1.0, 1.0); glutSolidSphere(1, 30, 30); glPopMatrix(); glPushMatrix(); // orange sphere glTranslatef(3.0f, 0.0f, 0.0f); glColor4f(1.0, 0.5, 0.0, 1.0); glutSolidSphere(1, 15, 15); glPopMatrix(); glPushMatrix(); // pink whosum glTranslatef(-3.0f, 0.0f, -2.0f); glColor4f(1.0, 0.5, 1.0, 1.0); glutSolidTorus(0.1, 0.5, 15, 15); glPopMatrix(); glPushMatrix(); // yellow whassum glTranslatef(-3.0f, 0.0f, -20.0f); glColor4f(1.0, 1.0, 0.0, 1.0); glutSolidDodecahedron(); glPopMatrix(); }
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 cene_doca(){ glPushMatrix(); glColor3d(0.5,1,0.9); glTranslated(2,2,-6); glRotated(-20, 0, 5, 0); glutSolidDodecahedron(); glPopMatrix(); }
/* metoda care deseneaza un asteroid avand culoarea specificata */ void Asteroid::draw (int color) { glPushMatrix(); if (color == BROWN_ID) { glColor4f(BROWN, 0.5); } if (color == RED_ID) { glColor4f(RED, 0.5); } glTranslatef(position.x, position.y, position.z); glRotatef(spin, 0, 1, 0); glutSolidDodecahedron(); glPopMatrix(); }
void yangbiru(){ if(ert<=60){if(ert<30)ert+=0.25;else ert+=5; if(ert==60)yui=60;} else if(yui>=0){if(yui>30)yui-=0.25;else yui-=5; if(yui==0)ert=0.0;} glPushMatrix(); //tempat duduk glTranslatef( 0, -2.5, 0); glColor3f(2.0,1.0,0.0); glutSolidDodecahedron(); glColor3f(0.0,0.5,0.5); glutSolidCube(2.5); glPopMatrix(); }
//------------------------------------------------------------------------------ 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 scene(void) { /* 表示図形をディスプレイリストに登録 */ int l = glGenLists(2); /* 内側の立方体 */ cube = l; glNewList(cube, GL_COMPILE); glMaterialfv(GL_FRONT, GL_DIFFUSE, red); glutSolidCube(2.0); glEndList(); /* 外側の12面体 */ dodeca = l + 1; glNewList(dodeca, GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue); glutSolidDodecahedron(); glEndList(); }
void Asteroid::Render(){ if(alive){ glPushMatrix(); static GLfloat material_ambient1[] = { 179.0f/255.0f, 157.0f/255.0f, 83.0f/255.0f, 1.0f }; //static GLfloat material_diffuse1[] = { 179.0f/255.0f, 157.0f/255.0f, 83.0f/255.0f, 1.0f }; static GLfloat material[] = { culoare.x,culoare.y,culoare.z,1.0f}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material); glMaterialfv(GL_FRONT,GL_SPECULAR,material_ambient1); glTranslatef(pozitie.x,pozitie.y,pozitie.z); glScalef(size,size,size); glutSolidDodecahedron(); glPopMatrix(); }else{ init(1); alive = true; } }
void displayBall(void){ int i; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, fire); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 100, 100, 0, GL_RGBA, GL_UNSIGNED_BYTE, fireTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); for(i=0;i<numSpheres;i++){ glPushMatrix(); glTranslatef(spheres[i][0], spheres[i][1], spheres[i][2]); glScalef(10.0, 10.0, 10.0); glutSolidDodecahedron(); //glutSolidSphere(spheres[i][3], 50, 50); //glutSolidCube(spheres[i][3]); glPopMatrix(); } glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glEnable(GL_COLOR_MATERIAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0, 0.0, 0.0, 0.2); for(i=0;i<numSpheres;i++){ glPushMatrix(); //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, sphere_mat); glTranslatef(spheres[i][0], spheres[i][1], spheres[i][2]+5); gluSphere(qsphere,20, 50, 50); glPopMatrix(); } glDisable(GL_COLOR_MATERIAL); glDisable(GL_BLEND); }
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(); }
// Draw our world void display_1(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 ,"Solid Cube"); if (shape == 1) Sprint(-3, -7 ,"Solid Cone"); if (shape == 2) Sprint(-3, -7 ,"Solid Sphere"); if (shape == 3) Sprint(-3, -7 ,"Solid Torus"); if (shape == 4) Sprint(-3, -7 ,"Solid Dodecahedron"); if (shape == 5) Sprint(-3, -7 ,"Solid Octahedron"); if (shape == 6) Sprint(-3, -7 ,"Solid Tetrahedron"); if (shape == 7) Sprint(-3, -7 ,"Solid Icosahedron"); if (shape == 8) Sprint(-3, -7 ,"Solid 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) glutSolidCube(10); // Draw a cube if (shape == 1) glutSolidCone(5,10, 16,16); // Draw a Cone if (shape == 2) glutSolidSphere(5, 16,16 ); // Draw a Sphere if (shape == 3) glutSolidTorus( 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); glutSolidOctahedron(); } if (shape == 6) { glScalef( 5.0, 5.0, 5.0); glutSolidTetrahedron(); } if (shape == 7) { glScalef( 5.0, 5.0, 5.0); glutSolidIcosahedron(); } if (shape == 8) glutSolidTeapot( 5 ); glutSwapBuffers(); }
void Inspector::display(void){ glutSetWindow(this->winID); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, bgTexture); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1, -1, -.9); glTexCoord2f(0.0, 1); glVertex3f(-1, 1, -.9); glTexCoord2f(1, 1); glVertex3f(1, 1, -.9); glTexCoord2f(1, 0.0); glVertex3f(1, -1, -.9); glEnd(); glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glScaled(transformations[6] / (GLfloat)ts.getBoardWidth(), transformations[7] / (GLfloat)ts.getBoardHeight(), transformations[8] / (GLfloat)ts.getBoardHeight()); glTranslated(-(ts.getBoardWidth() / 2) + transformations[0], -ts.getBoardHeight() + transformations[1], transformations[2]); glRotated(transformations[5], 0, 0, 1); glRotated(transformations[4], 0, 1, 0); glRotated(transformations[3], 1, 0, 0); int* board = ts.getBoardState(); float x = 0, y = ts.getBoardHeight(); for (int h = 0; h < ts.getBoardHeight(); h++){ for (int w = 0; w < ts.getBoardWidth(); w++){ if (board[h*ts.getBoardWidth() + w]){ //tpBase.draw(w,y-h,0); glPushMatrix(); glTranslatef(w, y - h, 0); if (bObj){ glScalef(.55, .55, .55); tpBase.draw(); } else { glScalef(.35, .35, .35); glutSolidDodecahedron(); } glPopMatrix(); } } } // char k[5]; sprintf_s(k, 5, "%i", ins.getScore()); glutSetWindowTitle(k); glPopMatrix(); glFlush(); glutSetWindow(1); glutPostRedisplay(); }
static void hugsprim_glutSolidDodecahedron_2(HugsStackPtr hugs_root) { glutSolidDodecahedron(); hugs->returnIO(hugs_root,0); }
void DisplayFunc(void) { double xfactor=1.0, yfactor=1.0; double Eye =0.0; int i; if(ps.w < ps.h) { xfactor = 1.0; yfactor = ps.h/ps.w; } else if(ps.h < ps.w) { xfactor = ps.w/ps.h; yfactor = 1.0; } glClear(GL_COLOR_BUFFER_BIT); for(i=0;i<2;i++) { glEnable(GL_LIGHT0 + i); glClear(GL_DEPTH_BUFFER_BIT); if(i==0) /* left eye - RED */ { Eye = ps.eye; glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE); } else /* if(i==1) right eye - BLUE */ { Eye = -ps.eye; glColorMask(GL_FALSE,GL_FALSE,GL_TRUE,GL_TRUE); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( (-(ps.w/(2.0*PIXELS_PER_INCH))+Eye) *(ps.znear/ps.zscreen)*xfactor, (ps.w/(2.0*PIXELS_PER_INCH)+Eye) *(ps.znear/ps.zscreen)*xfactor, -(ps.h/(2.0*PIXELS_PER_INCH))*(ps.znear/ps.zscreen)*yfactor, (ps.h/(2.0*PIXELS_PER_INCH))*(ps.znear/ps.zscreen)*yfactor, ps.znear, ps.zfar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(Eye,0.0,0.0); glTranslated(0,0,-ps.zscreen); switch(ps.solidmode) { case 1: { glTranslated(cos(ps.RotationY*M_PI/180.0), 0, -sin(ps.RotationY*M_PI/180.0) ); glRotated(ps.RotationY, 0.0,0.1,0.0); glPushMatrix(); glScalef(0.5,0.5,0.5); glutSolidDodecahedron(); glPopMatrix(); break; } case 2: { glTranslated(cos(ps.RotationY*M_PI/180.0), 0, -sin(ps.RotationY*M_PI/180.0) ); glRotated(ps.RotationY, 0.0,0.1,0.0); glutSolidIcosahedron(); break; } case 3: { glRotated(60.0, 1 , 0, 0); glTranslated(cos(ps.RotationY*M_PI/180.0), 0, -sin(ps.RotationY*M_PI/180.0) ); glRotated(ps.RotationY, 0.0,0.1,0.0); glutSolidTeapot(1.0); break; } case 4: { double SunRadius = 0.2; double SunToEarth = 1.0; double EarthRadius = 0.15; glutSolidSphere(SunRadius, 20, 16); /* draw sun */ glRotated(60.0, 1 , 0, 0); glPushMatrix(); glRotated(90.0, 1 , 0, 0); glutSolidTorus(0.01,SunToEarth, 10,50); glPopMatrix(); glRotated(ps.RotationY, 0.0,0.1,0.0); glTranslatef (SunToEarth, 0.0, 0.0); glutSolidSphere(EarthRadius, 10, 8); /* draw earth */ break; } } glDisable(GL_LIGHT0 + i); } glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glutSwapBuffers(); }
// 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(); }
void PointSourceLight::drawPost() { glPushMatrix(); glTranslatef(_position->getX(), _position->getY(), _position->getZ()-1.5); glScalef(0.5, 0.5, 0.5); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, getMaterial()->getAmbient()); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, getMaterial()->getDiffuse()); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, getMaterial()->getSpecular()); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, getMaterial()->getShine()); glColor3f(219/255.0, 232/255.0, 181/255.0); glTranslatef(0, 0, 1); glutSolidDodecahedron(); /*glBegin(GL_POLYGON); GLUquadricObj *obj = gluNewQuadric(); gluCylinder(obj, 1, 1, 3, 20, 20); glEnd();*/ glPopMatrix(); glPushMatrix(); glTranslatef(0, 0, 2.5); glLineWidth(1); glColor3f(0, 0, 0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(0, 0, 1); glEnd(); glPopMatrix(); glPushMatrix(); GLfloat amb[] = { 1.0f,0.25f,0.0f,1.0f }; GLfloat diff[] = { 0.62f,0.44f,0.2f,1.0f }; GLfloat spec[] = { 1.0f,0.7f,0.7f,1.0f }; GLfloat shine = 128.0f; GLfloat emission[] = { 1.0, 0.25f, 0.0, 1.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shine); if (getState()) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission); glTranslatef(0, 0, 4); glScalef(0.25, 0.25, 0.75); glColor3f(255, 64 / 255.0, 0); glutSolidSphere(1, 10, 10); glPopMatrix(); glPopMatrix(); GLfloat default[] = { 0, 0, 0, 1.0 }; glMaterialfv(GL_FRONT, GL_EMISSION, default); } void PointSourceLight::setMaterial(Material* material) { _material = material; } Material* PointSourceLight::getMaterial() { return _material; }
void SpaceShip::render () { // Predicted Route glColor4f(1.0, 0.0, 0.0, 1.0); SimpleColor(1, 0, 0, 1).setEmission(); glLineWidth(1.0f); glBegin(GL_LINE_STRIP); { for (auto v : m_predicted_route) v.vertex(); } glEnd(); SimpleColor(0, 0, 0, 1).setEmission(); // reset emission // Navigator m_navigator->renderPath(m_quat); glColor4f(1.0, 1.0, 1.0, 1.0); glm::mat4 dirmat = glm::toMat4(m_quat); glMultMatrixf(glm::value_ptr(dirmat)); glRotated(180, 0, 1, 0); game->getCamera()->getShaderManager()->requestShader("spaceship"); // Main body: SimpleVec3d p1(-SPACESHIP_X, -SPACESHIP_Y, -SPACESHIP_Z); SimpleVec3d p2( SPACESHIP_X, SPACESHIP_Y, SPACESHIP_Z); makeCuboid(p1, p2, 3, 3, 3); // Backside glPushMatrix(); { glTranslatef(-SPACESHIP_X, 0, -SPACESHIP_Z); glutSolidSphere(SPACESHIP_Y, DETAIL, DETAIL); } glPopMatrix(); glPushMatrix(); { glTranslatef(SPACESHIP_X, 0, -SPACESHIP_Z); glutSolidSphere(SPACESHIP_Y, DETAIL, DETAIL); } glPopMatrix(); // Left / Right glPushMatrix(); { glTranslatef(SPACESHIP_X, 0, -SPACESHIP_Z); makeCylinder(SPACESHIP_Y, SPACESHIP_Z*2, DETAIL); } glPopMatrix(); glPushMatrix(); { glTranslatef(-SPACESHIP_X, 0, -SPACESHIP_Z); makeCylinder(SPACESHIP_Y, SPACESHIP_Z*2, DETAIL); } glPopMatrix(); // Front glPushMatrix(); { glColor4f(0, 0.1, 0.4, 0.5); glTranslatef(-SPACESHIP_X, 0, SPACESHIP_Z); glRotatef(90, 0, 1, 0); GLUquadric* qobj = gluNewQuadric(); gluQuadricNormals(qobj, GLU_SMOOTH); gluCylinder(qobj, SPACESHIP_Y, SPACESHIP_Y, (SPACESHIP_X*2), DETAIL, DETAIL); } glPopMatrix(); glPushMatrix(); { glColor4f(0, 0.1, 0.4, 0.5); glTranslatef(-SPACESHIP_X, 0, SPACESHIP_Z); glutSolidSphere(SPACESHIP_Y, DETAIL, DETAIL); } glPopMatrix(); glPushMatrix(); { glColor4f(0, 0.1, 0.4, 0.5); glTranslatef(SPACESHIP_X, 0, SPACESHIP_Z); glutSolidSphere(SPACESHIP_Y, 100, 100); } glPopMatrix(); // Cockpit glPushMatrix(); { glColor4f(0, 0.1, 0.4, 0.5); glScalef(SPACESHIP_Y, SPACESHIP_Y, SPACESHIP_Y); glutSolidDodecahedron(); } glPopMatrix(); }
// 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(); }
/* Desenare satelit */ int Satellite::drawSatellite(){ glNormal3f(0,1,0); glTranslatef(posx, posy, posz); //daca nu e de tip power up if(bonus == false) { //daca nu explodeaza deseneaza cu culoarea obisnuita if(explodes == false ) { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,color); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color); } //daca explodeaza se folosesc culorile pt explozie if(explodes == true) { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient4f1.Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse4f1.Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular4f1.Array()); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess1); } //scalare glScalef(Size-1, Size-1, Size-1); //rotire in jurul axelor ox si oz glRotatef(spin, 0, spin/2.0,0); //setare tipa asteroid => icoshaedron/dodecahedron if(type == ICOS)glutSolidIcosahedron(); else glutSolidDodecahedron(); //desenare inele satelit glRotatef(90,1,0,0); glRotatef(spin, 0, spin/2.0,0); glutSolidTorus(0.05,2.2,20,20); glutSolidTorus(0.05,2,20,20); glutSolidTorus(0.05,1.8,20,20); } //satelit bonus; acelasi mod de desenare ca la satelitii normali if(bonus == true) { if(explodes == false) { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,Vector4D(1,0,0,1).Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Vector4D(1,0,0,1).Array()); glScalef(Size, Size, Size); glutSolidSphere(0.9,20,20); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,Vector4D(0,0,1,1).Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Vector4D(0,0,1,1).Array()); glRotatef(90,1,0,0); glRotatef(spin, 0, spin/2.0,0); glutSolidTorus(0.05,1.7,20,20); glutSolidTorus(0.05,1.4,20,20); glutSolidTorus(0.05,1.1,20,20); } if(explodes == true) { glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient4f1.Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse4f1.Array()); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular4f1.Array()); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess1); glScalef(Size, Size, Size); glutSolidSphere(0.9,20,20); glRotatef(90,1,0,0); glRotatef(spin, 0, spin/2.0,0); glutSolidTorus(0.05,1.7,20,20); glutSolidTorus(0.05,1.4,20,20); glutSolidTorus(0.05,1.1,20,20); } } time += 0.01; //daca are loc explozia atunci nu se mai deplaseaza if(explodes == false) { posx += (v0 * time) * dx/7.0; posy += (v0 * time) * dy/7.0; posz += (v0 * time ) * dz/7.0; } //daca satelitul debaseste spatiul de joc se reseteaza parametri if(posx < 0 || posx > box || posy < 0 || posy > box || posz > box){ destroy(); return 1; } if(explosion != NULL && explodes) { // daca satelitul explodeaza randeaza lumina pt explozie + efectul de fade out explosion->Renderexplight(); if(counter < 100) { explosion->SetAttenuation(explosion->getAttenuation()-0.1); } else if(counter < 200) { explosion->SetAttenuation(explosion->getAttenuation()+0.05); } else if(counter<300) { ambient4f1.a-=FADE; diffuse4f1.a-=FADE; specular4f1.a-=FADE; } if(counter<300) { counter++; } else { explosion->Disable(); explodes = false; delete explosion; explosion = NULL; destroy(); counter=0; } } if(spin>360)spin =0; else spin+=0.5f; return 0; }
/** SolidDodecahedron () -> None */ static int glut_solid_dodecahedron(lua_State *L) { glutSolidDodecahedron(); }
//------------------------------------------------------------------------- // 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 (); } }
static void drawSolidDodecahedron(void) { glutSolidDodecahedron (); }
/* * Class: gruenewa_opengl_GLUT__ * Method: glutSolidDodecahedron * Signature: ()V */ JNIEXPORT void JNICALL Java_gruenewa_opengl_GLUT_00024_glutSolidDodecahedron (JNIEnv * jenv, jobject jobj) { glutSolidDodecahedron(); }
//显示回调函数 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(); }
static void Redisplay(void) { static const GLfloat px[3] = { 1.2, 0, 0}; static const GLfloat nx[3] = {-1.2, 0, 0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(Xrot, 1.0f, 0.0f, 0.0f); glRotatef(Yrot, 0.0f, 1.0f, 0.0f); glEnable(GL_LIGHTING); glPushMatrix(); glScalef(0.5, 0.5, 0.5); glutSolidDodecahedron(); glPopMatrix(); glDisable(GL_LIGHTING); glColor3f(0, 1, 0); glBegin(GL_LINES); glVertex3f(-1, 0, 0); glVertex3f( 1, 0, 0); glEnd(); glColor3f(1, 1, 0); if (Bitmap) { glRasterPos3fv(px); BitmapText("+X"); glRasterPos3fv(nx); BitmapText("-X"); } else { glUseProgram(Program); /* vertex positions (deltas) depend on texture size and window size */ if (uScale != -1) { glUniform2f(uScale, 2.0 * TEX_WIDTH / WinWidth, 2.0 * TEX_HEIGHT / WinHeight); } /* draw +X */ glBindTexture(GL_TEXTURE_2D, Textures[0]); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3fv(px); glTexCoord2f(1, 0); glVertex3fv(px); glTexCoord2f(1, 1); glVertex3fv(px); glTexCoord2f(0, 1); glVertex3fv(px); glEnd(); /* draw -X */ glBindTexture(GL_TEXTURE_2D, Textures[1]); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex3fv(nx); glTexCoord2f(1, 0); glVertex3fv(nx); glTexCoord2f(1, 1); glVertex3fv(nx); glTexCoord2f(0, 1); glVertex3fv(nx); glEnd(); glUseProgram(0); } glPopMatrix(); glutSwapBuffers(); }