Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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
123 changes: 123 additions & 0 deletions opengl/programmablePipelineGlBindingSDL.cpp
Original file line number Diff line number Diff line change
@@ -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 <array>
#include <string>
#include <cstdlib>
#include <optional>
#include <iostream>
#include <algorithm>
#include <string_view>
// glbinding
#include <glbinding/gl/gl.h>
#include <glbinding/glbinding.h>
// SDL
#include <SDL2/SDL.h>

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<int>(source) == current;
})) {
return;
}

std::cout << message << '\n';
}

static auto parseProgramOptions(int argc, char** argv)
-> std::optional<std::pair<int, int>> {
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<float, 4> 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;
}