画棋盘—OpenGL

画一个棋盘,使用C++


#include<windows.h>
#include<gl/gl.h>
#include<gl/glu.h>
#include<gl/glut.h>
#include<iostream.h>
#include<math.h>

//////////////////////////////////
void myInit()
{
 glClearColor(1.0,1.0,1.0,0.0);
 glLineWidth(3.0);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 gluOrtho2D(0.0,640,0.0,480);
}
/////////////////////////////////////
void myDisplay()
{
 glClear(GL_COLOR_BUFFER_BIT);
 int width=30,length=40,num=0;
 for(int i=0;i<16;i++)
 {
  for(int j=0;j<16;j++)
  {
   if(num%2==0)
   {
    glColor3f(0.6f,0.6f,0.6f);
   }
   else
   {
    glColor3f(0.2f,0.2f,0.2f);
   }
   glRecti(width+i*25,length+j*25,width+(i+1)*25,length+(j+1)*25);
   num++;
   cout<<num<<endl;
  }
  num++;
 }
 glFlush();
}
///////////////////////////////////////
void main(int argc,char **argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
 glutInitWindowSize(640,480);
 glutInitWindowPosition(100,150);
 glutCreateWindow("my second attempt");
 glutDisplayFunc(myDisplay);
 myInit();
 glutMainLoop();
}

当初为了测试程序的正确性,添加了测试程序。读者使用时可以自己去掉

你可能感兴趣的:(c,测试,buffer)