From a8b366277a465bf4681cfdd5f8f33546d6985ec2 Mon Sep 17 00:00:00 2001 From: Joseph Roy Date: Mon, 15 Apr 2024 23:26:53 +0100 Subject: [PATCH] first commit --- .gitignore | 1 + .vscode/settings.json | 48 +++++++++++++++++++++++++++++++ Makefile | 19 +++++++++++++ main.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7ce682d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,48 @@ +{ + "makefile.launchConfigurations": [ + { + "cwd": "/home/joseph/Source/OpenGL", + "binaryPath": "/home/joseph/Source/OpenGL/OpenGLTest", + "binaryArgs": [] + }, + { + "cwd": "/home/joseph/Source/OpenGL", + "binaryPath": "/home/joseph/Source/OpenGL/OpenGLTest.out", + "binaryArgs": [] + } + ], + "files.associations": { + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp" + }, + "editor.insertSpaces": false +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b4c482 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +CXX = g++ +CFLAGS = -std=c++17 +LDFLAGS = -lglfw -lGLEW -lGL + +TARGET = bin/OpenGLTest + +$(TARGET): main.cpp | bin + $(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) + +.PHONY: test clean + +test: $(TARGET) + ./$(TARGET) + +clean: + rm -f $(TARGET) + +bin: + mkdir -p bin diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d2de8d7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,66 @@ +#include // Include the OpenGL ES header +#include + +#define GLM_FORCE_RADIANS +#define GLM_FORCE_DEPTH_ZERO_TO_ONE + +#include +#include + +#include + +void framebuffer_size_callback(GLFWwindow* window, int width, int height); + +int main() +{ + if (!glfwInit()) + { + std::cerr << "Failed to initialize GLFW." << std::endl; + return -1; + } + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); +#ifdef __APPLE__ + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif + + GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL window", nullptr, nullptr); + if (window == NULL) + { + const char* description; + int errorCode = glfwGetError(&description); + std::cout << "Failed to create GLFW window. Error code: " << errorCode << ", Description: " << description << std::endl; + glfwTerminate(); + return -1; + } + + glfwMakeContextCurrent(window); + + glViewport(0, 0, 800, 600); + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + glm::mat4 matrix; + glm::vec4 vec; + + auto test = vec * matrix; + + while (!glfwWindowShouldClose(window)) + { + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glfwPollEvents(); + glfwSwapBuffers(window); + } + + glfwDestroyWindow(window); + glfwTerminate(); + + return 0; +} + +void framebuffer_size_callback(GLFWwindow* window, int width, int height) +{ + glViewport(0, 0, width, height); +}