openGPMP
Open Source Mathematics Package
openGL_tri.c
Go to the documentation of this file.
1 /*
2  * Testing openGL with drawing a simple triangle with shades
3  */
4 #include <GL/glut.h>
5 #include <math.h>
6 #include <stdio.h>
7 
8 #define pi 3.142857
9 
10 void display() {
11  // setting every pixel in frame buffer to a clear color
12  glClear(GL_COLOR_BUFFER_BIT);
13 
14  // being drawing
15  glBegin(GL_POLYGON);
16  glColor3f(1, 0, 1);
17  glVertex3f(-0.6, -0.75, 0.5);
18  glColor3f(0, 1, 0);
19  glVertex3f(0.6, -0.75, 0);
20  glColor3f(0, 0, 1);
21  glVertex3f(0, 0.75, 0);
22  glEnd();
23 
24  // flush the draw cmd to display image immediately
25  glFlush();
26 }
27 
28 int main(int argc, char **argv) {
29  glutInit(&argc, argv);
30  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
31 
32  // Position window at (80,80)-(480,380) and give it a title.
33  glutInitWindowPosition(80, 80);
34  glutInitWindowSize(1000, 800);
35  glutCreateWindow("A Shaded Triangle");
36 
37  // Tell GLUT that whenever the main window needs to be repainted
38  // that it should call the function display().
39  glutDisplayFunc(display);
40 
41  glutMainLoop();
42 
43  return 0;
44 }
void display()
Definition: openGL_tri.c:10
int main(int argc, char **argv)
Definition: openGL_tri.c:28