glPushMatrix(); qMultMatrix(mat); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor); //stars(); GLUquadric* quad = gluNewQuadric(); gluSphere (quad, 10.0d, 40, 40); gluDeleteQuadric(quad); glTranslated(15.0d,15.0d,15.0d); glColor3d(1,0,0); GLUquadric* quad2 = gluNewQuadric(); gluSphere (quad2, 2.0d, 10, 10); gluDeleteQuadric(quad2); GLUquadric* quad3 = gluNewQuadric(); glTranslated(-35.0d,30.0d,10.0d); gluSphere (quad3, 5.5d, 10, 10); gluDeleteQuadric(quad3); glPopMatrix();
//-----------------------------------------------------------------------------// Name: renderSphere()// Desc: Create a sphere centered at cy, cx, cz with radius r, and // precision p. Based on a function Written by Paul Bourke. // http://astronomy.swin.edu.au/~pbourke/opengl/sphere///-----------------------------------------------------------------------------void renderSphere( float cx, float cy, float cz, float r, int p ){ const float PI = 3.14159265358979f; const float TWOPI = 6.28318530717958f; const float PIDIV2 = 1.57079632679489f; float theta1 = 0.0; float theta2 = 0.0; float theta3 = 0.0; float ex = 0.0f; float ey = 0.0f; float ez = 0.0f; float px = 0.0f; float py = 0.0f; float pz = 0.0f; // Disallow a negative number for radius. if( r < 0 ) r = -r; // Disallow a negative number for precision. if( p < 0 ) p = -p; // If the sphere is too small, just render a OpenGL point instead. if( p < 4 || r <= 0 ) { glBegin( GL_POINTS ); glVertex3f( cx, cy, cz ); glEnd(); return; } for( int i = 0; i < p/2; ++i ) { theta1 = i * TWOPI / p - PIDIV2; theta2 = (i + 1) * TWOPI / p - PIDIV2; glBegin( GL_TRIANGLE_STRIP ); { for( int j = 0; j <= p; ++j ) { theta3 = j * TWOPI / p; ex = cosf(theta2) * cosf(theta3); ey = sinf(theta2); ez = cosf(theta2) * sinf(theta3); px = cx + r * ex; py = cy + r * ey; pz = cz + r * ez; glNormal3f( ex, ey, ez ); glTexCoord2f( -(j/(float)p) , 2*(i+1)/(float)p ); glVertex3f( px, py, pz ); ex = cosf(theta1) * cosf(theta3); ey = sinf(theta1); ez = cosf(theta1) * sinf(theta3); px = cx + r * ex; py = cy + r * ey; pz = cz + r * ez; glNormal3f( ex, ey, ez ); glTexCoord2f( -(j/(float)p), 2*i/(float)p ); glVertex3f( px, py, pz ); } } glEnd(); }}
void Patch::draw() const{ GLbyte *pBytes; glPushMatrix(); qMultMatrix(mat); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor); GLint Width, Height, Components; GLenum Format; GLUquadric* quad = gluNewQuadric();//---------- glPixelStorei (GL_UNPACK_ALIGNMENT, 1); pBytes = gltLoadTGA("earth.tga", &Width, &Height, &Components, &Format); if (pBytes == NULL) exit (2); glTexImage2D(GL_TEXTURE_2D, 0, Components, Width, Height, 0, Format, GL_UNSIGNED_BYTE, pBytes); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,15);//---------- gluQuadricTexture(quad, GL_TRUE); gluQuadricDrawStyle(quad, GLU_FILL); gluSphere (quad, 10.0d, 20, 20); gluDeleteQuadric(quad); free(pBytes); glTranslated(15.0d,15.0d,15.0d); glColor3d(1,0,0); glDisable(GL_TEXTURE_2D);//---------------------------------------------------------------------------------- GLUquadric* quad2 = gluNewQuadric(); glEnable(GL_TEXTURE_2D); GLbyte *pBytes2; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); pBytes2 = gltLoadTGA("luna.tga", &Width, &Height, &Components, &Format); if (pBytes2 == NULL) exit (2); glTexImage2D(GL_TEXTURE_2D, 0, Components, Width, Height, 0, Format, GL_UNSIGNED_BYTE, pBytes2); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D,15); gluQuadricTexture(quad2, GL_TRUE); gluQuadricDrawStyle(quad2, GLU_FILL); gluSphere (quad2, 2.0d, 10, 10); gluDeleteQuadric(quad2); free(pBytes2); glTranslated(15.0d,15.0d,15.0d); glColor3d(1,0,0); glDisable(GL_TEXTURE_2D);//------------------------------------------------------------------ GLUquadric* quad3 = gluNewQuadric(); glEnable(GL_TEXTURE_2D); GLbyte *pBytes3; glPixelStorei (GL_UNPACK_ALIGNMENT, 1); pBytes3 = gltLoadTGA("luna.tga", &Width, &Height, &Components, &Format); if (pBytes3 == NULL) exit (2); glTexImage2D(GL_TEXTURE_2D, 0, Components, Width, Height, 0, Format, GL_UNSIGNED_BYTE, pBytes3); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D,15); gluQuadricTexture(quad3, GL_TRUE); gluQuadricDrawStyle(quad3, GLU_FILL); gluSphere (quad3, 5.5d, 20, 20); gluDeleteQuadric(quad3); free(pBytes3); glTranslated(-35.0d,30.0d,10.0d); glColor3d(1,0,0); glDisable(GL_TEXTURE_2D); glPopMatrix();