-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_render_fixed.c
158 lines (126 loc) · 3.43 KB
/
app_render_fixed.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// This file contains some of the code that is uses to render using the
// fixed pipeline; the high-level rendering is done with the fixed pipeline
// via the "app_draw()" function in the "app.c" file, which calls functions
// from here and to use the programmable pipeline. (Nothing 3D is rendered
// with what is here, and the functions are just placeholders.)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <math.h>
//
// Function to draw a reference box using the fixed pipeline
//
int DrawGridbox()
{
GLfloat col[3];
GLfloat d = 0.5;
GLfloat x1[3],x2[3],x3[3],x4[3];
GLfloat x5[3],x6[3],x7[3],x8[3];
// colour
col[0] = 1.0;
col[1] = 1.0;
col[2] = 1.0;
// lower points
x1[0] = -d;
x1[1] = -d;
x1[2] =- d;
x2[0] = d;
x2[1] = -d;
x2[2] =- d;
x3[0] = d;
x3[1] = -d;
x3[2] =+ d;
x4[0] = -d;
x4[1] = -d;
x4[2] =+ d;
// upper points
x5[0] = -d;
x5[1] = d;
x5[2] =- d;
x6[0] = d;
x6[1] = d;
x6[2] =- d;
x7[0] = d;
x7[1] = d;
x7[2] =+ d;
x8[0] = -d;
x8[1] = d;
x8[2] =+ d;
glBegin(GL_LINE_LOOP);
glColor3fv( col );
glVertex3fv(x1);
glVertex3fv(x2);
glVertex3fv(x3);
glVertex3fv(x4);
glVertex3fv(x1);
glVertex3fv(x5);
glVertex3fv(x8);
glVertex3fv(x4);
glVertex3fv(x1);
glVertex3fv(x2);
glVertex3fv(x6);
glVertex3fv(x5);
glVertex3fv(x5);
glVertex3fv(x6);
glVertex3fv(x7);
glVertex3fv(x8);
glVertex3fv(x8);
glVertex3fv(x7);
glVertex3fv(x3);
glVertex3fv(x4);
glVertex3fv(x1);
glEnd();
return 0;
}
//
// ----- a function to prepare the fixed rasterization pipeline
//
void prepare(void)
{
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );
// controls specular reflections
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE );
// order of specular light processing
glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR );
// glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR );
// ambient light regardless of lights present
GLfloat ambient_light[] = { 0.1, 0.1, 0.1, 1.0 };
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient_light );
GLfloat position[] = { -12.1, 19.1, 19.1, 1.0 };
//static float r1 = 0.0;
//r1 += 0.05*acos(-1.0);
//position[0] += 2.0*cos((double) r1);
//position[1] += 2.0*sin((double) r1);
glLightfv( GL_LIGHT0, GL_POSITION, position );
GLfloat ambient[] = { 0.02, 0.02, 0.02, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 0.0, 0.0, 0.0, 1.0 }; // For now...
glLightfv( GL_LIGHT0, GL_AMBIENT, ambient );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse );
glLightfv( GL_LIGHT0, GL_SPECULAR, specular );
glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.0 );
glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05 );
glEnable( GL_LIGHT0 );
GLfloat col[] = { 1.0, 0.2, 0.2 };
glMaterialfv( GL_FRONT, GL_AMBIENT, col );
// glMaterialfv( GL_BACK, GL_AMBIENT, col );
glMaterialfv( GL_FRONT, GL_DIFFUSE, col );
// glMaterialfv( GL_BACK, GL_DIFFUSE, col );
col[1] = 1.0; col[2] = 1.0;
glMaterialfv( GL_FRONT, GL_SPECULAR, col );
// glMaterialfv( GL_BACK, GL_SPECULAR, col );
}
//
// ----- a function to "undo stuff" from the fixed rasterization pipeline
//
void unprepare(void)
{
}