Skip to content

Commit

Permalink
Feat: Added vendor includes and libs to the repo to make it easily ru…
Browse files Browse the repository at this point in the history
…nnable
  • Loading branch information
rabinadk1 committed Jun 8, 2024
1 parent 66e5a26 commit 3cb8da8
Show file tree
Hide file tree
Showing 553 changed files with 141,098 additions and 903 deletions.
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.5.0)
project(ictc-modeling VERSION 0.1.0)

if(MSVC)
add_compile_options(/W4)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Weffc++)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

add_executable(ictc-modeling main.cpp IndexBuffer.cpp VertexBuffer.cpp VertexArray.cpp Shader.cpp Renderer.cpp Texture.cpp Camera.cpp Mesh.cpp Model.cpp CubeMap.cpp stb_image.cpp)
add_compile_options(-Wall -Wextra -Wpedantic -Weffc++)


file(GLOB src_files CONFIGURE_DEPENDS "*.cpp")
add_executable(ictc-modeling ${src_files})

target_include_directories(ictc-modeling PRIVATE includes)
target_link_libraries(ictc-modeling PRIVATE GLEW glfw GL X11 dl assimp)
target_include_directories(ictc-modeling SYSTEM PRIVATE vendor_includes)

target_link_directories(ictc-modeling PRIVATE vendor_libs)
target_link_libraries(ictc-modeling PRIVATE GLEW glfw GL assimp)

target_compile_features(ictc-modeling PRIVATE cxx_auto_type)
target_compile_features(ictc-modeling PRIVATE cxx_nullptr)
target_compile_features(ictc-modeling PRIVATE cxx_range_for)
93 changes: 39 additions & 54 deletions Camera.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#include "Camera.hpp"

#define PLANE_Y -1.f
Camera::Camera(const glm::vec3 &position, const glm::vec3 &up, const float yaw,
const float pitch, const float fov)
: m_Yaw(yaw), m_Pitch(pitch), m_FOV(fov), m_Up(up), m_Position(position),
m_Front(calculateFrontVector(yaw, pitch)),
m_Right(calculateRightVector(m_Front, up)) {}

Camera::Camera(const glm::vec3 &position, const glm::vec3 &up, float yaw, float pitch)
: m_Position(position),
m_Up(up),
m_Yaw(yaw),
m_Pitch(pitch),
m_FOV(45.f)
{
updateCameraVectors();
}
Camera::Camera(const float posX, const float posY, const float posZ,
const float upX, const float upY, const float upZ,
const float yaw, const float pitch, const float fov)
: m_Yaw(yaw), m_Pitch(pitch), m_FOV(fov), m_Up(glm::vec3(upX, upY, upZ)),
m_Position(glm::vec3(posX, posY, posZ)),
m_Front(calculateFrontVector(yaw, pitch)),
m_Right(calculateRightVector(m_Front, m_Up)) {}

