fixed some stuff (cannot compile yet though)

This commit is contained in:
Daniel 2023-08-06 12:05:25 +02:00
parent ae99c30c6a
commit 42db40144e
2 changed files with 19 additions and 17 deletions

View File

@ -16,6 +16,16 @@ set(CMAKE_CXX_STANDARD 17) # request C++17
set(CMAKE_CXX_STANDARD_REQUIRED ON) # enforce requested standard set(CMAKE_CXX_STANDARD_REQUIRED ON) # enforce requested standard
set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler specific extensions set(CMAKE_CXX_EXTENSIONS OFF) # disable compiler specific extensions
# add extra include directories
include_directories($ENV{OPENGL_LIBS}/glm)
include_directories($ENV{OPENGL_LIBS}/glad/include)
include_directories($ENV{OPENGL_LIBS}/glfw/include)
# add extra lib directories
include_directories($ENV{OPENGL_LIBS}/glfw/lib)
# helper function to simplify definition of projects # helper function to simplify definition of projects
function(target name) function(target name)
file(GLOB_RECURSE SRC "${name}/*") # recursively collect all files in sub-folder for project file(GLOB_RECURSE SRC "${name}/*") # recursively collect all files in sub-folder for project

View File

@ -13,7 +13,6 @@
#include "util/camera/camera.h" #include "util/camera/camera.h"
#include "object/game_object.h" #include "object/game_object.h"
// TODO: Replace current rendering with he GameObject
// Continue: https://learnopengl.com/Lighting/Colors // Continue: https://learnopengl.com/Lighting/Colors
// Chapter: A lighting scene // Chapter: A lighting scene
// //
@ -35,8 +34,7 @@
typedef glm::mat4 mat4; typedef glm::mat4 mat4;
typedef glm::vec3 vec3; typedef glm::vec3 vec3;
vec3 cameraPosition = vec3(0.0f, 0.0f, 3.0f); Camera cam(glm::vec3(0.0f, 0.0f, 3.0f));
Camera cam(cameraPosition);
float deltaTime = 0.0f, lastFrameTime = 0.0f; float deltaTime = 0.0f, lastFrameTime = 0.0f;
float mouseLastX = WINDOW_WIDTH / 2, mouseLastY = WINDOW_HEIGHT / 2; float mouseLastX = WINDOW_WIDTH / 2, mouseLastY = WINDOW_HEIGHT / 2;
@ -119,7 +117,7 @@ int main()
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{ {
std::cerr << "ERROR::GLAD::INITILISE"; std::cerr << "ERROR::GLAD::INITIALISE";
return -1; return -1;
} }
@ -188,7 +186,7 @@ int main()
vec3(-1.3f, 1.0f, -1.5f) vec3(-1.3f, 1.0f, -1.5f)
}; };
// VBO == all verticies; EBO == connection of vertices (faces) and is optional although it is a bit more efficient than using VBOs, since it reuses vertices; // VBO == all vertices; EBO == connection of vertices (faces) and is optional, although it is a bit more efficient than using VBOs, since it reuses vertices;
// VAO == collection of VBOs/EBOs used for rendering // VAO == collection of VBOs/EBOs used for rendering
GLuint vertexBufferObject, elementBufferObject, vertexArrayObject; GLuint vertexBufferObject, elementBufferObject, vertexArrayObject;
glGenVertexArrays(1, &vertexArrayObject); glGenVertexArrays(1, &vertexArrayObject);
@ -235,7 +233,7 @@ int main()
// main loop // main loop
while(!glfwWindowShouldClose(window)) while(!glfwWindowShouldClose(window))
{ {
float currentFrameTime = glfwGetTime(); float currentFrameTime = (float)glfwGetTime();
deltaTime = currentFrameTime - lastFrameTime; deltaTime = currentFrameTime - lastFrameTime;
lastFrameTime = currentFrameTime; lastFrameTime = currentFrameTime;
@ -244,35 +242,29 @@ int main()
ProcessInput(window); ProcessInput(window);
mat4 viewMatrix = cam.GetViewMatrix();
mat4 projectionMatrix = glm::perspective(glm::radians(cam.Fov), 800.0f / 600.0f, 0.1f, 100.0f); mat4 projectionMatrix = glm::perspective(glm::radians(cam.Fov), 800.0f / 600.0f, 0.1f, 100.0f);
shader->Use(); shader->Use();
shader->SetInt("ourTexture1", 0); shader->SetInt("ourTexture1", 0);
shader->SetInt("ourTexture2", 1); shader->SetInt("ourTexture2", 1);
shader->SetMatrix("viewMatrix", viewMatrix); // more or less the camera shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
shader->SetMatrix("projectionMatrix", projectionMatrix); shader->SetMatrix("projectionMatrix", projectionMatrix);
containerImage.BindTexture(); containerImage.BindTexture();
faceImage.BindTexture(GL_TEXTURE0 + 1); // GL_TEXTURE0 + 1 == GL_TEXTURE1, this means looping over multiple texture units is easily possible faceImage.BindTexture(GL_TEXTURE0 + 1); // GL_TEXTURE0 + 1 == GL_TEXTURE1, this means looping over multiple texture units is easily possible
glBindVertexArray(vertexArrayObject); for (int i = 0; i < 10; i++)
for (int i = 1; i < 10; i++)
{ {
mat4 model = mat4(1.0f); cube.Position = cubePositions[i];
model = glm::translate(model, cubePositions[i]); mat4 model = cube.GetModelMatrix();
float angle = (20.0f * i); float angle = (20.0f * i);
if (i % 3 == 0) if (i % 3 == 0)
angle = currentFrameTime * 25; angle = currentFrameTime * 25;
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f)); model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
shader->SetMatrix("modelMatrix", model); shader->SetMatrix("modelMatrix", model);
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // for EBOs cube.Draw();
glDrawArrays(GL_TRIANGLES, 0, 36); // for VAOs
} }
shader->SetMatrix("modelMatrix", cube.GetModelMatrix());
cube.Draw();
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();