}
}
// 定义地球的材质并绘制地球 { }
glutSwapBuffers();
GLfloat earth_mat_ambient[] = {0.0f, 0.0f, 0.5f, 1.0f}; GLfloat earth_mat_diffuse[] = {0.0f, 0.0f, 0.5f, 1.0f}; GLfloat earth_mat_specular[] = {0.0f, 0.0f, 1.0f, 1.0f}; GLfloat earth_mat_emission[] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat earth_mat_shininess = 30.0f;
glMaterialfv(GL_FRONT, GL_AMBIENT, earth_mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, earth_mat_specular); glMaterialfv(GL_FRONT, GL_EMISSION, earth_mat_emission); glMaterialf (GL_FRONT, GL_SHININESS, earth_mat_shininess);
glRotatef(angle, 0.0f, -1.0f, 0.0f); glTranslatef(5.0f, 0.0f, 0.0f); glutSolidSphere(2.0, 40, 32);
void myIdle(void)
{ }
int main(int argc, char* argv[]) { }
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(200, 200); glutInitWindowSize(WIDTH, HEIGHT); glutCreateWindow(\光照演示\glutDisplayFunc(&myDisplay); glutIdleFunc(&myIdle); glutMainLoop(); return 0; angle += 1.0f; if( angle >= 360.0f )
angle = 0.0f;
myDisplay();
4颜色和光照
使用光源设置、材质设置和法向量设置。 #include
#define DELTA 0.1 #define PI2 2*3.14159 #define checkImageWidth 64 #define checkImageHeight 64
enum {ROTATE,TRANSLATE,SCALE};
typedef struct {
int x; int y; int z;
} Point3I;
GLuint m_texName[2]; //纹理名称
GLubyte checkImage[checkImageHeight][checkImageWidth][3]; GLubyte image1D[checkImageWidth][3];
GLfloat diffuseMaterial[4] = { 0.5, 0.5, 0.5, 1.0 };
double parabolicSurf[36][10][3]; double vertexNormal[36][10][3];
int m_leftDown; //鼠标是否拖动 double m_clientWidth; //客户区宽 double m_clientHeight; //客户区高 double m_clip;
GLdouble m_rotMatrix[16]; //旋转矩阵 double m_axis[3]; //旋转轴 double m_rotation; //旋转角 double m_ratio; //缩放比例 double m_translate[3]; //平移量 int m_transMode; int flag;
Point3I m_downPoint; //鼠标相对于窗口左上角的象素坐标
void Localize(double p[]) { 放?
行
// int i,j; double e[3];
double pMatrix[16],a[3][3]; //模型视图矩阵
glGetDoublev(GL_MODELVIEW_MATRIX,pMatrix);//取模型视图矩阵A,元素按列存
for(i=0;i<3;i++) //取矩阵左上角三阶矩阵
for(j=0;j<3;j++)
a[i][j]=pMatrix[i+4*j]; //a[i]表示模型视图矩阵的第i