diff --git a/.clang-tidy b/.clang-tidy index e0299ea..c07c97a 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,14 +3,4 @@ Checks: 'portability-*,performance-*,readability-*,cppcoreguidelines-*, HeaderFilterRegex: '.*' AnalyzeTemporaryDtors: false FormatStyle: none -CheckOptions: - - { key: readability-identifier-naming.NamespaceCase, value: camelBack } - - { key: readability-identifier-naming.ClassCase, value: CamelCase } - - { key: readability-identifier-naming.PrivateMemberPrefix, value: m } - - { key: readability-identifier-naming.PrivateMemberCase, value: CamelCase } - - { key: readability-identifier-naming.StructCase, value: CamelCase } - - { key: readability-identifier-naming.FunctionCase, value: camelBack } - - { key: readability-identifier-naming.VariableCase, value: camelBack } - - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } - - { key: readability-identifier-naming.LocalConstantCase, value: CamelBack } ... diff --git a/CMakeLists.txt b/CMakeLists.txt index 30f0ee3..6681ecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,4 +20,3 @@ endif() add_subdirectory(window) add_subdirectory(opengl) add_subdirectory(shaders) - diff --git a/cmake/FindAssimp.cmake b/cmake/FindAssimp.cmake deleted file mode 100644 index 56b13d7..0000000 --- a/cmake/FindAssimp.cmake +++ /dev/null @@ -1,39 +0,0 @@ -find_path( - Assimp_INCLUDE_DIR - NAMES assimp/scene.h - PATHS /usr/include/ - /usr/local/include/ -) - -find_library( - Assimp_LIBRARY - NAMES assimp - PATHS /usr/lib/ - /usr/local/lib/ -) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - Assimp DEFAULT_MSG Assimp_INCLUDE_DIR Assimp_LIBRARY -) - -# TODO(Hussein): Check static or shared -add_library( - Assimp::Assimp - SHARED - IMPORTED - GLOBAL -) - -target_include_directories( - Assimp::Assimp - INTERFACE - ${Assimp_INCLUDE_DIR} -) - -target_link_libraries( - Assimp::Assimp - INTERFACE - ${Assimp_LIBRARY} -) - diff --git a/cmake/Findgl3w.cmake b/cmake/Findgl3w.cmake deleted file mode 100644 index 066c691..0000000 --- a/cmake/Findgl3w.cmake +++ /dev/null @@ -1,42 +0,0 @@ -# ${CMAKE_SOURCE_DIR}/cmake/Findgl3w.cmake -if(TARGET gl3w::gl3w) - return() -endif() - -enable_language(C) - -set(GL3W_DIR ${CMAKE_SOURCE_DIR}/thirdparty/gl3w) - -add_library( - gl3w - STATIC -) - -add_library( - gl3w::gl3w - ALIAS - gl3w -) - -target_sources( - gl3w - PRIVATE - ${GL3W_DIR}/src/gl3w.c -) - -target_include_directories( - gl3w - SYSTEM PUBLIC - ${GL3W_DIR}/include/ -) - -target_link_libraries( - gl3w - PRIVATE - $<$:${CMAKE_DL_LIBS}> -) - -# TODO(Hussein): Additional modules -#include(FindPackageHandleStandardArgs) -# Handle REQUIRD argument, define *_FOUND variable -#find_package_handle_standard_args(gl3w DEFAULT_MSG gl3w) diff --git a/opengl/CMakeLists.txt b/opengl/CMakeLists.txt index af831da..1ab5fd1 100644 --- a/opengl/CMakeLists.txt +++ b/opengl/CMakeLists.txt @@ -1,8 +1,8 @@ # ${CMAKE_SOURCE_DIR}/window/CMakeLists.txt -find_package(SDL2 REQUIRED) +find_package(SDL2 REQUIRED) set(OpenGL_GL_PREFERENCE "GLVND") -find_package(OpenGL REQUIRED) -find_package(gl3w REQUIRED) +find_package(OpenGL REQUIRED) +find_package(glbinding REQUIRED) if(UNIX AND ENABLE_X11) find_package(X11 REQUIRED) @@ -51,7 +51,7 @@ set( demos fixedPipelineOpenGLSDL programmablePipelineOpenGLSDL - programmablePipelineGl3wSDL + programmablePipelineGlBindingSDL programmablePipelineSDL2EGL ) @@ -65,7 +65,7 @@ foreach(demo IN LISTS demos) ${demo} PRIVATE OpenGL::GL - gl3w::gl3w + glbinding::glbinding SDL2::SDL2 SDL2::SDL2main options::options diff --git a/opengl/programmablePipelineGl3wSDL.cpp b/opengl/programmablePipelineGl3wSDL.cpp deleted file mode 100644 index 1f8a4f7..0000000 --- a/opengl/programmablePipelineGl3wSDL.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// 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 -// GL3W -#include -// SDL -#include -#include - -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 << source << " : " << 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); - - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } - - // 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; -} diff --git a/opengl/shaders/CMakeLists.txt b/opengl/shaders/CMakeLists.txt index 62dc4a7..2ddcfe5 100644 --- a/opengl/shaders/CMakeLists.txt +++ b/opengl/shaders/CMakeLists.txt @@ -36,7 +36,7 @@ foreach(sample IN LISTS samples) SDL2::SDL2 SDL2::SDL2main options::options - gl3w::gl3w + glbinding::glbinding glm::glm ) diff --git a/opengl/shaders/controlTriangleColorWithMousePosition.cpp b/opengl/shaders/controlTriangleColorWithMousePosition.cpp index 98af448..a932eb6 100644 --- a/opengl/shaders/controlTriangleColorWithMousePosition.cpp +++ b/opengl/shaders/controlTriangleColorWithMousePosition.cpp @@ -11,11 +11,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -35,7 +37,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -49,7 +51,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -73,7 +75,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -138,10 +140,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawCube.cpp b/opengl/shaders/drawCube.cpp index e3daeab..bea7e42 100644 --- a/opengl/shaders/drawCube.cpp +++ b/opengl/shaders/drawCube.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; [[maybe_unused]] static constexpr auto GL3D_SUCCESS = 0; @@ -39,7 +41,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -53,7 +55,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -77,7 +79,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -142,10 +144,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(SDL_SWAP_SYNCHRONIZED); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawCubeWithPerspective.cpp b/opengl/shaders/drawCubeWithPerspective.cpp index 222cf3d..44533b5 100644 --- a/opengl/shaders/drawCubeWithPerspective.cpp +++ b/opengl/shaders/drawCubeWithPerspective.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; [[maybe_unused]] static constexpr auto GL3D_SUCCESS = 0; @@ -39,7 +41,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -53,7 +55,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -77,7 +79,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -142,10 +144,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(SDL_SWAP_SYNCHRONIZED); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawCubeWithPerspectiveUBO.cpp b/opengl/shaders/drawCubeWithPerspectiveUBO.cpp index 344ae84..53f4366 100644 --- a/opengl/shaders/drawCubeWithPerspectiveUBO.cpp +++ b/opengl/shaders/drawCubeWithPerspectiveUBO.cpp @@ -11,11 +11,13 @@ // GLM #include #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; [[maybe_unused]] static constexpr auto GL3D_SUCCESS = 0; @@ -40,7 +42,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -54,7 +56,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -78,7 +80,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -143,10 +145,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(SDL_SWAP_SYNCHRONIZED); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawRedPointPipeline.cpp b/opengl/shaders/drawRedPointPipeline.cpp index b216ff6..ba03f74 100644 --- a/opengl/shaders/drawRedPointPipeline.cpp +++ b/opengl/shaders/drawRedPointPipeline.cpp @@ -10,12 +10,15 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include #include +using namespace gl; + static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); static constexpr auto GL_PROGRAM_FAILURE = std::numeric_limits::max(); @@ -34,7 +37,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +51,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +75,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +140,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawRedPointShader.cpp b/opengl/shaders/drawRedPointShader.cpp index b216ff6..2a15744 100644 --- a/opengl/shaders/drawRedPointShader.cpp +++ b/opengl/shaders/drawRedPointShader.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawRedTriangleShader.cpp b/opengl/shaders/drawRedTriangleShader.cpp index c420955..0c582e0 100644 --- a/opengl/shaders/drawRedTriangleShader.cpp +++ b/opengl/shaders/drawRedTriangleShader.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawTrianglePositionAndColorUsingAttributes.cpp b/opengl/shaders/drawTrianglePositionAndColorUsingAttributes.cpp index 5291c0b..7852ce5 100644 --- a/opengl/shaders/drawTrianglePositionAndColorUsingAttributes.cpp +++ b/opengl/shaders/drawTrianglePositionAndColorUsingAttributes.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSA.cpp b/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSA.cpp index 2a74566..f205677 100644 --- a/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSA.cpp +++ b/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSA.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { @@ -209,8 +208,8 @@ auto main(int argc, char *argv[]) -> int { GLuint vbos[2]; glCreateBuffers(2, vbos); - glNamedBufferStorage(vbos[positionAttribute], vertices.size() * sizeof(float), vertices.data(), 0); - glNamedBufferStorage(vbos[colorAttribute], colors.size() * sizeof(float), colors.data(), 0); + glNamedBufferStorage(vbos[positionAttribute], vertices.size() * sizeof(float), vertices.data(), GL_NONE_BIT); + glNamedBufferStorage(vbos[colorAttribute], colors.size() * sizeof(float), colors.data(), GL_NONE_BIT); // ============================ // Must create one VAO at lest. diff --git a/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSAOneVBO.cpp b/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSAOneVBO.cpp index 7559dda..5fde94a 100644 --- a/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSAOneVBO.cpp +++ b/opengl/shaders/drawTrianglePositionAndColorUsingAttributesDSAOneVBO.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { @@ -202,7 +201,7 @@ auto main(int argc, char *argv[]) -> int { GLuint vbo; glCreateBuffers(1, &vbo); - glNamedBufferStorage(vbo, vertices.size() * sizeof(float), vertices.data(), 0); + glNamedBufferStorage(vbo, vertices.size() * sizeof(float), vertices.data(), GL_NONE_BIT); // ============================ // Must create one VAO at lest. diff --git a/opengl/shaders/drawTriangleUsingAttributes.cpp b/opengl/shaders/drawTriangleUsingAttributes.cpp index 4ada4b3..45ee4cd 100644 --- a/opengl/shaders/drawTriangleUsingAttributes.cpp +++ b/opengl/shaders/drawTriangleUsingAttributes.cpp @@ -10,11 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include + +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto GL_SHADER_FAILURE = std::numeric_limits::max(); @@ -34,7 +36,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -48,7 +50,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -72,7 +74,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -137,10 +139,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(1); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/opengl/shaders/drawTriangleUsingAttributesDSA.cpp b/opengl/shaders/drawTriangleUsingAttributesDSA.cpp index 347ae27..6d157ff 100644 --- a/opengl/shaders/drawTriangleUsingAttributesDSA.cpp +++ b/opengl/shaders/drawTriangleUsingAttributesDSA.cpp @@ -10,12 +10,13 @@ #include // GLM #include -// GL3W -#include +// glbinding +#include +#include // SDL #include -#include +using namespace gl; static constexpr auto GL3D_SUCCESS = 0; static constexpr auto SDL_SUCCESS = 0; @@ -40,7 +41,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static auto parseProgramOptions(int argc, char **argv) -> std::optional> { @@ -54,7 +55,7 @@ static auto parseProgramOptions(int argc, char **argv) -> std::optional bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -78,7 +79,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -143,10 +144,7 @@ auto main(int argc, char *argv[]) -> int { // Enable vsync SDL_GL_SetSwapInterval(SDL::Synchronized); - if(gl3wInit() != GL3D_SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { @@ -199,7 +197,7 @@ auto main(int argc, char *argv[]) -> int { GLuint vbo; glCreateBuffers(1, &vbo); - glNamedBufferStorage(vbo, vertices.size() * sizeof(float), vertices.data(), 0); + glNamedBufferStorage(vbo, vertices.size() * sizeof(float), vertices.data(), GL_NONE_BIT); // ============================ // Must create one VAO at lest. diff --git a/shaders/CMakeLists.txt b/shaders/CMakeLists.txt index b9b7c5e..8346acc 100644 --- a/shaders/CMakeLists.txt +++ b/shaders/CMakeLists.txt @@ -1,8 +1,7 @@ # ${CMAKE_SOURCE_DIR}/shaders/CMakeLists.txt -find_package(SDL2 REQUIRED) -find_package(gl3w REQUIRED) -#find_package(Assimp REQUIRED) -find_package(assimp REQUIRED) +find_package(SDL2 REQUIRED) +find_package(glbinding REQUIRED) +find_package(assimp REQUIRED) add_subdirectory(materials) add_subdirectory(lights) diff --git a/shaders/lights/CMakeLists.txt b/shaders/lights/CMakeLists.txt index e7df058..6d6a5a3 100644 --- a/shaders/lights/CMakeLists.txt +++ b/shaders/lights/CMakeLists.txt @@ -21,7 +21,7 @@ foreach(light IN LISTS lights) SDL2::SDL2main options::options assimp::assimp - gl3w::gl3w + glbinding::glbinding ) endforeach() diff --git a/shaders/lights/ambient.cpp b/shaders/lights/ambient.cpp index b25039c..9ae1d01 100644 --- a/shaders/lights/ambient.cpp +++ b/shaders/lights/ambient.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -18,6 +18,8 @@ #include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -37,7 +39,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -156,7 +158,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -180,7 +182,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -290,10 +292,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/CMakeLists.txt b/shaders/materials/CMakeLists.txt index 0a6ad25..7bbdcbf 100644 --- a/shaders/materials/CMakeLists.txt +++ b/shaders/materials/CMakeLists.txt @@ -22,7 +22,7 @@ foreach(material IN LISTS meterials) SDL2::SDL2main options::options assimp::assimp - gl3w::gl3w + glbinding::glbinding ) endforeach() diff --git a/shaders/materials/ambientPerFragment.cpp b/shaders/materials/ambientPerFragment.cpp index fbbcdc8..b6235ee 100644 --- a/shaders/materials/ambientPerFragment.cpp +++ b/shaders/materials/ambientPerFragment.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -19,6 +19,8 @@ //#include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -38,7 +40,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -163,7 +165,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -187,7 +189,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -297,10 +299,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/diffuse.cpp b/shaders/materials/diffuse.cpp index 003b2dc..ec2af75 100644 --- a/shaders/materials/diffuse.cpp +++ b/shaders/materials/diffuse.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -19,6 +19,8 @@ //#include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -38,7 +40,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -181,7 +183,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -205,7 +207,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -315,10 +317,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/diffusePerFragment.cpp b/shaders/materials/diffusePerFragment.cpp index 2ce806a..9ea5aa6 100644 --- a/shaders/materials/diffusePerFragment.cpp +++ b/shaders/materials/diffusePerFragment.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -19,6 +19,8 @@ //#include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -38,7 +40,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -183,7 +185,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -207,7 +209,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -317,10 +319,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/diffusePerFragmentUBO.cpp b/shaders/materials/diffusePerFragmentUBO.cpp index 7a1b3c8..49efb9b 100644 --- a/shaders/materials/diffusePerFragmentUBO.cpp +++ b/shaders/materials/diffusePerFragmentUBO.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -19,6 +19,8 @@ //#include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -38,7 +40,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -183,7 +185,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -207,7 +209,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -319,10 +321,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/loadObj.cpp b/shaders/materials/loadObj.cpp index 91d153a..a7beb25 100644 --- a/shaders/materials/loadObj.cpp +++ b/shaders/materials/loadObj.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -18,6 +18,8 @@ #include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -37,7 +39,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -130,7 +132,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -154,7 +156,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -264,10 +266,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/materials/specular.cpp b/shaders/materials/specular.cpp index 02b3398..ad4312a 100644 --- a/shaders/materials/specular.cpp +++ b/shaders/materials/specular.cpp @@ -4,11 +4,11 @@ #include #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include -#include // GLM #include #include @@ -19,6 +19,8 @@ //#include #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class ShaderResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; enum class ProgramResult : std::uint32_t { FAILURE = std::numeric_limits::max() }; @@ -38,7 +40,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity return; } - std::cout << source << " : " << message << '\n'; + std::cout << message << '\n'; } static const char *vertexShaderSource = R"GLSL( @@ -196,7 +198,7 @@ static auto LoadFile(const std::string &fileName) -> Scene { static auto checkShaderCompilation(GLuint shader) -> bool { GLint compiled; glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); - if(compiled != GL_TRUE) { + if(compiled != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetShaderInfoLog(shader, 1024, &log_length, message); @@ -220,7 +222,7 @@ static auto createShader(GLenum shaderType, const char *shaderSource) -> GLuint static auto checkProgramLinkage(GLuint program) -> bool { GLint program_linked; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if(program_linked != GL_TRUE) { + if(program_linked != 1) { GLsizei log_length = 0; GLchar message[1024]; glGetProgramInfoLog(program, 1024, &log_length, message); @@ -330,10 +332,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(gl3wInit() != GL3D::SUCCESS) { - std::cerr << "Can not initialize GL3W!\n"; - return EXIT_FAILURE; - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback if(glDebugMessageCallback) { diff --git a/shaders/triangle/CMakeLists.txt b/shaders/triangle/CMakeLists.txt index 7f8ba56..f362434 100644 --- a/shaders/triangle/CMakeLists.txt +++ b/shaders/triangle/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(fmt REQUIRED) set(demos triangle450 - triangle450UseUinform +# triangle450UseUinform ) foreach(demo IN LISTS demos) @@ -17,7 +17,7 @@ foreach(demo IN LISTS demos) SDL2::SDL2 SDL2::SDL2main options::options - gl3w::gl3w + glbinding::glbinding fmt::fmt-header-only ) endforeach() diff --git a/shaders/triangle/shaders/simple_vertex.glsl b/shaders/triangle/shaders/simple_vertex.glsl index 9a4c44a..a711cb6 100644 --- a/shaders/triangle/shaders/simple_vertex.glsl +++ b/shaders/triangle/shaders/simple_vertex.glsl @@ -1,7 +1,7 @@ #version 450 core const vec4 cPositions[3] = { - vec4( 0.25, -0.25, 0.5, 1.0), + vec4( 0.25, 0, 0.5, 1.0), vec4(-0.25, -0.25, 0.5, 1.0), vec4( 0.25, 0.25, 0.5, 1.0) }; diff --git a/shaders/triangle/triangle450.cpp b/shaders/triangle/triangle450.cpp index a433f18..ff55004 100644 --- a/shaders/triangle/triangle450.cpp +++ b/shaders/triangle/triangle450.cpp @@ -8,16 +8,23 @@ // FMT #include #include -// GL3W -#include +// glbinding +#include +#include // SDL2 #include +using namespace gl; + enum GL3D { SUCCESS = 0 }; enum class SDL_GL : int { ADAPTIVE_VSYNC = -1, IMMEDIATE = 0, SYNCHRONIZED = 1 }; constexpr auto gTitle = "Scene"; constexpr auto gWidth = 640U; constexpr auto gHeight = 480U; +constexpr auto gMessageLength = 1024U; +constexpr auto gMajorVersion = 4; +constexpr auto gMinorVersion = 5; +inline const bool gDebugOpenGL = std::getenv("DEBUG_OPENGL") != nullptr; constexpr auto SDL_SUCCESS = 0; inline auto readTextFile(const std::string& fileName) -> std::string { @@ -47,7 +54,7 @@ static void DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity // return; //} - fmt::print(fg(fmt::color::red), "Error: {0} - {1}\n", source, message); + fmt::print(fg(fmt::color::red), "Error: {0} - {1}\n", static_cast(source), message); } class Engine final { @@ -58,13 +65,13 @@ class Engine final { } // Enable Debug OpenGL - int contextFlags; + int contextFlags = 0; SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &contextFlags); contextFlags |= SDL_GL_CONTEXT_DEBUG_FLAG; // OpenGL 4.5 Core Profile SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gMajorVersion); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gMinorVersion); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); m_pWindow = SDL_CreateWindow(gTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, gWidth, gHeight, SDL_WINDOW_OPENGL); @@ -77,12 +84,10 @@ class Engine final { throw std::runtime_error(fmt::format("Can not create context \"{}\"", SDL_GetError())); } - if(gl3wInit() != GL3D::SUCCESS) { - throw std::runtime_error("Can not initialize GL3W!"); - } + glbinding::initialize(nullptr, false); // Set OpenGL Debug Callback - if(glDebugMessageCallback) { + if(gDebugOpenGL) { std::cout << "Debug is enabled\n"; glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(DebugCallback, nullptr); @@ -96,7 +101,7 @@ class Engine final { static GLuint CreateProgramFromShader(const std::string& shaderName, GLenum shaderType) { const auto shaderSource = readTextFile(shaderName); - const auto pShaderSource = shaderSource.data(); + const auto *pShaderSource = shaderSource.data(); GLuint shader = glCreateShader(shaderType); glShaderSource(shader, 1, &pShaderSource, nullptr); GLuint program = glCreateProgram(); @@ -105,13 +110,13 @@ class Engine final { glLinkProgram(program); glDeleteShader(shader); - GLint program_linked; + GLint program_linked = 0; glGetProgramiv(program, GL_LINK_STATUS, &program_linked); - if (program_linked != GL_TRUE) { + if (program_linked != 1) { GLsizei log_length = 0; - GLchar message[1024]; - glGetProgramInfoLog(program, 1024, &log_length, message); - throw std::runtime_error(message); + std::array message{}; + glGetProgramInfoLog(program, gMessageLength, &log_length, message.data()); + throw std::runtime_error(message.data()); } return program; } @@ -131,11 +136,11 @@ class Engine final { glBindVertexArray(mVAO); } - void draw() { + void draw() const { bool bRunning = true; while(bRunning) { SDL_Event event; - while(SDL_PollEvent(&event)) { + while(SDL_PollEvent(&event) != 0) { if(event.type == SDL_QUIT) { bRunning = false; } @@ -157,13 +162,14 @@ class Engine final { } SDL_Window *m_pWindow = nullptr; - SDL_GLContext mContext; - GLuint vsProgram, fsProgram; + SDL_GLContext mContext = nullptr; + GLuint vsProgram= 0; + GLuint fsProgram = 0; GLuint mVAO = 0; GLuint mProgram = 0; }; -int main(int argc, char *argv[]) { +int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) { try { Engine engine; engine.initialize(); diff --git a/window/CMakeLists.txt b/window/CMakeLists.txt index 3eed7c0..fe92bdd 100644 --- a/window/CMakeLists.txt +++ b/window/CMakeLists.txt @@ -90,4 +90,3 @@ if(WIN32 AND ENABLE_WIN32) options::options ) endif() -