1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,80 +0,0 @@ |
1 |
-/// Inlcudes |
|
2 |
-#include "MicroGlut.h" |
|
3 |
-#include "GL_utilities.h" |
|
4 |
- |
|
5 |
- |
|
6 |
-/// Defines |
|
7 |
-#define ARRAY_COUNT(ARRAY) (sizeof(ARRAY)/sizeof(*(ARRAY))) |
|
8 |
- |
|
9 |
- |
|
10 |
-/// Globals |
|
11 |
-GLuint vertexArray; |
|
12 |
-GLfloat positions[] = |
|
13 |
-{ |
|
14 |
- -0.5f, -0.5f, 0.0f, |
|
15 |
- -0.5f, +0.5f, 0.0f, |
|
16 |
- +0.5f, -0.5f, 0.0f, |
|
17 |
-}; |
|
18 |
- |
|
19 |
- |
|
20 |
-/// Init |
|
21 |
-void init(void) |
|
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("lab1-1.vert", "lab1-1.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 |
-} |
|
47 |
- |
|
48 |
- |
|
49 |
-/// Display |
|
50 |
-void display(void) |
|
51 |
-{ |
|
52 |
- // Clear the screen. |
|
53 |
- glClear(GL_COLOR_BUFFER_BIT); |
|
54 |
- |
|
55 |
- // Select VAO. |
|
56 |
- glBindVertexArray(vertexArray); |
|
57 |
- |
|
58 |
- // Draw. |
|
59 |
- glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions)/3); |
|
60 |
- printError("display draw"); |
|
61 |
- |
|
62 |
- // Show on the screen. |
|
63 |
- glutSwapBuffers(); |
|
64 |
-} |
|
65 |
- |
|
66 |
- |
|
67 |
-/// Main |
|
68 |
-int main(int argc, char * argv[]) |
|
69 |
-{ |
|
70 |
- glutInit(&argc, argv); |
|
71 |
- glutInitContextVersion(3, 2); |
|
72 |
- glutInitWindowSize(600, 600); |
|
73 |
- glutCreateWindow("TSBK07"); |
|
74 |
- |
|
75 |
- glutDisplayFunc(display); |
|
76 |
- |
|
77 |
- dumpInfo(); |
|
78 |
- init(); |
|
79 |
- glutMainLoop(); |
|
80 |
-} |
... | ... |
@@ -1,87 +1,80 @@ |
1 |
-// Lab 1-1. |
|
2 |
-// This is the same as the first simple example in the course book, |
|
3 |
-// but with a few error checks. |
|
4 |
-// Remember to copy your file to a new on appropriate places during the lab so you keep old results. |
|
5 |
-// Note that the files "lab1-1.frag", "lab1-1.vert" are required. |
|
6 |
- |
|
7 |
-#include "GL_utilities.h" |
|
1 |
+/// Inlcudes |
|
8 | 2 |
#include "MicroGlut.h" |
9 |
-// uses framework OpenGL |
|
10 |
-// uses framework Cocoa |
|
3 |
+#include "GL_utilities.h" |
|
4 |
+ |
|
5 |
+ |
|
6 |
+/// Defines |
|
7 |
+#define ARRAY_COUNT(ARRAY) (sizeof(ARRAY)/sizeof(*(ARRAY))) |
|
11 | 8 |
|
12 |
-// Globals |
|
13 |
-// Data would normally be read from files |
|
14 |
-GLfloat vertices[] = |
|
9 |
+ |
|
10 |
+/// Globals |
|
11 |
+GLuint vertexArray; |
|
12 |
+GLfloat positions[] = |
|
15 | 13 |
{ |
16 |
- -0.5f,-0.5f,0.0f, |
|
17 |
- -0.5f,0.5f,0.0f, |
|
18 |
- 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, |
|
19 | 17 |
}; |
20 | 18 |
|
21 |
-// vertex array object |
|
22 |
-unsigned int vertexArrayObjID; |
|
23 | 19 |
|
20 |
+/// Init |
|
24 | 21 |
void init(void) |
25 | 22 |
{ |
26 |
- // vertex buffer object, used for uploading the geometry |
|
27 |
- unsigned int vertexBufferObjID; |
|
28 |
- // Reference to shader program |
|
29 |
- GLuint program; |
|
30 |
- |
|
31 |
- dumpInfo(); |
|
32 |
- |
|
33 |
- // GL inits |
|
34 |
- glClearColor(0.2,0.2,0.5,0); |
|
23 |
+ // GL inits. |
|
24 |
+ glClearColor(0.2, 0.2, 0.5, 0.0); |
|
35 | 25 |
glDisable(GL_DEPTH_TEST); |
36 |
- printError("GL inits"); |
|
26 |
+ printError("init GL"); |
|
37 | 27 |
|
38 |
- // Load and compile shader |
|
39 |
- program = loadShaders("lab1-1.vert", "lab1-1.frag"); |
|
28 |
+ // Load and compile shader. |
|
29 |
+ GLuint program = loadShaders("lab1-1.vert", "lab1-1.frag"); |
|
40 | 30 |
printError("init shader"); |
41 |
- |
|
42 |
- // Upload geometry to the GPU: |
|
43 |
- |
|
44 |
- // Allocate and activate Vertex Array Object |
|
45 |
- glGenVertexArrays(1, &vertexArrayObjID); |
|
46 |
- glBindVertexArray(vertexArrayObjID); |
|
47 |
- // Allocate Vertex Buffer Objects |
|
48 |
- glGenBuffers(1, &vertexBufferObjID); |
|
49 |
- |
|
50 |
- // VBO for vertex data |
|
51 |
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjID); |
|
52 |
- glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), vertices, GL_STATIC_DRAW); |
|
53 |
- glVertexAttribPointer(glGetAttribLocation(program, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0); |
|
54 |
- glEnableVertexAttribArray(glGetAttribLocation(program, "in_Position")); |
|
55 |
- |
|
56 |
- // End of upload of geometry |
|
57 |
- |
|
58 |
- printError("init arrays"); |
|
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"); |
|
59 | 46 |
} |
60 | 47 |
|
61 | 48 |
|
49 |
+/// Display |
|
62 | 50 |
void display(void) |
63 | 51 |
{ |
64 |
- printError("pre display"); |
|
65 |
- |
|
66 |
- // clear the screen |
|
52 |
+ // Clear the screen. |
|
67 | 53 |
glClear(GL_COLOR_BUFFER_BIT); |
68 | 54 |
|
69 |
- glBindVertexArray(vertexArrayObjID); // Select VAO |
|
70 |
- glDrawArrays(GL_TRIANGLES, 0, 3); // draw object |
|
71 |
- |
|
72 |
- printError("display"); |
|
73 |
- |
|
55 |
+ // Select VAO. |
|
56 |
+ glBindVertexArray(vertexArray); |
|
57 |
+ |
|
58 |
+ // Draw. |
|
59 |
+ glDrawArrays(GL_TRIANGLES, 0, ARRAY_COUNT(positions)/3); |
|
60 |
+ printError("display draw"); |
|
61 |
+ |
|
62 |
+ // Show on the screen. |
|
74 | 63 |
glutSwapBuffers(); |
75 | 64 |
} |
76 | 65 |
|
77 |
-int main(int argc, char *argv[]) |
|
66 |
+ |
|
67 |
+/// Main |
|
68 |
+int main(int argc, char * argv[]) |
|
78 | 69 |
{ |
79 | 70 |
glutInit(&argc, argv); |
80 | 71 |
glutInitContextVersion(3, 2); |
81 | 72 |
glutInitWindowSize(600, 600); |
82 |
- glutCreateWindow ("GL3 white triangle example"); |
|
83 |
- glutDisplayFunc(display); |
|
84 |
- init (); |
|
73 |
+ glutCreateWindow("TSBK07"); |
|
74 |
+ |
|
75 |
+ glutDisplayFunc(display); |
|
76 |
+ |
|
77 |
+ dumpInfo(); |
|
78 |
+ init(); |
|
85 | 79 |
glutMainLoop(); |
86 |
- return 0; |
|
87 | 80 |
} |
find . -type f -exec chmod -x {} +
Robert Cranston authored on 27/02/2024 02:27:271 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,87 @@ |
1 |
+// Lab 1-1. |
|
2 |
+// This is the same as the first simple example in the course book, |
|
3 |
+// but with a few error checks. |
|
4 |
+// Remember to copy your file to a new on appropriate places during the lab so you keep old results. |
|
5 |
+// Note that the files "lab1-1.frag", "lab1-1.vert" are required. |
|
6 |
+ |
|
7 |
+#include "GL_utilities.h" |
|
8 |
+#include "MicroGlut.h" |
|
9 |
+// uses framework OpenGL |
|
10 |
+// uses framework Cocoa |
|
11 |
+ |
|
12 |
+// Globals |
|
13 |
+// Data would normally be read from files |
|
14 |
+GLfloat vertices[] = |
|
15 |
+{ |
|
16 |
+ -0.5f,-0.5f,0.0f, |
|
17 |
+ -0.5f,0.5f,0.0f, |
|
18 |
+ 0.5f,-0.5f,0.0f |
|
19 |
+}; |
|
20 |
+ |
|
21 |
+// vertex array object |
|
22 |
+unsigned int vertexArrayObjID; |
|
23 |
+ |
|
24 |
+void init(void) |
|
25 |
+{ |
|
26 |
+ // vertex buffer object, used for uploading the geometry |
|
27 |
+ unsigned int vertexBufferObjID; |
|
28 |
+ // Reference to shader program |
|
29 |
+ GLuint program; |
|
30 |
+ |
|
31 |
+ dumpInfo(); |
|
32 |
+ |
|
33 |
+ // GL inits |
|
34 |
+ glClearColor(0.2,0.2,0.5,0); |
|
35 |
+ glDisable(GL_DEPTH_TEST); |
|
36 |
+ printError("GL inits"); |
|
37 |
+ |
|
38 |
+ // Load and compile shader |
|
39 |
+ program = loadShaders("lab1-1.vert", "lab1-1.frag"); |
|
40 |
+ printError("init shader"); |
|
41 |
+ |
|
42 |
+ // Upload geometry to the GPU: |
|
43 |
+ |
|
44 |
+ // Allocate and activate Vertex Array Object |
|
45 |
+ glGenVertexArrays(1, &vertexArrayObjID); |
|
46 |
+ glBindVertexArray(vertexArrayObjID); |
|
47 |
+ // Allocate Vertex Buffer Objects |
|
48 |
+ glGenBuffers(1, &vertexBufferObjID); |
|
49 |
+ |
|
50 |
+ // VBO for vertex data |
|
51 |
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjID); |
|
52 |
+ glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), vertices, GL_STATIC_DRAW); |
|
53 |
+ glVertexAttribPointer(glGetAttribLocation(program, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0); |
|
54 |
+ glEnableVertexAttribArray(glGetAttribLocation(program, "in_Position")); |
|
55 |
+ |
|
56 |
+ // End of upload of geometry |
|
57 |
+ |
|
58 |
+ printError("init arrays"); |
|
59 |
+} |
|
60 |
+ |
|
61 |
+ |
|
62 |
+void display(void) |
|
63 |
+{ |
|
64 |
+ printError("pre display"); |
|
65 |
+ |
|
66 |
+ // clear the screen |
|
67 |
+ glClear(GL_COLOR_BUFFER_BIT); |
|
68 |
+ |
|
69 |
+ glBindVertexArray(vertexArrayObjID); // Select VAO |
|
70 |
+ glDrawArrays(GL_TRIANGLES, 0, 3); // draw object |
|
71 |
+ |
|
72 |
+ printError("display"); |
|
73 |
+ |
|
74 |
+ glutSwapBuffers(); |
|
75 |
+} |
|
76 |
+ |
|
77 |
+int main(int argc, char *argv[]) |
|
78 |
+{ |
|
79 |
+ glutInit(&argc, argv); |
|
80 |
+ glutInitContextVersion(3, 2); |
|
81 |
+ glutInitWindowSize(600, 600); |
|
82 |
+ glutCreateWindow ("GL3 white triangle example"); |
|
83 |
+ glutDisplayFunc(display); |
|
84 |
+ init (); |
|
85 |
+ glutMainLoop(); |
|
86 |
+ return 0; |
|
87 |
+} |