19,468
社区成员
发帖
与我相关
我的任务
分享
void DrawBackground(GLuint nSize)
{
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glColor3f(1.0f,1.0f,1.0f);
GLint x=-(GLint)nSize/2,y=x;
GLint width=(GLint)nSize/2,height=width;
glBegin(GL_QUADS);
for (int i=x;i<width;i++)
{
for (int j=y;j<height;j++)
{
glVertex3i(i,0,j);
glVertex3i(i+1,0,j);
glVertex3i(i+1,0,j+1);
glVertex3i(i,0,j+1);
}
}
glEnd();
}
void CMainWnd::DrawScene()
{
// TODO: Replace the following sample code with your code to draw the scene.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear buffers
glLoadIdentity(); // Load identity matrix
/*set camera*/
gluLookAt(0,50,50,0,0,0,0,1,0);
// Add a light source
GLfloat glfLightPos[] = {0.0f, 4.0f, 0.0f, 1.0f};//点光源在Y轴正方向上
glLightfv(GL_LIGHT0, GL_POSITION, glfLightPos);
/*draw background*/
DrawBackground(32);//在X轴和Z轴的平面上画一个32x32个小方片组成的幕布,其中心在原点
glFlush();
}