Merge branch 'master' of gitlab.com:4VRDriver/fall-fever into master

This commit is contained in:
4VRDriver
2020-08-31 17:38:47 +02:00
8 changed files with 136 additions and 9 deletions

2
.vscode/launch.json vendored
View File

@@ -9,7 +9,7 @@
"name": "(gdb) Starten",
"type": "cppdbg",
"request": "launch",
"program": "build/Fall-Fever",
"program": "${workspaceFolder}/build/Fall-Fever",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

47
.vscode/settings.json vendored
View File

@@ -1,6 +1,51 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"files.associations": {
"ostream": "cpp"
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ranges": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}

View File

@@ -21,6 +21,7 @@ target_link_libraries(
Fall-Fever PRIVATE
glfw
glad
GL
)
target_compile_options(Fall-Fever PRIVATE -Wall -Wextra -pedantic)

View File

@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <iostream>
#include <glad/glad.h>
#ifdef __linux__
#include <unistd.h>
@@ -30,22 +31,88 @@ Controller::~Controller() {
}
void Controller::run() {
bool running = 1;
while(running) {
glClearColor(0.241f, 0.578f, 0.308f, 1.0f);
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if(!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
unsigned int fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if(!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}
unsigned int shaderProgram;
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
float vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// This is the game loop
while(!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
// Timing
limit_framerate();
std::cout << 1/deltaTime << std::endl;
std::cout << "FPS: " << 1/deltaTime << std::endl;
// Update game
// Render and buffer swap
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(gameWindow->getGLFWwindow());
// Check events, handle input
gameEventHandler->handleEvents(gameWindow->getGLFWwindow());
if(gameEventHandler->gameShouldTerminate) running = 0;
}
}
void Controller::error_callback(int error, const char* description) {

View File

@@ -24,6 +24,19 @@ private:
const uint16_t MAX_FPS = 60;
double deltaTime;
double deltaTime;
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main() {\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main() {\n"
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\0";
};

View File

@@ -2,7 +2,6 @@
void EventHandler::handleEvents(GLFWwindow *window) {
glfwPollEvents();
gameShouldTerminate = glfwWindowShouldClose(window);
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);

View File

@@ -7,7 +7,6 @@ class EventHandler {
public:
void handleEvents(GLFWwindow *window);
bool gameShouldTerminate;
private:

View File

@@ -14,6 +14,7 @@ Window::Window() {
// Create OpenGL context
glfwMakeContextCurrent(window);
// Initialize GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
exit(-1);
@@ -21,6 +22,7 @@ Window::Window() {
glViewport(0, 0, width, height);
// Tell GLFW which function to call when window is resized
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
}
@@ -29,6 +31,7 @@ Window::~Window() {
glfwDestroyWindow(window);
}
// This function is called when the window gets resized
void Window::framebuffer_size_callback(GLFWwindow* window, int width, int height) {
(void)window;
glViewport(0, 0, width, height);