资源简介
两个物体,带纹理旋转,有光照,有键盘交互。十分适合计算机图形学的考试课程设计。
代码片段和文件信息
#include
GLfloat x1=0.0f;
GLfloat y1=0.0f;
GLfloat rsize=25;
GLfloat xstep=1.0f;
GLfloat ystep=1.0f;
GLfloat windowWidth;
GLfloat windowHeight;
static GLfloat xrot = 0.0f;
static GLfloat yrot = 0.0f;
#define stripeImageWidth 50
GLubyte stripeImage[3*stripeImageWidth];
void makeStripeImage(void)
{
int j;
for (j = 0; j < stripeImageWidth; j++)
{
stripeImage[3*j] = 255;
stripeImage[3*j+1] =255/1*j;
stripeImage[3*j+2] =200;
}
}
GLfloat sgenparams[] = {2.0 0.0 0.0 0.0};
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_BACKGL_FILL);
glLoadIdentity();
glPushMatrix();
glColor3f(1.00.00.0);
glRotatef(xrot 0.0f 0.1f 0.0f);
xrot+=0.1f;
glRotatef(yrot 0.1f 0.0f 0.0f);
glutSolidTeapot(50);
glTranslatef(15000);
glRotatef(xrot 0.0f 0.1f 0.0f);
xrot+=0.1f;
glRotatef(yrot 0.1f 0.0f 0.0f);
glutSolidSphere(25.025.0100.0);
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
void SpecialKeys(int key int x int y)
{ if(key == GLUT_KEY_UP) yrot -= 5.0f;
if(key == GLUT_KEY_DOWN) yrot += 5.0f;
if(key == GLUT_KEY_LEFT) xrot -= 5.0f;
if(key == GLUT_KEY_RIGHT) xrot += 5.0f;
}
void SetupRC(void)
{
GLfloat mat_specular[] = { 1.0 1.0 1.0 1.0 };
GLfloat mat_shininess[] = { 100.0 };
GLfloat light_position[] = { -50.0 100.0 1000.0 0.0};
GLfloat light_ambient[]={0.0 0.0 0.0 1.0};
GLfloat light_diffuse[]={ 1.0 1.0 1.0 1.0 };
GLfloat light_specular[]={ 1.0 1.0 1.0 1.0 };
GLfloat light_position1[] = { 0.0 100.0 0.0 1.0 };
glClearColor (0.0 0.0 0.0 0.0);
glShadeModel (GL_SMOOTH);
makeStripeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT 1);
glTexEnvf(GL_TEXTURE_ENV GL_TEXTURE_ENV_MODE GL_MODULATE);
glTexParameterf(GL_TEXTURE_1D GL_TEXTURE_WRAP_S GL_REPEAT);
glTexParameterf(GL_TEXTURE_1D GL_TEXTURE_MAG_FILTER G
评论
共有 条评论