Compare commits
3 Commits
8349039167
...
4a57bb1357
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a57bb1357 | |||
| a6cad08505 | |||
| b5f6758400 |
@@ -4,8 +4,11 @@ project(64kDemo VERSION 0.1
|
|||||||
DESCRIPTION "CPU SDF Renderer"
|
DESCRIPTION "CPU SDF Renderer"
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
SET(CMAKE_CXX_FLAGS "-Os -s")
|
SET(CMAKE_CXX_FLAGS "-Os -s")
|
||||||
|
|
||||||
|
|
||||||
add_executable(one main.cpp)
|
add_executable(one main.cpp)
|
||||||
|
|
||||||
target_link_libraries(one m glfw GLEW GL)
|
target_link_libraries(one m glfw GLEW GL)
|
||||||
|
|||||||
40
PerformanceAnalyser.hpp
Normal file
40
PerformanceAnalyser.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
16
main.cpp
16
main.cpp
@@ -1,7 +1,9 @@
|
|||||||
#include "FullScreenQuad.hpp"
|
#include "FullScreenQuad.hpp"
|
||||||
|
#include "PerformanceAnalyser.hpp"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
const char *vertexShaderSource =
|
const char *vertexShaderSource =
|
||||||
#include "fsq.glsl"
|
#include "fsq.glsl"
|
||||||
@@ -75,6 +77,8 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
std::cout << "test";
|
||||||
|
std::cout << std::flush;
|
||||||
|
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
|
|
||||||
@@ -104,7 +108,15 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
FullScreenQuad fsq{};
|
FullScreenQuad fsq{};
|
||||||
|
|
||||||
|
PerformanceAnalyser perf{};
|
||||||
|
|
||||||
|
double time = glfwGetTime();
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
|
||||||
|
time = glfwGetTime();
|
||||||
|
perf.update(time);
|
||||||
|
|
||||||
processInput(window);
|
processInput(window);
|
||||||
/* Render here */
|
/* Render here */
|
||||||
|
|
||||||
@@ -112,8 +124,12 @@ int main(int argc, char **argv) {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(shaderProgram);
|
glUseProgram(shaderProgram);
|
||||||
|
|
||||||
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
|
int aspectLocation = glGetUniformLocation(shaderProgram, "aspect");
|
||||||
glUniform1f(aspectLocation, aspect);
|
glUniform1f(aspectLocation, aspect);
|
||||||
|
int timeLocation = glGetUniformLocation(shaderProgram, "t");
|
||||||
|
glUniform1f(timeLocation, 2. * time);
|
||||||
|
|
||||||
glBindVertexArray(fsq.getVAO());
|
glBindVertexArray(fsq.getVAO());
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
|
|||||||
3
sdf.glsl
3
sdf.glsl
@@ -5,6 +5,7 @@ out vec4 FragColor;
|
|||||||
in vec2 texCoords;
|
in vec2 texCoords;
|
||||||
|
|
||||||
uniform float aspect;
|
uniform float aspect;
|
||||||
|
uniform float t;
|
||||||
|
|
||||||
vec3 center = vec3(0.0,-4.0,20.0);
|
vec3 center = vec3(0.0,-4.0,20.0);
|
||||||
float radius = 5.0;
|
float radius = 5.0;
|
||||||
@@ -55,7 +56,7 @@ float planeMin(vec3 pos){
|
|||||||
}
|
}
|
||||||
|
|
||||||
float sphereMin(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){
|
Ray minFn(Ray ray){
|
||||||
|
|||||||
Reference in New Issue
Block a user