Compare commits

..

3 Commits

Author SHA1 Message Date
4a57bb1357 feat: added FPS counter to terminal 2025-09-03 13:55:51 +02:00
a6cad08505 setup: defined cxx version in cmake 2025-09-03 13:55:17 +02:00
b5f6758400 feat: added sin distortions 2025-09-03 12:59:38 +02:00
4 changed files with 61 additions and 1 deletions

View File

@@ -4,8 +4,11 @@ project(64kDemo VERSION 0.1
DESCRIPTION "CPU SDF Renderer"
LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
SET(CMAKE_CXX_FLAGS "-Os -s")
add_executable(one main.cpp)
target_link_libraries(one m glfw GLEW GL)

40
PerformanceAnalyser.hpp Normal file
View File

@@ -0,0 +1,40 @@
#include <GL/glew.h>
#include <cmath>
#include <iostream>
class PerformanceAnalyser {
private:
double lastFrameTime = 0;
int frameCount = 0;
double timeAcc = 0;
double lastFps = 0;
public:
PerformanceAnalyser(int framesToAcc = 10, bool autoPrint = true)
: framesToAcc(framesToAcc), autoPrint(autoPrint) {};
int framesToAcc;
bool autoPrint;
int getFPS() { return lastFps; }
void update(float time) {
timeAcc += (time - lastFrameTime);
lastFrameTime = time;
frameCount++;
if (frameCount == framesToAcc) {
lastFps = double(framesToAcc) / timeAcc;
if (autoPrint) {
std::cout << "Fps: " << std::round(lastFps * 10.0) * 0.1 << "\n"
<< std::flush;
}
frameCount = 0;
timeAcc = 0;
}
}
};

View File

@@ -1,7 +1,9 @@
#include "FullScreenQuad.hpp"
#include "PerformanceAnalyser.hpp"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <cstdio>
#include <iostream>
const char *vertexShaderSource =
#include "fsq.glsl"
@@ -75,6 +77,8 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
}
int main(int argc, char **argv) {
std::cout << "test";
std::cout << std::flush;
GLFWwindow *window;
@@ -104,7 +108,15 @@ int main(int argc, char **argv) {
FullScreenQuad fsq{};
PerformanceAnalyser perf{};
double time = glfwGetTime();
while (!glfwWindowShouldClose(window)) {
time = glfwGetTime();
perf.update(time);
processInput(window);
/* Render here */
@@ -112,8 +124,12 @@ int main(int argc, char **argv) {
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
glUniform1f(aspectLocation, aspect);
int timeLocation = glGetUniformLocation(shaderProgram, "t");
glUniform1f(timeLocation, 2. * time);
glBindVertexArray(fsq.getVAO());
glDrawArrays(GL_TRIANGLES, 0, 6);

View File

@@ -5,6 +5,7 @@ out vec4 FragColor;
in vec2 texCoords;
uniform float aspect;
uniform float t;
vec3 center = vec3(0.0,-4.0,20.0);
float radius = 5.0;
@@ -55,7 +56,7 @@ float planeMin(vec3 pos){
}
float sphereMin(vec3 pos){
return length(pos - center) - radius;
return length(pos - center) - radius + 0.2*sin(5*pos.x+t)*sin(5*pos.y+t)*sin(5*pos.z+t);
}
Ray minFn(Ray ray){