From daa124c19de7ddd5c8f5b547e309163468d10f03 Mon Sep 17 00:00:00 2001 From: Ahmed Hussein Date: Mon, 28 Feb 2022 21:19:45 +0200 Subject: [PATCH 1/3] Create build.yml --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..da828fe --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: CMake Build Matrix + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: submodule + run: git submodule update --init + - name: install dependencies + run: sudo apt-get update && \ + sudo apt-get install -yq \ + build-essential \ + cmake \ + ninja-build \ + libglbinding-dev \ + libglm-dev \ + libfmt-dev \ + libassimp-dev \ + libsdl2-dev + - name: create build dir + run: mkdir build + - name: cmake configuration + run: cmake -G Ninja -Bbuild -H. + - name: build + run: cd build && ninja From 5a72802ec687d6ea3700080a443931cb0d994dba Mon Sep 17 00:00:00 2001 From: Ahmed Hussein Date: Mon, 28 Feb 2022 21:24:15 +0200 Subject: [PATCH 2/3] Update build.yml --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da828fe..c86258c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,8 @@ jobs: - name: submodule run: git submodule update --init - name: install dependencies - run: sudo apt-get update && \ + run: | + sudo apt-get update sudo apt-get install -yq \ build-essential \ cmake \ From 27388b1709528c65def2ce50badb431c35cc07f0 Mon Sep 17 00:00:00 2001 From: Ahmed Abdel Aal Date: Mon, 28 Feb 2022 19:26:25 +0200 Subject: [PATCH 3/3] Add missing file --- opengl/programmablePipelineGlBindingSDL.cpp | 123 ++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 opengl/programmablePipelineGlBindingSDL.cpp diff --git a/opengl/programmablePipelineGlBindingSDL.cpp b/opengl/programmablePipelineGlBindingSDL.cpp new file mode 100644 index 0000000..2cd1368 --- /dev/null +++ b/opengl/programmablePipelineGlBindingSDL.cpp @@ -0,0 +1,123 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check it. +// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +// STL +#include +#include +#include +#include +#include +#include +#include +// glbinding +#include +#include +// SDL +#include + +using namespace gl; + +static constexpr auto GL3D_SUCCESS = 0; + +static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *pUserParam) { + (void)type; + (void)id; + (void)severity; + (void)length; + (void)pUserParam; + constexpr std::array ignoreWarrings = {33350}; + + if(std::any_of(std::cbegin(ignoreWarrings), std::cend(ignoreWarrings), [source](auto current) -> bool { + return static_cast(source) == current; + })) { + return; + } + + std::cout << message << '\n'; +} + +static auto parseProgramOptions(int argc, char** argv) + -> std::optional> { + if(argc != 3) { + return std::nullopt; + } + + return std::make_pair( + std::stoi(argv[1]), + std::stoi(argv[2]) + ); +} + +auto main(int argc, char *argv[]) -> int { + if(SDL_Init(SDL_INIT_VIDEO) != 0) { + std::cerr << "Can not initialize SDL2\n"; + return EXIT_FAILURE; + } + + int width = 640; + int height = 480; + if(const auto args = parseProgramOptions(argc, argv); + args) { + constexpr auto firstScreenIndex = 0; + SDL_DisplayMode displayMode; + SDL_GetCurrentDisplayMode(firstScreenIndex, &displayMode); + + width = std::min(args.value().first, displayMode.w); + height = std::min(args.value().second, displayMode.h); + } + + constexpr std::string_view sWindowTitle = "HelloWorld!"; + auto pWindow = SDL_CreateWindow(sWindowTitle.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL); + if(pWindow == nullptr) { + std::cerr << "Can not create SDL2 window\n"; + return EXIT_FAILURE; + } + + // Enable Debug OpenGL + int contextFlags; + SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &contextFlags); + contextFlags |= SDL_GL_CONTEXT_DEBUG_FLAG; + // OpenGL 3.3 Core Profile + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags); + SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); + + // Create OpenGL Context + SDL_GLContext context = SDL_GL_CreateContext(pWindow); + if(context == nullptr) { + std::cerr << "Can not create SDL2 context\n"; + return EXIT_FAILURE; + } + // Enable vsync + SDL_GL_SetSwapInterval(1); + + glbinding::initialize(nullptr, false); + + // Set OpenGL Debug Callback + if(glDebugMessageCallback) { + std::cout << "Debug is enabled\n"; + glDebugMessageCallback(DebugCallback, nullptr); + } + + constexpr std::array clearColor = {0.F, 0.F, 0.F, 1.F}; + auto bRunning = true; + while(bRunning) { + SDL_Event event; + while(SDL_PollEvent(&event) > 0) { + switch(event.type) { + case SDL_QUIT: bRunning = false; break; + } + } + + glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); + + glClear(GL_COLOR_BUFFER_BIT); + SDL_GL_SwapWindow(pWindow); + } + + SDL_GL_DeleteContext(context); + SDL_DestroyWindow(pWindow); + SDL_Quit(); + + return EXIT_SUCCESS; +}