feat: add padaczka

This commit is contained in:
Krzysztof Rudnicki 2022-08-30 20:02:22 +02:00
parent 5373d14909
commit aeb44363a0
3 changed files with 52 additions and 1 deletions

View File

@ -10,7 +10,8 @@
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": []
"compilerArgs": [],
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4

Binary file not shown.

View File

@ -6,6 +6,11 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include <random> // I am using standart library RNG because I am lazy and wanted to create quick code snippet
// upgrade to this: https://arvid.io/2018/06/30/on-cxx-random-number-generator-quality/ whenever, if ever I feel like it
#include <chrono> // for std::chrono
#include "constants.hpp"
void configureGLFW() {
@ -68,12 +73,55 @@ void viewPort(GLFWwindow* window)
// we call framebuffer_size_callback on every window resize
}
void processInput(GLFWwindow *window)
{
// glfwGetKey takes window and key as an input and checks is currently being pressed
// if the user pressed escape we close window
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if(glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
const float padaczkaSimulator()
{
// Seed our Mersenne Twister using the
std::mt19937 mt{ static_cast<unsigned int>(
std::chrono::steady_clock::now().time_since_epoch().count()
) };
// Create a reusable random number generator that generates uniform numbers between 1 and 6
std::uniform_int_distribution ten{ 1, 10 }; // for C++14, use std::uniform_int_distribution<> die6{ 1, 6 };
const float MT_FLOAT = static_cast<float> (ten(mt) % 10);
return MT_FLOAT / 10;
}
void renderLoop(GLFWwindow* window)
{
// glfwWindowShouldClose checks if GLFW was instructed to close
while(!glfwWindowShouldClose(window))
{
// input
processInput(window);
const float FIRST_COLOR = padaczkaSimulator();
const float SECOND_COLOR = padaczkaSimulator();
const float THIRD_COLOR = padaczkaSimulator();
const float FOUR_COLOR = padaczkaSimulator();
std::cout << FIRST_COLOR << std::endl;
glClearColor( FIRST_COLOR, SECOND_COLOR, THIRD_COLOR, FOUR_COLOR);
glClear(GL_COLOR_BUFFER_BIT);
// swaps buffer containing color values of each pixel in window
// there is front buffer (final image) and back buffer (where all rendering commands draw to)
// when back buffer is ready we swap it with front buffer to eliminate flickering
glfwSwapBuffers(window);
// glfwPollEvents checks if any event (like mouse/keyboard input was triggered), updates window state and calls functions (which we register via callback methods)
glfwPollEvents();
}
}
@ -97,6 +145,8 @@ int main()
viewPort(window);
renderLoop(window);
// clean GLFW resources
glfwTerminate();
return 0;
}