-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglhello.c
88 lines (63 loc) · 1.73 KB
/
glhello.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "glhello.h"
int main(int argc, char **argv) {
/* General initialization for GLUT and OpenGL
Must be called first */
glutInit( &argc, argv ) ;
/* we define these setup procedures */
glut_setup() ;
gl_setup() ;
my_setup();
/* go into the main event loop */
glutMainLoop() ;
return(0) ;
}
/* This function sets up the windowing related glut calls */
void glut_setup(void) {
/* specify display mode -- here we ask for a double buffer and RGB coloring */
glutInitDisplayMode (GLUT_DOUBLE |GLUT_RGB);
/* make a 400x300 window with the title of "GLUT Skeleton" placed at the top left corner */
glutInitWindowSize(400,100);
glutInitWindowPosition(0,0);
glutCreateWindow("GLUT Skeleton");
/*initialize callback functions */
glutDisplayFunc( my_display );
glutReshapeFunc( my_reshape );
glutIdleFunc( my_idle );
return ;
}
/* This function sets up the initial states of OpenGL related enivornment */
void gl_setup(void) {
/* specifies a background color: black in this case */
glClearColor(0,0,0,0) ;
/* setup for simple 2d projection */
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, 0, 1.0);
return ;
}
void my_setup(void) {
return;
}
void my_reshape(int w, int h) {
/* define viewport -- x, y, (origin is at lower left corner) width, height */
glViewport (0, (int)(h*0.25), w/2, h/2);
return;
}
void my_display(void) {
/* clear the buffer */
glClear(GL_COLOR_BUFFER_BIT) ;
glColor3f(0,1,0) ;
/* draw something */
glBegin(GL_POLYGON);
glVertex2f(-1.0,1.0);
glVertex2f(1.0,1.0);
glVertex2f(1.0,-1.0);
glVertex2f(-1.0,-1.0);
glEnd();
/* buffer is ready */
glutSwapBuffers();
return ;
}
void my_idle(void) {
return ;
}