Пример #1
0
/*
 * initSphereList(GLuint *listID, GLdouble scale) - create a display list
 * to render the sphere more efficently than calling lots of trigonometric
 * functions for each frame.
 */
void initSphereList(GLuint *listID)
{
  *listID = glGenLists(1);
  
  glNewList(*listID, GL_COMPILE);
  drawTexturedSphere(1.0, 20); // Radius 1.0, 20 segments
  glEndList();
}
void drawPlanet(jrPlanet *pPlanet) {

	glPushMatrix(); //begin drawing
	glPushName((unsigned int) pPlanet);
	glPushAttrib(GL_ALL_ATTRIB_BITS);

	if (pPlanet->iType < SUN || !g_bTexturesOn) {
		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pPlanet->afAmbient); //set the materials of the planet
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pPlanet->afDiffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, g_af_SphereSpecular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, g_f_SphereShininess);
	}

	glTranslatef(pPlanet->afPosition[0], pPlanet->afPosition[1], pPlanet->afPosition[2]); //move the position so we can draw at the correct point
	glRotatef(pPlanet->fRotationAngle, pPlanet->afPosition[0] - pPlanet->fSize, pPlanet->afPosition[1] - pPlanet->fSize, pPlanet->afPosition[2] - pPlanet->fSize);

	int iType = pPlanet->iType;

	if (!g_bTexturesOn && pPlanet->iType >= SUN) {
		iType = SPHERE;
	}
	else if (g_bTexturesOn && pPlanet->iType >= SUN) {
		iType = SPECIAL;
	}


	switch (iType) { //change to constants

	case SPHERE:
		glutSolidSphere(pPlanet->fSize, pPlanet->iSlices, pPlanet->iSegments); //draw the planet
		break;
	case CUBE:
		glutSolidCube(pPlanet->fSize * 2.0f);
		break;
	case CONE:
		glutSolidCone(pPlanet->fSize, pPlanet->fSize * 2.0f, pPlanet->iSlices, pPlanet->iSegments);
		break;
	case TEAPOT:
		glutSolidTeapot(pPlanet->fSize);
		break;
	case SPECIAL:
		drawTexturedSphere(pPlanet);
		break;
	}

	glPopName();
	glPopMatrix(); //end drawing

	if (g_bTrailsOn && !pPlanet->m_bFixed) {
		drawTrail(pPlanet);
	}

	glPopAttrib();

}
Пример #3
0
void gl_draw(){
  glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
  
  glLoadIdentity();
  glTranslatef(0,0,zoom);
  glRotatef(yRot, 1, 0, 0);
  glRotatef(xRot, 0, 1, 0);
  glScalef( .25, .25, .25 );
  
  float time = (clock()-clock_0)/(float)(CLOCKS_PER_SEC);
  
  glPushMatrix();
  glRotatef(30.0f*time, 0.0f, 0.0f, 1.0f);
  glTranslatef(5.0f, 0.0f, 0.0f);
  float lightpos0[4]={0.0f, 0.0f, 0.0f, 1.0f};
  glLightfv(GL_LIGHT0, GL_POSITION, lightpos0);
  glPopMatrix();
  
  glPushMatrix();
  glRotatef(45.0f*time, 0.0f, 0.0f, 1.0f);
  glColor3f(1.0f, 1.0f, 1.0f);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glBindTexture(GL_TEXTURE_2D, textureID);
  
  glUseProgram( programObj );
  
  if(drawTeapot){
    glutSolidTeapot(1.0); }
  else{
    drawTexturedSphere(1.0, 20); }
  
  glUseProgram(0);
  
  glPopMatrix();
  
  // Disable lighting again, to prepare for next frame.
  glDisable(GL_LIGHTING);
  glDisable(GL_LIGHT0);
  
  
  glutSwapBuffers();
}