Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit 3bdb8c7

Browse files
committed
Fix multiple problems:
- update install instructions for MinGW (use x86_64 architecture) - add #define GLM_ENABLE_EXPERIMENTAL for newer GLM versions - fix GLM matrix initialization to identity matrix - several small fixes
1 parent ceec2f4 commit 3bdb8c7

File tree

21 files changed

+57
-49
lines changed

21 files changed

+57
-49
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ On Microsoft Windows you may try to open the `CMakeLists.txt` file with the late
162162
However the recommended way is to avoid Visual Studio and install [CLion IDE](https://www.jetbrains.com/clion/) and a __GCC__ based compiler:
163163

164164
* Download and install [MinGW-w64](https://sourceforge.net/projects/mingw-w64/), this is the latest GCC compiler for Windows in a nice installer.
165-
* Make sure to install the __64bit version__, you need to manually switch this in the installer process.
165+
* Make sure to install the __64bit version (select x86_64, NOT i686)__, you need to manually switch this in the installer process.
166166
* To avoid issues with malformed paths also edit the installation destination to C:/mingw-w64 instead of Program Files.
167167
* Run CLion and select MinGW as the __toolchain__ when prompted (default is C:/mingw-w64/..)
168168
* Setup the rest of the settings as you see fit.

ppgso/image.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
#include <algorithm>
12
#include "image.h"
23

34
using namespace std;
45
using namespace ppgso;
56

7+
uint8_t clamp(float value) {
8+
return (uint8_t) (std::min(std::max(value, 0.0f), 1.0f) * 255.0f);
9+
}
10+
611
Image::Image(int width, int height) : width{width}, height{height} {
712
framebuffer.resize((size_t) (width * height));
813
}
@@ -28,5 +33,5 @@ void Image::setPixel(int x, int y, int r, int g, int b) {
2833
}
2934

3035
void Image::setPixel(int x, int y, float r, float g, float b) {
31-
setPixel(x,y,{(uint8_t) (r * 255), (uint8_t) (g * 255), (uint8_t) (b * 255)});
36+
setPixel(x,y,{clamp(r), clamp(g), clamp(b)});
3237
}

ppgso/ppgso.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#define GLM_ENABLE_EXPERIMENTAL
23
#include <glm/glm.hpp>
34
#include <glm/gtc/random.hpp>
45
#include <glm/gtx/compatibility.hpp>

ppgso/window.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void Window::glfw_mouse_button_callback(GLFWwindow *window, int button, int acti
101101
}
102102

103103
void Window::close() {
104-
glfwSetWindowShouldClose(window, true);
104+
glfwSetWindowShouldClose(window, GLFW_TRUE);
105105
}
106106

107107
void Window::glfw_window_refresh_callback(GLFWwindow *window) {

shader/color_vert.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#version 330
22
// The inputs will be fed by the vertex buffer objects
33
layout(location = 0) in vec3 Position;
4-
in vec3 Color;
4+
layout(location = 4) in vec3 Color;
55

66
// Matrices as program attributes
77
uniform mat4 ProjectionMatrix;

src/gl1_gradient/gl1_gradient.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GradientWindow : public Window {
2727
vector<vec3> vertex_buffer{
2828
// x, y
2929
{0.0f, 0.8f, 0.0f},
30-
{0.8f, -0.8f, 0.0f},
30+
{0.8f, -0.8f, 0.0f},
3131
{-0.8f, -0.8f, 0.0f},
3232
};
3333

@@ -76,9 +76,9 @@ class GradientWindow : public Window {
7676
glEnableVertexAttribArray(color_attrib);
7777

7878
// Set Matrices to identity so there are no projections/transformations applied in the vertex shader
79-
program.setUniform("ModelMatrix", mat4{});
80-
program.setUniform("ViewMatrix", mat4{});
81-
program.setUniform("ProjectionMatrix", mat4{});
79+
program.setUniform("ModelMatrix", mat4{1.0f});
80+
program.setUniform("ViewMatrix", mat4{1.0f});
81+
program.setUniform("ProjectionMatrix", mat4{1.0f});
8282
}
8383

8484
/*!
@@ -92,9 +92,9 @@ class GradientWindow : public Window {
9292
}
9393

9494
/*!
95-
* Window update implementation that will be called automatically from pollEvents
95+
* Window refresh implementation that will be called automatically from pollEvents when needed
9696
*/
97-
void onIdle() override {
97+
void onRefresh() override {
9898
// Set gray background
9999
glClearColor(.5, .5, .5, 0);
100100

src/gl2_texture/gl2_texture.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class TextureWindow : public Window {
7777
glBindTexture(GL_TEXTURE_2D, texture_id);
7878

7979
// Set Matrices to identity so there are no projections/transformations applied in the vertex shader
80-
program.setUniform("ModelMatrix", mat4{});
81-
program.setUniform("ViewMatrix", mat4{});
82-
program.setUniform("ProjectionMatrix", mat4{});
80+
program.setUniform("ModelMatrix", mat4{1.0f});
81+
program.setUniform("ViewMatrix", mat4{1.0f});
82+
program.setUniform("ProjectionMatrix", mat4{1.0f});
8383
}
8484

8585
/*!
@@ -90,9 +90,9 @@ class TextureWindow : public Window {
9090
}
9191

9292
/*!
93-
* Window update implementation that will be called automatically from pollEvents
93+
* Window refresh implementation that will be called automatically from pollEvents when needed
9494
*/
95-
void onIdle() override {
95+
void onRefresh() override {
9696
// Set gray background
9797
glClearColor(.5f, .5f, .5f, 0);
9898

src/gl3_animate/gl3_animate.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class AnimateWindow : public Window {
6868
program.setUniform("Texture", texture);
6969

7070
// Set Matrices to identity so there are no projections/transformations applied in the vertex shader
71-
program.setUniform("ModelMatrix", mat4{});
72-
program.setUniform("ViewMatrix", mat4{});
73-
program.setUniform("ProjectionMatrix", mat4{});
71+
program.setUniform("ModelMatrix", mat4{1.0f});
72+
program.setUniform("ViewMatrix", mat4{1.0f});
73+
program.setUniform("ProjectionMatrix", mat4{1.0f});
7474
}
7575

7676
/*!

src/gl4_transform/gl4_transform.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ class TransformWindow : public Window {
107107
});
108108

109109
case Mode::ROTATE_TOP_LEFT:
110-
return translate(mat4{}, vec3{-1, 1, 0})
111-
* rotate(mat4{}, time, vec3{0, 0, 1})
112-
* glm::translate(mat4{}, -vec3{-1, 1, 0});
110+
return translate(mat4{1.0f}, vec3{-1, 1, 0})
111+
* rotate(mat4{1.0f}, time, vec3{0, 0, 1})
112+
* glm::translate(mat4{1.0f}, -vec3{-1, 1, 0});
113113

114114
default:
115115
break;
116116
}
117-
return mat4{};
117+
return mat4{1.0f};
118118
}
119119

120120
public:
@@ -125,8 +125,8 @@ class TransformWindow : public Window {
125125
// Set program input for texture uniform
126126
program.setUniform("Texture", texture);
127127
// Set Matrices to identity so there are no projections/transformations applied in the vertex shader
128-
program.setUniform("ViewMatrix", mat4{});
129-
program.setUniform("ProjectionMatrix", mat4{});
128+
program.setUniform("ViewMatrix", mat4{1.0f});
129+
program.setUniform("ProjectionMatrix", mat4{1.0f});
130130
}
131131

132132
/*!

src/gl5_projection/gl5_projection.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ProjectionWindow : public Window {
5151
program.setUniform("ProjectionMatrix", perspective((PI / 180.f) * 60.0f, 1.0f, 0.1f, 10.0f));
5252

5353
// Create view matrix (translate camera a bit backwards, so we can see the geometry)
54-
program.setUniform("ViewMatrix", translate(mat4{}, {0.0f, 0.0f, -3.0f}));
54+
program.setUniform("ViewMatrix", translate(mat4{1.0f}, {0.0f, 0.0f, -3.0f}));
5555
break;
5656
case Mode::PARALLEL:
5757
// Create projection matrix (field of view (radians), aspect ratio, near plane distance, far plane distance)
@@ -87,8 +87,8 @@ class ProjectionWindow : public Window {
8787

8888
// Quad positions
8989
// Coordinates in world coordinates
90-
quad1ModelMatrix = translate(mat4{}, {0, 0, 1});
91-
quad2ModelMatrix = translate(mat4{}, {0, 0, -1});
90+
quad1ModelMatrix = translate(mat4{1.0f}, {0, 0, 1});
91+
quad2ModelMatrix = translate(mat4{1.0f}, {0, 0, -1});
9292
}
9393

9494
/*!
@@ -112,7 +112,7 @@ class ProjectionWindow : public Window {
112112
void onIdle() override {
113113
// Update time and create a rotation matrix
114114
auto time = glfwGetTime();
115-
auto rotateMat = rotate(mat4{}, (float)time, {0, 1, 0});
115+
auto rotateMat = rotate(mat4{1.0f}, (float)time, {0, 1, 0});
116116

117117
// Set up projection and view matrix
118118
setProjection();

src/gl6_mesh/gl6_mesh.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ class MeshWindow : public Window {
9191
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
9292

9393
// Create object matrices
94-
auto cubeMat = rotate(mat4{}, time, {0.5f, 1.0f, 0.0f});
95-
auto sphereMat = translate(mat4{}, {sin(time), cos(time), 0});
94+
auto cubeMat = rotate(mat4{1.0f}, time, {0.5f, 1.0f, 0.0f});
95+
auto sphereMat = translate(mat4{1.0f}, {sin(time), cos(time), 0});
9696
sphereMat = scale(sphereMat, {0.5f, 0.5f, 0.5f});
9797

9898
// Camera position/rotation - for example, translate camera a bit backwards (positive value in Z axis), so we can see the objects
99-
auto cameraMat = translate(mat4{}, {0.0f, 0.0f, -2.5f});
99+
auto cameraMat = translate(mat4{1.0f}, {0.0f, 0.0f, -2.5f});
100100
program.setUniform("ViewMatrix", cameraMat);
101101

102102
// Update camera position with perspective projection
@@ -117,7 +117,7 @@ class MeshWindow : public Window {
117117
program.setUniform("ProjectionMatrix", ortho(-1.0f, 1.0f, -1.0f, 1.0f, 1000.0f, -1000.0f));
118118

119119
// Create object matrix
120-
auto cursorMat = translate(mat4{}, {cursorX, cursorY, 0.0f}) * scale(mat4{}, {0.1f, 0.1f, 0.1f});
120+
auto cursorMat = translate(mat4{1.0f}, {cursorX, cursorY, 0.0f}) * scale(mat4{1.0f}, {0.1f, 0.1f, 0.1f});
121121

122122
// Render objects
123123
program.setUniform("Texture", cursorTexture);

src/gl7_diffuse/gl7_diffuse.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DiffuseWindow : public Window {
3030
*/
3131
DiffuseWindow() : Window{"gl7_diffuse", SIZE, SIZE} {
3232
// Set camera position/rotation - for example, translate camera a bit backwards (positive value in Z axis), so we can see the objects
33-
auto cameraMat = translate(mat4{}, {0.0f, 0.0f, -1.0f});
33+
auto cameraMat = translate(mat4{1.0f}, {0.0f, 0.0f, -1.0f});
3434
program.setUniform("ViewMatrix", cameraMat);
3535

3636
// Set camera position with perspective projection
@@ -81,7 +81,7 @@ class DiffuseWindow : public Window {
8181
auto time = glfwGetTime();
8282

8383
// Create object matrix that rotates in time
84-
auto sphereMat = rotate(mat4{}, (float)time, {0.5f, 1.0f, 0.0f});
84+
auto sphereMat = rotate(mat4{1.0f}, (float)time, {0.5f, 1.0f, 0.0f});
8585

8686
// Set the matrix as model matrix for current program
8787
program.setUniform("ModelMatrix", sphereMat);

src/gl8_framebuffer/gl8_framebuffer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ class FramebufferWindow : public Window {
100100
auto sphereProjectionMatrix = perspective((PI / 180.f) * 60.0f, (float)SIZE/(float)SIZE, 1.0f, 10.0f);
101101

102102
// Create view matrix (translate camera backwards a bit, so we can see the geometry)
103-
auto sphereViewMatrix = translate(mat4(), {0.0f, 0.0f, -1.5f});
103+
auto sphereViewMatrix = translate(mat4{1.0}, {0.0f, 0.0f, -1.5f});
104104

105105
// Assign sphere texture
106-
auto sphereModelMatrix = rotate(mat4{}, time, {0, 1, 0});
106+
auto sphereModelMatrix = rotate(mat4{1.0f}, time, {0, 1, 0});
107107

108108
// Set shader inputs
109109
sphereShader.use();
@@ -128,10 +128,10 @@ class FramebufferWindow : public Window {
128128
auto quadProjectionMatrix = perspective((PI / 180.f) * 60.0f, (float)SIZE/(float)SIZE, 1.0f, 10.0f);
129129

130130
// Create view matrix (translate camera backwards a bit, so we can see the geometry)
131-
auto quadViewMatrix = translate(mat4(), {0.0f, 0.0f, -3.0f});
131+
auto quadViewMatrix = translate(mat4{1.0f}, {0.0f, 0.0f, -3.0f});
132132

133133
// Animate rotation of the quad
134-
auto quadModelMatrix = rotate(mat4{}, sin(time / 2.0f) * 1.5f, {0, 1, .1});
134+
auto quadModelMatrix = rotate(mat4{1.0f}, sin(time / 2.0f) * 1.5f, {0, 1, .1});
135135

136136
// Set shader inputs
137137
quadShader.use();

src/gl9_scene/object.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#define GLM_ENABLE_EXPERIMENTAL
12
#include <glm/glm.hpp>
23
#include <glm/gtc/matrix_transform.hpp>
34
#include <glm/gtx/euler_angles.hpp>

src/gl9_scene/space.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ void Space::render(Scene &scene) {
3535

3636
// Render mesh, not using any projections, we just render in 2D
3737
shader->setUniform("ModelMatrix", modelMatrix);
38-
shader->setUniform("ViewMatrix", mat4{});
39-
shader->setUniform("ProjectionMatrix", mat4{});
38+
shader->setUniform("ViewMatrix", mat4{1.0f});
39+
shader->setUniform("ProjectionMatrix", mat4{1.0f});
4040
shader->setUniform("Texture", *texture);
4141
mesh->render();
4242

src/raw2_raycast/raw2_raycast.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ struct World {
212212
}
213213

214214
// Additive lighting result
215-
dvec3 color = ambientColor + emissionColor + diffuseColor + specularColor;
216-
217-
return clamp(color, 0.0, 1.0);
215+
return ambientColor + emissionColor + diffuseColor + specularColor;
218216
}
219217

220218
/*!
@@ -225,7 +223,7 @@ struct World {
225223
// Render section of the framebuffer
226224
for(int y = 0; y < image.height; ++y) {
227225
for (int x = 0; x < image.width; ++x) {
228-
dvec3 color;
226+
dvec3 color{};
229227
for (unsigned int i = 0; i < samples; i++) {
230228
auto ray = camera.generateRay(x, y, image.width, image.height);
231229
color = color + trace(ray);

src/raw3_raytrace/raw3_raytrace.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ struct World {
223223
#pragma omp parallel for
224224
for (int y = 0; y < image.height; ++y) {
225225
for (int x = 0; x < image.width; ++x) {
226-
dvec3 color;
226+
dvec3 color{};
227227

228228
// Generate multiple samples
229229
for (unsigned int i = 0; i < samples; ++i) {
230230
auto ray = camera.generateRay(x, y, image.width, image.height);
231231
color = color + trace(ray, depth);
232232
}
233233
// Collect the data
234-
color = clamp(color / (double) samples, 0.0, 1.0);
234+
color = color / (double) samples;
235235
image.setPixel(x, y, (float)color.r, (float)color.g, (float)color.b);
236236
}
237237
}
@@ -266,7 +266,7 @@ int main() {
266266
};
267267

268268
// Render the scene
269-
world.render(image, 64, 5);
269+
world.render(image, 32, 5);
270270

271271
// Save the result
272272
image::saveBMP(image, "raw3_raytrace.bmp");

src/raw4_raster/raw4_raster.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Program {
100100
auto x = (int) (textCoord.x * (image.width - 1));
101101
auto y = (int) (textCoord.y * (image.height - 1));
102102
// NOTE: The coordinates are vertically inverted for compatibility with object files generated using Blender 3D.
103-
auto pixel = image.getPixel(x, image.height-y-1);
103+
auto pixel = image.getPixel(x, image.height-y);
104104
// Return normalized color vector
105105
return vec4{pixel.r / 255.0f, pixel.g / 255.0f, pixel.b / 255.0f, 1.0};
106106
}
@@ -122,7 +122,7 @@ class Rasterizer {
122122
*/
123123
Vertex toViewport(const Vertex &vertex) {
124124
// Matrix that aligns the screen coordinates to viewport coordinates
125-
static const mat4 viewportMatrix = glm::translate(glm::scale(mat4{}, vec3{image.width / 2.0, -image.height / 2.0, 1.0}), vec3{1, -1, 0});
125+
static const mat4 viewportMatrix = glm::translate(glm::scale(mat4{1.0f}, vec3{image.width / 2.0, -image.height / 2.0, 1.0}), vec3{1, -1, 0});
126126
// First convert homogeneous coordinates to cartesian and transform to viewport
127127
vec4 viewportCoordinates = viewportMatrix * (vertex.position / vertex.position.w);
128128
// Copy rest of the data without change

src/task5_2dshapes/task5_2dshapes.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <iostream>
77
#include <vector>
88

9+
#define GLM_ENABLE_EXPERIMENTAL
910
#include <glm/glm.hpp>
1011
#include <glm/gtx/matrix_transform_2d.hpp>
1112
#include <glm/gtx/euler_angles.hpp>

src/task6_bezier_surface/task6_bezier_surface.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88
#include <vector>
99

10+
#define GLM_ENABLE_EXPERIMENTAL
1011
#include <glm/glm.hpp>
1112
#include <glm/gtc/matrix_transform.hpp>
1213
#include <glm/gtx/euler_angles.hpp>

src/task7_particles/task7_particles.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <map>
1010
#include <list>
1111

12+
#define GLM_ENABLE_EXPERIMENTAL
1213
#include <glm/glm.hpp>
1314
#include <glm/gtc/matrix_transform.hpp>
1415
#include <glm/gtx/euler_angles.hpp>

0 commit comments

Comments
 (0)