1 | 1 |
deleted file mode 100755 |
... | ... |
@@ -1,87 +0,0 @@ |
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 |
-} |
1 | 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 |
+} |