include windows include GL glut include math const unsigned int SCR_WI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <windows.h>
#include <GL/glut.h>
#include <math.h>
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
void display() {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
//Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(0.5f, 0.5f, 0.5f);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(0.5f, 0.1f);
glVertex2f(-0.5f, 0.1f);
glEnd();
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.98f, 0.5f);
glVertex2f(-0.16f, 0.0f);
glVertex2f(0.16f, 0.0f);
glVertex2f(0.16f, -0.25f);
glVertex2f(-0.16f, -0.25f);
glEnd();
glBegin(GL_TRIANGLES); // Each set of 4 vertices form a quad
glColor3f(0.35f, 1.0f, 0.59f); // Red
glVertex2f(0.0f, 0.8f); // x, y
glVertex2f(-0.7f, 0.11f);
glVertex2f(0.7f, 0.11f);
glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(SCR_WIDTH, SCR_HEIGHT); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the event-processing loop
return 0;
}