Camera::Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch)
: m_Position(glm::vec3(posX, posY, posZ)),
m_Up(glm::vec3(upX, upY, upZ)),
m_Yaw(yaw),
m_Pitch(pitch),
m_FOV(45.f)
{
updateCameraVectors();
}
void Camera::ProcessKeyboard(const CameraMovement &direction,
const float deltaTime) {
constexpr float plane_y = -1.f;

void Camera::ProcessKeyboard(const CameraMovement &direction, float deltaTime)
{
const float velocity = 2.5f * deltaTime;

switch (direction)
{
switch (direction) {
case CameraMovement::FORWARD:
m_Position += m_Front * velocity;
break;
Expand All @@ -47,50 +40,42 @@ void Camera::ProcessKeyboard(const CameraMovement &direction, float deltaTime)
default:
m_Position -= m_Up * velocity;
}
if (m_Position.y <= PLANE_Y)
m_Position.y = PLANE_Y;
if (m_Position.y <= plane_y)
m_Position.y = plane_y;
}

void Camera::ProcessMouseMovement(float xoffset, float yoffset, bool constrainPitch)
{
const float mouseSensitivity = 0.1f;
void Camera::ProcessMouseMovement(const float xoffset, const float yoffset,
bool constrainPitch) {
constexpr float mouseSensitivity = 0.1f;
m_Yaw += xoffset * mouseSensitivity;
m_Pitch += yoffset * mouseSensitivity;

constexpr float max_Pitch = 89.f;
// Make sure that when pitch is out of bounds, screen doesn't get flipped
if (constrainPitch)
{
if (m_Pitch > 89.0f)
m_Pitch = 89.0f;
else if (m_Pitch < -89.0f)
m_Pitch = -89.0f;
if (constrainPitch) {
if (m_Pitch > max_Pitch)
m_Pitch = max_Pitch;
else if (m_Pitch < -max_Pitch)
m_Pitch = -max_Pitch;
}

// Update Front & Right Vectors using the updated Euler angles
updateCameraVectors();
}

void Camera::ProcessMouseScroll(float yoffset)
{
m_FOV -= yoffset;
if (m_FOV < 1.f)
m_FOV = 1.f;
else if (m_FOV > 45.f)
m_FOV = 45.f;
}

void Camera::updateCameraVectors()
{
// Calculate the new Front vector
m_Front = glm::normalize(
glm::vec3(
cos(glm::radians(m_Yaw)) * cos(glm::radians(m_Pitch)),
sin(glm::radians(m_Pitch)),
sin(glm::radians(m_Yaw)) * cos(glm::radians(m_Pitch))));
m_Front = calculateFrontVector(m_Yaw, m_Pitch);

/*
Recalculate the right vector also
Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
Normalize the vectors, because their length gets closer to 0 the more you look
up or down which results in slower movement.
*/
m_Right = glm::normalize(glm::cross(m_Front, m_Up));
m_Right = calculateRightVector(m_Front, m_Up);
}

void Camera::ProcessMouseScroll(const float yoffset) {
m_FOV -= -yoffset;
if (m_FOV < 1.f)
m_FOV = 1.f;
else if (m_FOV > 45.f)
m_FOV = 45.f;
}
28 changes: 13 additions & 15 deletions CubeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,28 @@
#include "stb_image.h"

CubeMap::CubeMap(const std::vector<std::string> &faces)
{
glGenTextures(1, &m_RendererID);
glBindTexture(GL_TEXTURE_CUBE_MAP, m_RendererID);
: m_RendererID(generateRenderedID()) {

int width, height, nrChannels;
u_char *localBuffer;
stbi_set_flip_vertically_on_load(false);
for (uint i = 0; i < faces.size(); ++i)
{
for (size_t i = 0; i < faces.size(); ++i) {
int width, height, nrChannels;
/*
load and generate the texture
NOTE: Last argument to force the number of channels, **0 to not force**
*/
localBuffer = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
if (localBuffer)
{
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, localBuffer);
if (const auto localBuffer =
stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
localBuffer) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, width, height,
0, GL_RGB, GL_UNSIGNED_BYTE, localBuffer);
stbi_image_free(localBuffer);
}
else
std::cerr << "Cubemap tex failed to load at path: " << faces[i] << std::endl;
} else
std::cerr << "Cubemap tex failed to load at path: " << faces[i]
<< std::endl;
}

// set the texture wrapping/filtering options (on the currently bound texture object)
// set the texture wrapping/filtering options (on the currently bound texture
// object)
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
Expand Down
8 changes: 3 additions & 5 deletions IndexBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "IndexBuffer.hpp"

IndexBuffer::IndexBuffer(const unsigned int *data, const unsigned int count)
: m_Count(count)
{
glGenBuffers(1, &m_RendererID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW);
: m_Count(count), m_RendererID(generateRendererID()) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data,
GL_STATIC_DRAW);
}
62 changes: 19 additions & 43 deletions Mesh.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,41 @@
#include "Mesh.hpp"
#include "VertexBufferLayout.hpp"
#include "Renderer.hpp"

Mesh::Mesh(std::vector<Vertex> &vertices, std::vector<uint> &indices, const std::unordered_map<std::string, Texture> &texturesLoaded, std::vector<std::string> &textures)
: m_TexturesLoaded(texturesLoaded),
m_Vertices(vertices),
m_Indices(indices),
m_Textures(textures),
m_VA(),
Mesh::Mesh(const std::vector<Vertex> &vertices,
const std::vector<unsigned int> &indices,
const std::unordered_map<std::string, Texture> &texturesLoaded,
const std::vector<std::string> &textures)
: m_TexturesLoaded(texturesLoaded), m_Vertices(vertices),
m_Indices(indices), m_Textures(textures),
m_IB(&indices[0], indices.size()),
m_VB(&vertices[0], sizeof(Vertex) * vertices.size()),
/*
NOTE: Address of Vector and the address of first element of vector are different.
Also, sizeof(<vector>) is the size of the vector not containing data
NOTE: Address of Vector and the address of first element of vector are
different. Also, sizeof(<vector>) is the size of the vector not containing
data
*/
m_VB(&vertices[0], sizeof(Vertex) * vertices.size())
{
SetupMesh();
}

void Mesh::SetupMesh() const
{
VertexBufferLayout layout;

// For Vertex Positions
layout.Push<float>(3);

//For Vertex Normals
layout.Push<float>(3);

// For Vertex Texture Coords
layout.Push<float>(2);
m_VA(m_VB, generateVertextBufferLayout()) {}

// For Vertex Tangent
layout.Push<float>(3);

// For Vertex Bitangent
layout.Push<float>(3);

m_VA.AddBuffer(m_VB, layout);
}

void Mesh::Draw(Shader &shader) const
{
void Mesh::Draw(Shader &shader) const {
// bind appropriate textures
uint diffuseNr = 1;
uint specularNr = 1;
unsigned int diffuseNr = 1;
unsigned int specularNr = 1;

for (uint i = 0; i < m_Textures.size(); ++i)
{
for (size_t i = 0; i < m_Textures.size(); ++i) {
const Texture &texture = m_TexturesLoaded.find(m_Textures[i])->second;
// retrieve texture number (the N in diffuse_textureN)
std::string number;
const std::string &textureType = texture.GetType();
const auto &textureType = texture.GetType();

if (textureType == "diffuse")
number = std::to_string(diffuseNr++);
else if (textureType == "specular")
number = std::to_string(specularNr++); // transfer unsigned int to stream
else
continue;
shader.SetUniform(("u_Material." + textureType + number).c_str(), static_cast<int>(i));

shader.SetUniform(("u_Material." + textureType + number).c_str(),
static_cast<int>(i));
texture.Bind(i);
}

Expand Down
Loading

0 comments on commit 3cb8da8

Please sign in to comment.