Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8056c32
Added the end introduction code
joksim Mar 1, 2019
3187fcc
Added 2.1 Basic triangle
joksim Mar 7, 2019
7f2d593
Cleanup of 2.1
joksim Mar 7, 2019
108f55e
Reformatting
joksim Mar 8, 2019
7d59dd8
Reformatting
joksim Mar 8, 2019
84106e7
Drawing quad using 2 triangles. Using EBO for drawing.
joksim Mar 14, 2019
7cbf8ec
Drawing a triangle using std::vector
joksim Mar 14, 2019
46625af
Added Pac-man with 8 angles using vector
joksim Mar 14, 2019
f43152f
Correction
joksim Mar 14, 2019
e8bfeea
Changed cmath related functions to glm functions
joksim Mar 15, 2019
1a8607b
Added glm constants in code
joksim Mar 15, 2019
66f6eb0
Fixed CMakeLists.txt to add the resources project and symlink the cor…
joksim Mar 23, 2019
f1ab01c
Added the uniform GLSL exampl
joksim Mar 23, 2019
ff18e1b
Added the uniform GLSL exampl
joksim Mar 23, 2019
1552375
Simple fragmet example
joksim Mar 24, 2019
2ea6550
Added the Shader class example
joksim Mar 24, 2019
d224a2f
Cleanup
joksim Mar 29, 2019
ffc1dab
CMake fixes
joksim Apr 1, 2019
f54d321
CleanUp and additional constructor of Shader class
joksim Apr 3, 2019
5835a2f
Mixing textures in fragment shader
joksim Apr 3, 2019
a465806
Added Transformations
joksim Apr 25, 2019
3424be6
Added Transformations 2
joksim Apr 25, 2019
3068c48
Coordinate systems
joksim Apr 25, 2019
e3258dc
coordinate-systems-2
joksim May 2, 2019
9d37a6e
coordinate-systems-3
joksim May 2, 2019
72d2273
coordinate-systems-4
joksim May 2, 2019
c8db050
camera-1
joksim May 2, 2019
bc2fbec
camera-2
joksim May 2, 2019
69759e4
camera-3
joksim May 2, 2019
8b9221e
camera-4
joksim May 2, 2019
5ea83c6
initial commit
JosifovMatej404 Oct 1, 2025
96e2f4b
fix?
JosifovMatej404 Oct 15, 2025
de1730f
Merge branch 'camera-4' of https://github.com/JosifovMatej404/OpenGLPrj
JosifovMatej404 Oct 15, 2025
916bd0a
created basic plane
JosifovMatej404 Oct 18, 2025
6f4d561
added island shape generation
JosifovMatej404 Oct 18, 2025
7679658
implemented randomly generated terrain, basic lightning, basic coloring
JosifovMatej404 Oct 18, 2025
b4f5e71
cleaned up main.cpp
JosifovMatej404 Oct 18, 2025
ed13ced
increased shadow and grid resolution, changed shadow calculation code
JosifovMatej404 Oct 22, 2025
8353b86
fixed shadows
JosifovMatej404 Oct 25, 2025
a61f45f
added sun and bloom effect
JosifovMatej404 Oct 26, 2025
500eb3b
fixed colors and added beaches
JosifovMatej404 Oct 26, 2025
744bcc9
added skybox
JosifovMatej404 Nov 8, 2025
ecf973b
added terrain erosion and water
JosifovMatej404 Dec 23, 2025
e879e34
fixed-shadow-island-water
JosifovMatej404 Dec 24, 2025
b34d370
fixed-water-shadow and span
JosifovMatej404 Dec 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[Bb]uild/
.vs/
47 changes: 37 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(OpenGLPrj)
option(GLFW_BUILD_DOCS OFF)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)

add_subdirectory(vendor/glfw)

if(MSVC)
Expand All @@ -15,6 +16,9 @@ else()
endif()
endif()

set(SHADERS_RELATIVE_SRC_PATH "res/shaders")
set(TEXTURES_RELATIVE_SRC_PATH "res/textures")

