Polygon
code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//necessary header | |
#include<stdlib.h> | |
#include<math.h> | |
#include<Windows.h> | |
//Opengl utilities | |
#include <GL\glew.h> | |
#include<GL/GLU.h> | |
#include<GL/GL.h> | |
#include <GL\freeglut.h> | |
//function initialization and definition | |
void display(void) { | |
//clearing all pixel | |
glClear(GL_COLOR_BUFFER_BIT); | |
//draw white polygon (rectangle) with corner at (0.25,0.25, 0.0) and (0.75,0.75,0.0) | |
glColor3f(1.0,1.0,1.0); | |
glBegin(GL_POLYGON); | |
glVertex3f(0.25,0.25,0.0); | |
glVertex3f(0.75,0.25,0.0); | |
glVertex3f(0.75,0.75,0.0); | |
glVertex3f(0,1,0); | |
glVertex3f(0.25,0.75,0.0); | |
glEnd(); | |
//start processing openGL routine | |
glFlush(); | |
} | |
void init(void) { | |
//for background | |
glClearColor(0.0,0.0,0.0,0.0); | |
//initializing viewing values | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
// left, right, buttom, top, zNear, zFar | |
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0); | |
} | |
//main function | |
//declare initial window size, position, and display mode (single buffered and RBGA) | |
//open window with "Polygon" in title bar | |
//call initialization routine | |
//register call back function | |
//enter main loop and process event | |
int main(int argc, char* argv[]) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); | |
glutInitWindowSize(250,250); | |
glutInitWindowPosition(100,100); | |
glutCreateWindow("Polygon"); | |
init(); | |
glutDisplayFunc(display); | |
glutMainLoop(); | |
return(0); | |
} |