#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void setup(){
glClearColor(1.0, 1.0, 1.0, 1.0);
gluOrtho2D(-01.0, 10.0, -01.01, 10.0);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
// boxes
glColor3f(1.0, 0.0, 1.1);
glRectf(1.0, 1.0, 5.0, 5.0); // x1, y1, x2, y2
glColor3f(0.0, 1.0, 0.0);
glRectf(6.0, 1.0, 8.0, 5.0);
glColor3f(0.0, 0.0, 1.0);
glRectf(1.0, 6.0, 5.0, 8.0);
glColor3f(0.0, 1.0, 1.0);
glRectf(6.0, 6.0, 8.0, 8.0);
// box lines
glColor3f(0.4, 0.4, 1.0);
glBegin(GL_LINES);
// left
glVertex2f(0.5, 0.5); // x, y
glVertex2f(0.5, 8.5);
// top
glVertex2f(0.5, 8.5);
glVertex2f(8.5, 8.5);
// right
glVertex2f(8.5, 8.5);
glVertex2f(8.5, 0.5);
// bottom
glVertex2f(8.5, 0.5);
glVertex2f(0.5, 0.5);
glEnd();
// coordinate system
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
// horizontal
glVertex2f(-10.0, 0.0);
glVertex2f(10.0, 0.0);
// vertical
glVertex2f(0.0, 10.0);
glVertex2f(0.0, -10.0);
glEnd();
glFlush();
}
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(200, 100);
glutInitWindowSize(400, 300);
glutCreateWindow("Hello World");
glutDisplayFunc(display);
setup();
glutMainLoop();
return 0;
}
No comments:
Post a Comment