include_directories(include/
vendor/glad/include/
vendor/glfw/include/
Expand All @@ -24,13 +28,19 @@ include_directories(include/
file(GLOB VENDORS_SOURCES vendor/glad/src/glad.c)
file(GLOB PROJECT_HEADERS include/*.hpp)
file(GLOB PROJECT_SOURCES src/*.cpp)
file(GLOB PROJECT_SHADERS shaders/*.comp
shaders/*.frag
shaders/*.geom
shaders/*.vert
shaders/*.vs
shaders/*.fs
file(GLOB PROJECT_SHADERS ${SHADERS_RELATIVE_SRC_PATH}/*.comp
${SHADERS_RELATIVE_SRC_PATH}/*.frag
${SHADERS_RELATIVE_SRC_PATH}/*.geom
${SHADERS_RELATIVE_SRC_PATH}/*.vert
${SHADERS_RELATIVE_SRC_PATH}/*.vs
${SHADERS_RELATIVE_SRC_PATH}/*.fs
${SHADERS_RELATIVE_SRC_PATH}/*.glsl
)

file(GLOB PROJECT_TEXTURES ${TEXTURES_RELATIVE_SRC_PATH}/*.png
${TEXTURES_RELATIVE_SRC_PATH}/*.jpg
)

file(GLOB PROJECT_CONFIGS CMakeLists.txt
Readme.md
.gitattributes
Expand All @@ -39,17 +49,34 @@ file(GLOB PROJECT_CONFIGS CMakeLists.txt

source_group("include" FILES ${PROJECT_HEADERS})
source_group("shaders" FILES ${PROJECT_SHADERS})
source_group("textures" FILES ${PROJECT_TEXTURES})
source_group("src" FILES ${PROJECT_SOURCES})
source_group("vendors" FILES ${VENDORS_SOURCES})

add_definitions(-DGLFW_INCLUDE_NONE
-DPROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\")

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES} ${PROJECT_HEADERS}
${PROJECT_SHADERS} ${PROJECT_CONFIGS}
${VENDORS_SOURCES})
${PROJECT_SHADERS} ${PROJECT_TEXTURES} ${PROJECT_CONFIGS}
${VENDORS_SOURCES} "src/Mesh.cpp" "src/Skybox.cpp")
target_link_libraries(${PROJECT_NAME}
glfw
${GLFW_LIBRARIES} ${GLAD_LIBRARIES}
)
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_NAME})


#set (source "${CMAKE_SOURCE_DIR}/res")
#set (destination "${CMAKE_CURRENT_BINARY_DIR}/res")

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/res
$<TARGET_FILE_DIR:${PROJECT_NAME}>/../res)


set_target_properties(${PROJECT_NAME}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/bin"
)
68 changes: 68 additions & 0 deletions include/Camera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef CAMERA_H
#define CAMERA_H

#include <glad/glad.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <vector>

// Defines several possible options for camera movement. Used as abstraction to
// stay away from window-system specific input methods
enum Camera_Movement { FORWARD, BACKWARD, LEFT, RIGHT };

// Default camera values
const float YAW = -90.0f;
const float PITCH = 0.0f;
const float SPEED = 2.5f;
const float SENSITIVITY = 0.1f;
const float ZOOM = 45.0f;

// An abstract camera class that processes input and calculates the
// corresponding Euler Angles, Vectors and Matrices for use in OpenGL
class Camera {
public:
// Camera Attributes
glm::vec3 Position;
glm::vec3 Front;
glm::vec3 Up;
glm::vec3 Right;
glm::vec3 WorldUp;
// Euler Angles
float Yaw;
float Pitch;
// Camera options
float MovementSpeed;
float MouseSensitivity;
float Zoom;

// Constructor with vectors
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW,
float pitch = PITCH);
// Constructor with scalar values
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ,
float yaw, float pitch);

// Returns the view matrix calculated using Euler Angles and the LookAt Matrix
glm::mat4 GetViewMatrix();

// Processes input received from any keyboard-like input system. Accepts input
// parameter in the form of camera defined ENUM (to abstract it from windowing
// systems)
void ProcessKeyboard(Camera_Movement direction, float deltaTime);

// Processes input received from a mouse input system. Expects the offset
// value in both the x and y direction.
void ProcessMouseMovement(float xoffset, float yoffset,
GLboolean constrainPitch = true);

// Processes input received from a mouse scroll-wheel event. Only requires
// input on the vertical wheel-axis
void ProcessMouseScroll(float yoffset);

private:
// Calculates the front vector from the Camera's (updated) Euler Angles
void updateCameraVectors();
};
#endif
18 changes: 18 additions & 0 deletions include/Mesh.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef mMesh
#define mMesh
#pragma once

#include <vector>
#include <glm/glm.hpp>

class Mesh {
public:
std::vector<float> vertices; // interleaved: pos(x,y,z), normal(x,y,z), uv(u,v)
std::vector<unsigned int> indices;
int vertexCount;

static Mesh generateGrid(float width, float depth, int m, int n, int erosionIterations, float hydraulicFactor, float talusAngle);
static Mesh generateWaterPlane(float width, float depth, unsigned int divisions);
};

#endif
8 changes: 1 addition & 7 deletions include/OpenGLPrj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,5 @@

// Reference: https://github.com/nothings/stb/blob/master/stb_image.h#L4
// To use stb_image, add this in *one* C++ source file.
// #define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

// Define Some Constants
const int mWidth = 1280;
const int mHeight = 800;

#endif //~ Glitter Header
#endif //~ OpenGLPrj Header
77 changes: 77 additions & 0 deletions include/Shader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef SHADER_HPP
#define SHADER_HPP

#include <glad/glad.h> // include glad to get all the required OpenGL headers

#include <fstream>
#include <glm/common.hpp>
#include <glm/matrix.hpp>
#include <glm/vector_relational.hpp>
#include <iostream>
#include <sstream>
#include <string>

class Shader {
public:
enum SHADER_TYPE { VERTEX, FRAGMENT, GEOMETRY };

unsigned int ID;
// constructor generates the shader on the fly
// ------------------------------------------------------------------------
Shader(const char *vertexPath, const char *fragmentPath);

// constructor using std::string
// ------------------------------------------------------------------------
Shader(const std::string vertexPath, const std::string fragmentPath);

// activate the shader
// ------------------------------------------------------------------------
void use();

// utility uniform functions
// ------------------------------------------------------------------------
void setBool(const std::string &name, bool value) const;

// ------------------------------------------------------------------------
void setInt(const std::string &name, int value) const;

// ------------------------------------------------------------------------
void setFloat(const std::string &name, float value) const;

// ------------------------------------------------------------------------
void setVec2(const std::string &name, const glm::vec2 &value) const;
void setVec2(const std::string &name, float x, float y) const;

// ------------------------------------------------------------------------
void setVec3(const std::string &name, const glm::vec3 &value) const;

void setVec3(const std::string &name, float x, float y, float z) const;
// ------------------------------------------------------------------------
void setVec4(const std::string &name, const glm::vec4 &value) const;

void setVec4(const std::string &name, float x, float y, float z,
float w) const;

// ------------------------------------------------------------------------
void setMat2(const std::string &name, const glm::mat2 &mat) const;

// ------------------------------------------------------------------------
void setMat3(const std::string &name, const glm::mat3 &mat) const;

// ------------------------------------------------------------------------
void setMat4(const std::string &name, const glm::mat4 &mat) const;

private:
// utility function for checking shader compilation/linking errors.
// ------------------------------------------------------------------------
void checkCompileErrors(unsigned int shader, std::string type);

void readShader(char const *const, Shader::SHADER_TYPE);

void compileShader();

std::string vertexShader;
std::string fragmentShader;
};

#endif // SHADER_HPP
20 changes: 20 additions & 0 deletions include/Skybox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <string>
#include <iostream>
#include <glad/glad.h> // or GLEW

class SkyBox {
int width, height, channels;
std::string imagePath;
unsigned int textureID; // OpenGL texture handle

public:

// Constructor: takes path to the cross image
SkyBox(const std::string& path);

unsigned char* extractFace(unsigned char* src, int faceSize, int xOffset, int yOffset, int width, int channels);
unsigned int loadCubemapFromCross(const std::string& path);

unsigned int getTextureID() const { return textureID; }
};
87 changes: 87 additions & 0 deletions include/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#ifndef mMain
#define mMain
#pragma once


#include <OpenGLPrj.hpp>
#include <GLFW/glfw3.h>
#include <Camera.hpp>
#include <Shader.hpp>
#include <Mesh.hpp>
#include <stb_perlin.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

const unsigned int SCR_WIDTH = 1920;
const unsigned int SCR_HEIGHT = 1080;

Camera camera(glm::vec3(0.0f, 5.0f, 10.0f));

float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;

float deltaTime = 0.0f;
float lastFrame = 0.0f;

unsigned int quadVAO = 0;
unsigned int quadVBO;

const float DAY_LENGTH = 300.0f; // seconds per full day (adjust)

std::unordered_map<std::string, Shader> shaders;

struct BloomBuffers {
unsigned int hdrFBO;
unsigned int colorBuffers[2];
unsigned int pingpongFBO[2];
unsigned int pingpongColorbuffers[2];
};

struct Vertex {
glm::vec3 Position;
glm::vec3 Normal;
glm::vec2 TexCoords;
glm::vec3 Tangent;
glm::vec3 Bitangent;
};


// Function declarations
// Main
int main();

// GLFW / OpenGL init
GLFWwindow* initGLFW();
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);

// Mesh & Shadow setup
void setupMesh(const Mesh& terrain, unsigned int& VAO, unsigned int& VBO, unsigned int& EBO);
void setupShadowMap(unsigned int& depthMapFBO, unsigned int& depthMap, const unsigned int SHADOW_WIDTH, const unsigned int SHADOW_HEIGHT);
unsigned int setupSun();

// Render helpers
void setupBloomBuffers(BloomBuffers& bloom, unsigned int width, unsigned int height);
void renderSun(Shader* sunShader, unsigned int sunVAO, glm::vec3 lightDir, glm::mat4 projection, glm::mat4 view);

// Render loop
void renderLoop(GLFWwindow* window,
std::unordered_map<std::string, std::unique_ptr<Shader>>& shaders,
const Mesh& terrain, unsigned int terrainVAO,
const Mesh& waterMesh, unsigned int waterVAO,
unsigned int depthMapFBO, unsigned int depthMap);

void renderQuad();

unsigned int loadWaterNormalMap(const char* path);
unsigned int createWaterPlaneVAO(std::vector<float>& outVertices, std::vector<unsigned int>& outIndices, unsigned int& VAO, unsigned int& VBO, unsigned int& EBO);
// Input
void processInput(GLFWwindow* window);
#endif
Loading