#include<windows.h>
#include<math.h>
#include<gl/gl.h>
#include<gl/glut.h>
#define SIZE 50
const int screenWidth=1366;
const int screenHeight=768;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);//背景颜色为白
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);//画图颜色为黑
glLineWidth(1.0);//画线线粗大小
glMatrixMode(GL_PROJECTION);//设置"相机形状"
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
int i,j;
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<30;i+=2)
for(j=0;j<18;j+=2)
{
if((i+j)%2==0)
{
glColor3f(0.6,0.6,0.6);
glBegin(GL_POLYGON);
glVertex2d(i*SIZE-SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE-SIZE);
glVertex2d(i*SIZE+SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE+SIZE);
glEnd();
glFlush();
}
else
{
glColor3f(0.2,0.2,0.2);
glBegin(GL_POLYGON);
glVertex2d(i*SIZE-SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE-SIZE);
glVertex2d(i*SIZE+SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE+SIZE);
glEnd();
glFlush();
}
}
}
void main(int argc,char** argv)
{
glutInit(&argc,argv); //初始化工具包
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//设置显示模式
glutInitWindowSize(screenWidth,screenHeight);//设置窗口大小
glutInitWindowPosition(0,0);//设置窗口在屏幕上的位置
glutCreateWindow("OpenGL DEMO");
glutDisplayFunc(myDisplay);//注册重画函数
myInit();
glutMainLoop();
}
#include<windows.h>
#include<math.h>
#include<gl/gl.h>
#include<gl/glut.h>
#define SIZE 50
const int screenWidth=1366;
const int screenHeight=768;
void myInit()
{
glClearColor(1.0,1.0,1.0,0.0);//背景颜色为白
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,0.0f,0.0f);//画图颜色为黑
glLineWidth(1.0);//画线线粗大小
glMatrixMode(GL_PROJECTION);//设置"相机形状"
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);
}
void myDisplay()
{
int i,j;
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
for(i=0;i<30;i+=2)
for(j=0;j<18;j+=2)
{
if((i+j)%4==0)
{
glColor3f(0.6,0.6,0.6);
glBegin(GL_POLYGON);
glVertex2d(i*SIZE-SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE-SIZE);
glVertex2d(i*SIZE+SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE+SIZE);
glEnd();
glFlush();
}
else
{
glColor3f(1.0,0.0,0.30);
glBegin(GL_POLYGON);
glVertex2d(i*SIZE-SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE-SIZE);
glVertex2d(i*SIZE+SIZE,j*SIZE);
glVertex2d(i*SIZE,j*SIZE+SIZE);
glEnd();
glFlush();
}
}
}
void main(int argc,char** argv)
{
glutInit(&argc,argv); //初始化工具包
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//设置显示模式
glutInitWindowSize(screenWidth,screenHeight);//设置窗口大小
glutInitWindowPosition(0,0);//设置窗口在屏幕上的位置
glutCreateWindow("OpenGL DEMO");
glutDisplayFunc(myDisplay);//注册重画函数
myInit();
glutMainLoop();
}