Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- void shapes(void) {
- float y1 = 0.0;
- float y2 = 0.0;
- float y3 = 0.1;
- float y4 = 0.1;
- for (int j = 0; j < 8; j++) {
- float x1 = 0.0;
- float x2 = 0.1;
- float x3 = 0.1;
- float x4 = 0.0;
- for (int i = 0; i < 8; i++) {
- glBegin(GL_QUADS);
- if ((j % 2) != 0) {
- if ((i % 2) != 0) {
- glColor3f(1.0, 1.0, 1.0);
- }
- else {
- glColor3f(0.2, 0.2, 0.2);
- }
- }
- if ((j % 2) == 0) {
- if ((i % 2) != 0) {
- glColor3f(0.2, 0.2, 0.2);
- }
- else {
- glColor3f(1.0, 1.0, 1.0);
- }
- }
- glVertex3f(x1, y1, 0.0);
- glVertex3f(x2, y2, 0.0);
- glVertex3f(x3, y3, 0.0);
- glVertex3f(x4, y4, 0.0);
- glEnd();
- x1 += 0.1;
- x2 += 0.1;
- x3 += 0.1;
- x4 += 0.1;
- }
- y1 += 0.1;
- y2 += 0.1;
- y3 += 0.1;
- y4 += 0.1;
- }
- }
- void display(void) {
- // clearing the window with black color, 1st 3 parameter are for R,G,B. last one for opacity
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- //viewing transformation
- //glulookat() positions the camera towards the object
- //camera position, camera target, up vector
- gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- shapes();
- glFlush();
- }
- void reshape(int w, int h) {
- // 1st 2 parameters for lower left corner of the viewport rectangle. the default is 0,0
- // the next coordinates are width and height of the viewport
- //Set the viewport to be the entire window
- glViewport(0, 0, (GLsizei)w, (GLsizei)h);
- // setting the camera
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //perspective transform
- //gluPerspective (30, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
- gluPerspective(30, 1, 1.0, 100.0);
- glMatrixMode(GL_MODELVIEW); //switch back the the model editing mode.
- }
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- // single buffering.. (double buffering for animation)
- glutInitDisplayMode(GLUT_SINGLE);
- // full screen is 1000,1000
- // this 0,0 or 1000,1000 are world coordinates
- glutInitWindowSize(700, 700);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("A basic OpenGL Window");
- // registering callback functions
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement