Browse code

Unify lab1 and lab4

Robert Cranston authored on 27/02/2024 02:27:37
Showing 10 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+/tsbk07
0 2
similarity index 52%
1 3
rename from lab4/lab4-1.cpp
2 4
rename to generate_terrain.cpp
... ...
@@ -1,19 +1,9 @@
1 1
 /// Inlcudes
2
-#define MAIN
3
-#include "MicroGlut.h"
4
-#include "GL_utilities.h"
5 2
 #include "VectorUtils4.h"
6 3
 #include "LittleOBJLoader.h"
7 4
 #include "LoadTGA.h"
8 5
 
9 6
 
10
-/// Globals
11
-GLuint   program;
12
-mat4     projection;
13
-Model  * terrain;
14
-GLuint   tex;
15
-
16
-
17 7
 /// Generate terrain
18 8
 Model * GenerateTerrain(const char * filename)
19 9
 {
... ...
@@ -75,88 +65,3 @@ Model * GenerateTerrain(const char * filename)
75 65
 	free(textureData.imageData);
76 66
 	return model;
77 67
 }
78
-
79
-
80
-/// Init
81
-void init(void)
82
-{
83
-	// GL inits.
84
-	glClearColor(0.2, 0.2, 0.5, 0.0);
85
-	glEnable(GL_DEPTH_TEST);
86
-	glDisable(GL_CULL_FACE);
87
-	printError("init GL");
88
-
89
-	// Load and compile shader.
90
-	program = loadShaders("terrain.vert", "terrain.frag");
91
-	glUseProgram(program);
92
-	printError("init shader");
93
-
94
-	// Matrices.
95
-	projection = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 50.0);
96
-	glUniformMatrix4fv(glGetUniformLocation(program, "projection"), 1, GL_TRUE, projection.m);
97
-	printError("init matrices");
98
-
99
-	// Textures.
100
-	LoadTGATextureSimple("../assets/terrain/dandelion.tga", &tex);
101
-	glBindTexture(GL_TEXTURE_2D, tex);
102
-	glUniform1i(glGetUniformLocation(program, "tex"), 0);
103
-	printError("init textures");
104
-
105
-	// Generate terrain.
106
-	terrain = GenerateTerrain("../assets/terrain/simple-4.tga");
107
-	printError("init terrain");
108
-}
109
-
110
-
111
-/// Display
112
-void display(void)
113
-{
114
-	// Clear the screen.
115
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
116
-
117
-	// Uniforms.
118
-	mat4 view = lookAt(
119
-		vec3(0, 5, 8), // Position.
120
-		vec3(2, 0, 2), // Target.
121
-		vec3(0, 1, 0)  // Up.
122
-	);
123
-	mat4 model = IdentityMatrix();
124
-	mat4 modelView = view * model;
125
-	glUniformMatrix4fv(glGetUniformLocation(program, "modelView"), 1, GL_TRUE, modelView.m);
126
-	printError("display uniforms");
127
-
128
-	// Draw.
129
-	DrawModel(terrain, program, "inPosition", nullptr, "inTexCoord");
130
-	printError("display draw");
131
-
132
-	// Show on the screen.
133
-	glutSwapBuffers();
134
-}
135
-
136
-
137
-/// Mouse
138
-void mouse(int x, int y)
139
-{
140
-	// This function is included in case you want some hints about using
141
-	// passive mouse movement. Uncomment to see mouse coordinates:
142
-	// printf("%d %d\n", x, y);
143
-}
144
-
145
-
146
-/// Main
147
-int main(int argc, char * argv[])
148
-{
149
-	glutInit(&argc, argv);
150
-	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
151
-	glutInitContextVersion(3, 2);
152
-	glutInitWindowSize(600, 600);
153
-	glutCreateWindow("TSBK07");
154
-
155
-	glutRepeatingTimer(20);
156
-	glutDisplayFunc(display);
157
-	glutPassiveMotionFunc(mouse);
158
-
159
-	dumpInfo();
160
-	init();
161
-	glutMainLoop();
162
-}
163 68
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-# set this variable to the director in which you saved the common files
2
-commondir = ../common/
3
-
4
-all : lab1-1
5
-
6
-lab1-1 : lab1-1.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c
7
-	gcc -Wall -o lab1-1 -I$(commondir) -I../common/Linux -DGL_GLEXT_PROTOTYPES lab1-1.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c -lXt -lX11 -lGL -lm -lstdc++
8
-
9
-clean :
10
-	rm lab1-1
11
-
12 0
deleted file mode 100644
... ...
@@ -1,10 +0,0 @@
1
-# set this variable to the director in which you saved the common files
2
-commondir = ../common/
3
-
4
-all : lab4-1
5
-
6
-lab4-1 : lab4-1.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c
7
-	gcc -Wall -o lab4-1 -I$(commondir) -I../common/Linux -DGL_GLEXT_PROTOTYPES lab4-1.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c -lXt -lX11 -lGL -lm
8
-
9
-clean :
10
-	rm lab4-1
11 0
deleted file mode 100644
... ...
@@ -1,13 +0,0 @@
1
-#version 150
2
-
3
-in vec2 texCoord;
4
-
5
-out vec4 outColor;
6
-
7
-uniform sampler2D tex;
8
-
9
-
10
-void main(void)
11
-{
12
-	outColor = texture(tex, texCoord);
13
-}
14 0
deleted file mode 100644
... ...
@@ -1,17 +0,0 @@
1
-#version 150
2
-
3
-in vec3 inPosition;
4
-in vec3 inNormal;
5
-in vec2 inTexCoord;
6
-
7
-out vec2 texCoord;
8
-
9
-uniform mat4 projection;
10
-uniform mat4 modelView;
11
-
12
-
13
-void main(void)
14
-{
15
-	gl_Position = projection * modelView * vec4(inPosition, 1.0);
16
-	texCoord    = inTexCoord;
17
-}
18 0
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+# set this variable to the director in which you saved the common files
2
+commondir = common/
3
+
4
+all : tsbk07
5
+
6
+tsbk07 : tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c
7
+	gcc -Wall -o tsbk07 -I$(commondir) -Icommon/Linux -DGL_GLEXT_PROTOTYPES tsbk07.cpp $(commondir)GL_utilities.c $(commondir)LoadTGA.c $(commondir)Linux/MicroGlut.c -lXt -lX11 -lGL -lm -lstdc++
8
+
9
+clean :
10
+	rm tsbk07
11
+
0 12
similarity index 96%
1 13
rename from lab1/lab1-1.cpp
2 14
rename to tsbk07.cpp
... ...
@@ -26,7 +26,7 @@ void init(void)
26 26
 	printError("init GL");
27 27
 
28 28
 	// Load and compile shader.
29
-	GLuint program = loadShaders("lab1-1.vert", "lab1-1.frag");
29
+	GLuint program = loadShaders("tsbk07.vert", "tsbk07.frag");
30 30
 	printError("init shader");
31 31
 
32 32
 	// Allocate and activate Vertex Array Object (VAO), used for uploading
33 33
similarity index 100%
34 34
rename from lab1/lab1-1.frag
35 35
rename to tsbk07.frag
36 36
similarity index 100%
37 37
rename from lab1/lab1-1.vert
38 38
rename to tsbk07.vert