bunch of test things

also new camera class
This commit is contained in:
Claire Schwarzer 2026-02-02 03:12:29 +01:00
parent b47c5e27d8
commit 89e47fa56c
10 changed files with 496 additions and 54 deletions

126
main.cpp
View file

@ -1,4 +1,5 @@
#include <iomanip>
#include <iostream>
#include <glad/glad.h>
@ -6,6 +7,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "stb/stb_easy_font.h"
#include <engine/mesh.h>
#include <engine/shader.h>
@ -78,10 +80,52 @@ int main(int argc, char* argv[])
// Load Shader
Shader shaderTest("assets/shaders/basicVertex.vert", "assets/shaders/basicFragment.frag");
std::vector<Vertex> vertices = {
{ 1, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f },
{ 1, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ 0, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
{ 0, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }
{ -0.5f, -0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 0.0f, 0.0f },
{ 0.5f, -0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 1.0f, 0.0f },
{ 0.5f, 0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 1.0f, 1.0f },
{ 0.5f, 0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 1.0f, 1.0f },
{ -0.5f, 0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 0.0f, 1.0f },
{ -0.5f, -0.5f, -0.5f, 1.0f, 0.2f, 0.2f, 0.0f, 0.0f },
// Back face (+z) green-ish
{ -0.5f, -0.5f, 0.5f, 0.2f, 1.0f, 0.2f, 0.0f, 0.0f },
{ 0.5f, -0.5f, 0.5f, 0.2f, 1.0f, 0.2f, 1.0f, 0.0f },
{ 0.5f, 0.5f, 0.5f, 0.2f, 1.0f, 0.2f, 1.0f, 1.0f },
{ 0.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 0.5f, 1.0f, 0.2f, 1.0f, 0.0f, 0.0f },
{ -0.5f, -0.5f, -0.5f, 1.0f, 0.2f, 1.0f, 0.0f, 1.0f },
// Top face (+y) cyan-ish
{ -0.5f, 0.5f, -0.5f, 0.2f, 1.0f, 1.0f, 0.0f, 1.0f },
{ 0.5f, 0.5f, -0.5f, 0.2f, 1.0f, 1.0f, 1.0f, 1.0f },
{ 0.5f, 0.5f, 0.5f, 0.2f, 1.0f, 1.0f, 1.0f, 0.0f },
{ 0.5f, 0.5f, 0.5f, 0.2f, 1.0f, 1.0f, 1.0f, 0.0f },
{ -0.5f, 0.5f, 0.5f, 0.2f, 1.0f, 1.0f, 0.0f, 0.0f },
{ -0.5f, 0.5f, -0.5f, 0.2f, 1.0f, 1.0f, 0.0f, 1.0f }
};
std::vector<unsigned int> indices = {
0, 1, 3,
@ -90,16 +134,6 @@ int main(int argc, char* argv[])
Mesh testMesh(vertices, indices);
std::vector<Vertex> vertices2 = {
{ 0, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.6f, 1.0f },
{ 0, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ -1, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
{ -1, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f }
};
Mesh testMesh2(vertices2, indices);
Texture texture1("assets/wall.jpg");
Texture texture2("assets/awesomeface.png", true);
@ -107,25 +141,79 @@ int main(int argc, char* argv[])
shaderTest.setInt("ourTexture", 0);
shaderTest.setInt("decal", 1);
glm::vec3 cubePositions[] = {
glm::vec3( 0.0f, 0.0f, 0.0f),
glm::vec3( 2.0f, 5.0f, -15.0f),
glm::vec3(-1.5f, -2.2f, -2.5f),
glm::vec3(-3.8f, -2.0f, -12.3f),
glm::vec3( 2.4f, -0.4f, -3.5f),
glm::vec3(-1.7f, 3.0f, -7.5f),
glm::vec3( 1.3f, -2.0f, -2.5f),
glm::vec3( 1.5f, 2.0f, -2.5f),
glm::vec3( 1.5f, 0.2f, -1.5f),
glm::vec3(-1.3f, 1.0f, -1.5f)
};
// Render Loop
double lastTime = 0.0;
int nbFrames = 0;
while (!glfwWindowShouldClose(window))
{
// Calculate FPS
double currentTime = glfwGetTime();
nbFrames++;
if (currentTime - lastTime >= 1.0) { // Update every second
double fps = nbFrames / (currentTime - lastTime);
std::cout << fps << std::endl;
nbFrames = 0;
lastTime += 1.0;
}
// Input processing
processInput(window);
// Rendering
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
shaderTest.Use();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1.ID);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2.ID);
testMesh.Draw();
testMesh2.Draw();
shaderTest.Use();
// Test
glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f));
glm::mat4 view = glm::mat4(1.0f);
// note that we're translating the scene in the reverse direction of where we want to move
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
glm::mat4 projection;
projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
shaderTest.setMat4("model", model);
shaderTest.setMat4("view", view);
shaderTest.setMat4("projection", projection);
//testMesh.Draw();
glBindVertexArray(testMesh.VAO);
for(unsigned int i = 0; i < 10; i++)
{
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, cubePositions[i]);
float angle = 20.0f * i;
model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f));
shaderTest.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
// Call events & swap buffers
glfwSwapBuffers(window);