Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <cmath>
- #define white 1
- #define black 0
- void reshape(int w, int h)
- {
- glClearColor(0.0, 0.5, 0.0, 0.0f);
- glViewport(0, 0 ,w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- float h2w= (float)h / (float) w;
- float w2h= (float)w / (float) h;
- if(w<=h)
- {
- gluOrtho2D(0.0, 80.0, 0.0, 80.0*h2w);
- }
- else
- {
- gluOrtho2D(0.0*w2h, 80.0, 0.0, 80.0);
- }
- glMatrixMode(GL_MODELVIEW);
- }
- //void init()
- //{
- // glClearColor(0.0, 0.5, 0.0, 0.0f);
- // glMatrixMode(GL_PROJECTION);
- // glLoadIdentity();
- // gluOrtho2D(0.0, 80.0, 0.0, 80.0 );
- // glMatrixMode(GL_MODELVIEW);
- //}
- void drawboard()
- {
- bool state = white;
- for (int i = 0; i<=80; i+=10)
- {
- for (int j = 0; j<=80; j+=10)
- {
- if (state==white)
- {
- glColor3ub(255,255,255);
- state = black;
- }
- else
- {
- glColor3ub(0,0,0);
- state = white;
- }
- glRecti(i,j, i+10,j+10);
- }
- }
- }
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- drawboard();
- glFlush();
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB);
- glutInitWindowPosition(300,200);
- glutInitWindowSize(500,500);
- glutCreateWindow("Cheese Board");
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- // init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement