|
@@ -27,6 +27,11 @@ GLubyte image[TextureWidth][TextureHeight][3];
|
|
|
// Vertex data arrays
|
|
|
point4 points[NumVertices];
|
|
|
vec2 tex_coords[NumVertices];
|
|
|
+vec3 normals[NumVertices];
|
|
|
+
|
|
|
+// plane light params
|
|
|
+GLuint plane_light;
|
|
|
+GLfloat light_on = 1.0f;
|
|
|
|
|
|
// fog params
|
|
|
GLuint fog; // is_foggy uniform
|
|
@@ -102,7 +107,7 @@ void load_model(const std::string &file_name, bool not_tex = false,
|
|
|
vertices.emplace_back(x / 50.0f + x_offset, z / 50.0f + z_offset,
|
|
|
y / 50.0f + y_offset, 1.0);
|
|
|
if (!not_tex) {
|
|
|
- *(reinterpret_cast<float*>(ter_alt) + idx) = y / 50.0f;
|
|
|
+ *(reinterpret_cast<float *>(ter_alt) + idx) = y / 50.0f;
|
|
|
idx++;
|
|
|
}
|
|
|
} else if (t == "vt") {
|
|
@@ -113,7 +118,10 @@ void load_model(const std::string &file_name, bool not_tex = false,
|
|
|
a--;
|
|
|
b--;
|
|
|
c--;
|
|
|
+ vec3 normal = normalize(
|
|
|
+ cross(vertices[b] - vertices[a], vertices[c] - vertices[b]));
|
|
|
points[index] = vertices[a];
|
|
|
+ normals[index] = normal;
|
|
|
if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
@@ -121,6 +129,7 @@ void load_model(const std::string &file_name, bool not_tex = false,
|
|
|
}
|
|
|
index++;
|
|
|
points[index] = vertices[b];
|
|
|
+ normals[index] = normal;
|
|
|
if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
@@ -128,6 +137,7 @@ void load_model(const std::string &file_name, bool not_tex = false,
|
|
|
}
|
|
|
index++;
|
|
|
points[index] = vertices[c];
|
|
|
+ normals[index] = normal;
|
|
|
if (not_tex) {
|
|
|
tex_coords[index] = {20.0, 0.0};
|
|
|
} else {
|
|
@@ -187,7 +197,8 @@ void init() {
|
|
|
GLuint buffer;
|
|
|
glGenBuffers(1, &buffer);
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
|
|
- glBufferData(GL_ARRAY_BUFFER, sizeof(points) + sizeof(tex_coords), NULL,
|
|
|
+ glBufferData(GL_ARRAY_BUFFER,
|
|
|
+ sizeof(points) + sizeof(tex_coords) + sizeof(normals), NULL,
|
|
|
GL_STATIC_DRAW);
|
|
|
|
|
|
// Specify an offset to keep track of where we're placing data in our
|
|
@@ -198,6 +209,9 @@ void init() {
|
|
|
offset += sizeof(points);
|
|
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(tex_coords), tex_coords);
|
|
|
+ offset += sizeof(tex_coords);
|
|
|
+
|
|
|
+ glBufferSubData(GL_ARRAY_BUFFER, offset, sizeof(normals), normals);
|
|
|
|
|
|
// Load shaders and use the resulting shader program
|
|
|
GLuint program = InitShader("vshader71.glsl", "fshader71.glsl");
|
|
@@ -215,6 +229,12 @@ void init() {
|
|
|
glEnableVertexAttribArray(vTexCoord);
|
|
|
glVertexAttribPointer(vTexCoord, 2, GL_FLOAT, GL_FALSE, 0,
|
|
|
BUFFER_OFFSET(offset));
|
|
|
+ offset += sizeof(tex_coords);
|
|
|
+
|
|
|
+ GLuint vNormal = glGetAttribLocation(program, "vNormal");
|
|
|
+ glEnableVertexAttribArray(vNormal);
|
|
|
+ glVertexAttribPointer(vNormal, 3, GL_FLOAT, GL_FALSE, 0,
|
|
|
+ BUFFER_OFFSET(offset));
|
|
|
|
|
|
// Set the value of the fragment shader texture sampler variable
|
|
|
// ("texture") to the the appropriate texture unit. In this case,
|
|
@@ -225,6 +245,7 @@ void init() {
|
|
|
projection = glGetUniformLocation(program, "projection");
|
|
|
fog = glGetUniformLocation(program, "foggy");
|
|
|
eye_pos = glGetUniformLocation(program, "eye_pos");
|
|
|
+ plane_light = glGetUniformLocation(program, "plane_light_on");
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
glClearColor(1, 1, 1, 1);
|
|
@@ -250,6 +271,8 @@ void display(void) {
|
|
|
|
|
|
glUniform1i(fog, foggy);
|
|
|
|
|
|
+ glUniform1f(plane_light, light_on);
|
|
|
+
|
|
|
glDrawArrays(GL_TRIANGLES, 0, NumVertices);
|
|
|
|
|
|
glutSwapBuffers();
|
|
@@ -270,6 +293,13 @@ void keyboard(unsigned char key, int mousex, int mousey) {
|
|
|
case 033: // Escape Key
|
|
|
exit(0);
|
|
|
break;
|
|
|
+ case 'l':
|
|
|
+ if (light_on > 0.0) {
|
|
|
+ light_on = 0.0;
|
|
|
+ } else {
|
|
|
+ light_on = 1.0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
case 'f':
|
|
|
if (foggy > 0) {
|
|
|
foggy = 0;
|