0% found this document useful (0 votes)
82 views

#Include #Include

This document contains the code for an OpenGL project. It defines a display function that uses various OpenGL primitives like GL_QUADS, GL_TRIANGLES, GL_LINES, etc. to draw different colored shapes on the screen. It also defines a main function that initializes GLUT and sets the display function to draw the shapes. The goal is to test different OpenGL primitives by drawing simple 2D shapes.

Uploaded by

IAGPLS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

#Include #Include

This document contains the code for an OpenGL project. It defines a display function that uses various OpenGL primitives like GL_QUADS, GL_TRIANGLES, GL_LINES, etc. to draw different colored shapes on the screen. It also defines a main function that initializes GLUT and sets the display function to draw the shapes. The goal is to test different OpenGL primitives by drawing simple 2D shapes.

Uploaded by

IAGPLS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*OPENGL PROJECT*/

#include <windows.h> // for MS Windows


#include <GL/glut.h> // GLUT, include glu.h and gl.h

void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(0.5,1.0);
glVertex2f( 0.5,0.8 );
glVertex2f( 0.3,0.7 );
glVertex2f(0.3,0.9 );
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.1,0.9);
glVertex2f(0.8,0.1);
glVertex2f(0.8,0.3);
glEnd();

glBegin(GL_LINES);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.3,0.7);
glVertex2f(0.1,0.7);
glEnd();

glBegin(GL_LINE_STRIP);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.3,0.3);
glVertex2f(0.2,0.4);
glVertex2f(0.4,0.5);
glVertex2f(0.2,0.6);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(0.0,1.0,1.0);
glVertex2f(0.8,0.5);
glVertex2f(1.0,0.4);
glVertex2f(1.0,0.2);
glVertex2f(0.9,0.2);
glVertex2f(0.85,0.3);
glEnd();

glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0,1.0,0.0);
glVertex2f(0.8,0.9);
glVertex2f(0.7,1.0);
glVertex2f(0.7,0.7);
glVertex2f(0.7,0.5);
glVertex2f(0.8,0.7);
glVertex2f(0.7,0.7);
glEnd();
glBegin(GL_QUAD_STRIP);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.1,0.2);
glVertex2f( 0.1,0.4 );
glVertex2f( 0.2,0.3 );
glVertex2f( 0.2,0.2);
glEnd();

glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.1,-0.6);
glVertex2f(-0.1,-0.9);
glVertex2f(-0.2,-0.75);
glColor3f(0.0,1.0,0.0);
glVertex2f(-0.3,-0.6);
glColor3f(0.0,0.0,1.0);
glVertex2f(-0.3,-0.9);
glColor3f(1.0,1.0,0.0);
glVertex2f(-0.1,-0.9);
glEnd();

glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.3,-0.1);
glVertex2f(-0.5,-0.3);
glVertex2f(-0.5,-0.5);
glVertex2f(-0.5,-0.3);
glVertex2f(-0.1,-0.3);

glEnd();

glFlush();
}

int main(int argc, char** argv) {


glutInit(&argc, argv);
glutCreateWindow("OpenGL Setup Test");
glutInitWindowSize(400, 400);
glutInitWindowPosition(50, 50);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

You might also like