... | ... |
@@ -11,70 +11,70 @@ |
11 | 11 |
GLuint vertexArray; |
12 | 12 |
GLfloat positions[] = |
13 | 13 |
{ |
14 |
- -0.5f, -0.5f, 0.0f, |
|
15 |
- -0.5f, +0.5f, 0.0f, |
|
16 |
- +0.5f, -0.5f, 0.0f, |
|
14 |
+ -0.5f, -0.5f, 0.0f, |
|
15 |
+ -0.5f, +0.5f, 0.0f, |
|
16 |
+ +0.5f, -0.5f, 0.0f, |
|
17 | 17 |
}; |
18 | 18 |
|
19 | 19 |
|
20 | 20 |
/// Init |
21 | 21 |
void init(void) |
22 | 22 |
{ |
23 |
- // GL inits. |
|
24 |
- glClearColor(0.2, 0.2, 0.5, 0.0); |
|
25 |
- glDisable(GL_DEPTH_TEST); |
|
26 |
- printError("init GL"); |
|
27 |
- |
|
28 |
- // Load and compile shader. |
|
29 |
- GLuint program = loadShaders("tsbk07.vert", "tsbk07.frag"); |
|
30 |
- printError("init shader"); |
|
31 |
- |
|
32 |
- // Allocate and activate Vertex Array Object (VAO), used for uploading |
|
33 |
- // the geometry. |
|
34 |
- glGenVertexArrays(1, &vertexArray); |
|
35 |
- glBindVertexArray(vertexArray); |
|
36 |
- |
|
37 |
- // Allocate and activate Vertex Buffer Objects (VBO), for vertex data. |
|
38 |
- GLint positionLocation = glGetAttribLocation(program, "inPosition"); |
|
39 |
- GLuint positionBuffer; |
|
40 |
- glGenBuffers(1, &positionBuffer); |
|
41 |
- glBindBuffer(GL_ARRAY_BUFFER, positionBuffer); |
|
42 |
- glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); |
|
43 |
- glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
|
44 |
- glEnableVertexAttribArray(positionLocation); |
|
45 |
- printError("init VBOs"); |
|
23 |
+ // GL inits. |
|
24 |
+ glClearColor(0.2, 0.2, 0.5, 0.0); |
|
25 |
+ glDisable(GL_DEPTH_TEST); |
|
26 |
+ printError("init GL"); |
|
27 |
+ |
|
28 |
+ // Load and compile shader. |
|
29 |
+ GLuint program = loadShaders("tsbk07.vert", "tsbk07.frag"); |
|
30 |
+ printError("init shader"); |
|
31 |
+ |
|
32 |
+ // Allocate and activate Vertex Array Object (VAO), used for uploading |
|
33 |
+ // the geometry. |
|
34 |
+ glGenVertexArrays(1, &vertexArray); |
|
35 |
+ glBindVertexArray(vertexArray); |
|
36 |
+ |
|
37 |
+ // Allocate and activate Vertex Buffer Objects (VBO), for vertex data. |
|
38 |
+ GLint positionLocation = glGetAttribLocation(program, "inPosition"); |
|
39 |
+ GLuint positionBuffer; |
|
40 |
+ glGenBuffers(1, &positionBuffer); |
|
41 |
+ glBindBuffer(GL_ARRAY_BUFFER, positionBuffer); |
|
42 |
+ glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); |
|
43 |
+ glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
|
44 |
+ glEnableVertexAttribArray(positionLocation); |
|
45 |
+ printError("init VBOs"); |
|
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
|
49 | 49 |
/// Display |
50 | 50 |
void display(void) |
51 | 51 |
{ |
52 |
- // Clear the screen. |
|
53 |
- glClear(GL_COLOR_BUFFER_BIT); |
|
52 |
+ // Clear the screen. |
|
53 |
+ glClear(GL_COLOR_BUFFER_BIT); |
|
54 | 54 |
|
55 |
- // Select VAO. |
|
56 |
- glBindVertexArray(vertexArray); |
|
55 |
+ // Select VAO. |
|
56 |
+ glBindVertexArray(vertexArray); |
|
57 | 57 |
|
58 |
- // Draw. |
|
59 |
- glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions)/3); |
|
60 |
- printError("display draw"); |
|
58 |
+ // Draw. |
|
59 |
+ glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions)/3); |
|
60 |
+ printError("display draw"); |
|
61 | 61 |
|
62 |
- // Show on the screen. |
|
63 |
- glutSwapBuffers(); |
|
62 |
+ // Show on the screen. |
|
63 |
+ glutSwapBuffers(); |
|
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
|
67 | 67 |
/// Main |
68 | 68 |
int main(int argc, char * argv[]) |
69 | 69 |
{ |
70 |
- glutInit(&argc, argv); |
|
71 |
- glutInitContextVersion(3, 2); |
|
72 |
- glutInitWindowSize(600, 600); |
|
73 |
- glutCreateWindow("TSBK07"); |
|
70 |
+ glutInit(&argc, argv); |
|
71 |
+ glutInitContextVersion(3, 2); |
|
72 |
+ glutInitWindowSize(600, 600); |
|
73 |
+ glutCreateWindow("TSBK07"); |
|
74 | 74 |
|
75 |
- glutDisplayFunc(display); |
|
75 |
+ glutDisplayFunc(display); |
|
76 | 76 |
|
77 |
- dumpInfo(); |
|
78 |
- init(); |
|
79 |
- glutMainLoop(); |
|
77 |
+ dumpInfo(); |
|
78 |
+ init(); |
|
79 |
+ glutMainLoop(); |
|
80 | 80 |
} |