diff --git a/Module1/CMakeLists.txt b/Module1/CMakeLists.txt index 6e32c5a..8e3d6d5 100644 --- a/Module1/CMakeLists.txt +++ b/Module1/CMakeLists.txt @@ -6,6 +6,9 @@ find_package(GLEW REQUIRED) find_package(GLM REQUIRED) find_package(SOIL REQUIRED) +find_package(Stb REQUIRED) +find_package(glbinding CONFIG REQUIRED) + add_subdirectory(Common) add_subdirectory(Chapter01) add_subdirectory(Chapter02) diff --git a/Module1/Chapter01/GettingStarted/CMakeLists.txt b/Module1/Chapter01/GettingStarted/CMakeLists.txt index 9b7f8ac..c5d226f 100644 --- a/Module1/Chapter01/GettingStarted/CMakeLists.txt +++ b/Module1/Chapter01/GettingStarted/CMakeLists.txt @@ -1,13 +1,10 @@ -add_executable( - GettingStarted - main.cpp -) +# ${CMAKE_SOURCE_DIR}/Module1/Chapter01/GettingStarted/CMakeLists.txt +add_executable(GettingStarted main.cpp) target_link_libraries( GettingStarted - PUBLIC - OpenGL::GL - GLUT::GLUT - GLEW::GLEW - options::options -) \ No newline at end of file + PUBLIC fmt::fmt + OpenGL::GL + glfw + glbinding::glbinding + options::options) diff --git a/Module1/Chapter01/GettingStarted/main.cpp b/Module1/Chapter01/GettingStarted/main.cpp index 87375e2..a1cd2d5 100644 --- a/Module1/Chapter01/GettingStarted/main.cpp +++ b/Module1/Chapter01/GettingStarted/main.cpp @@ -1,76 +1,86 @@ // 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 -#include +#include +#include -#include -#include +#include +#include -using namespace std; +#include +#include +#define GLFW_INCLUDE_NONE -// screen size -const int WIDTH = 1280; -const int HEIGHT = 960; +#include -// OpenGL initialization -void OnInit() { - // set clear color to red - glClearColor(1, 0, 0, 0); - cout << "Initialization successfull" << endl; -} - -// release all allocated resources -void OnShutdown() { cout << "Shutdown successfull" << endl; } - -// handle resize event -void OnResize(int /*nw*/, int /*nh*/) {} - -// display callback function -void OnRender() { - // clear colour and depth buffers - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // swap front and back buffers to show the rendered result - glutSwapBuffers(); -} - -int main(int argc, char **argv) { - // freeglut initialization calls - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); - glutInitContextVersion(3, 3); - glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG); - glutInitContextProfile(GLUT_FORWARD_COMPATIBLE); - glutInitWindowSize(WIDTH, HEIGHT); - glutCreateWindow("Getting started with OpenGL 3.3"); - - // glew initialization - glewExperimental = GL_TRUE; - GLenum err = glewInit(); - if (GLEW_OK != err) { - cerr << "Error: " << glewGetErrorString(err) << endl; - } else { - if (GLEW_VERSION_3_3) { - cout << "Driver supports OpenGL 3.3\nDetails:" << endl; - } +using namespace gl; + +namespace { +constexpr uint32_t WIDTH = 1280; +constexpr uint32_t HEIGHT = 960; +} // namespace + +int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { + glfwSetErrorCallback([](int errorCode, const char* message) { + fmt::print(stderr, fg(fmt::color::red), "GLFW ERROR({}): {}\n", errorCode, message); + }); + + // glfw initialization + if(GLFW_FALSE == glfwInit()) { + return EXIT_FAILURE; } - // print information on screen - cout << "\tUsing GLEW " << glewGetString(GLEW_VERSION) << endl; - cout << "\tVendor: " << glGetString(GL_VENDOR) << endl; - cout << "\tRenderer: " << glGetString(GL_RENDERER) << endl; - cout << "\tVersion: " << glGetString(GL_VERSION) << endl; - cout << "\tGLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl; + glfwWindowHint(GLFW_RED_BITS, 8); + glfwWindowHint(GLFW_GREEN_BITS, 8); + glfwWindowHint(GLFW_BLUE_BITS, 8); + glfwWindowHint(GLFW_DEPTH_BITS, 16); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); - // initialization of OpenGL - OnInit(); + glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); - // callback hooks - glutCloseFunc(OnShutdown); - glutDisplayFunc(OnRender); - glutReshapeFunc(OnResize); + auto* window = glfwCreateWindow(WIDTH, HEIGHT, "Getting started with OpenGL 3.3", nullptr, nullptr); + if(nullptr == window) { + glfwTerminate(); + return EXIT_FAILURE; + } + glfwMakeContextCurrent(window); + + glbinding::initialize(glfwGetProcAddress); + + { + int major = 0; + int minor = 0; + int rev = 0; + glfwGetVersion(&major, &minor, &rev); + fmt::print("\tUsing GLEW {}.{}.{}\n", major, minor, rev); + } + fmt::print("\tVendor: {}\n", reinterpret_cast(glGetString(GL_VENDOR))); + fmt::print("\tRenderer: {}\n", reinterpret_cast(glGetString(GL_RENDERER))); + fmt::print("\tVersion: {}\n", reinterpret_cast(glGetString(GL_VERSION))); + fmt::print("\tGLSL: {}\n", reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION))); + + glDebugMessageCallbackARB( + [](GLenum, GLenum, GLuint, GLenum severity, GLsizei, const char* message, const void*) { + if(severity == GL_DEBUG_SEVERITY_HIGH_ARB) { + fmt::print(stderr, fg(fmt::color::red), "OpenGL ERROR: {}\n", message); + } + }, + nullptr); + + glClearColor(1, 0, 0, 0); + fmt::print("Initialization successfull\n"); + + while(!glfwWindowShouldClose(window)) { + glfwPollEvents(); + + glClear(GL_COLOR_BUFFER_BIT); + + glfwSwapBuffers(window); + } - // main loop call - glutMainLoop(); + fmt::print("Shutdown successfull\n"); - return 0; -} + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 705f659..c7494d3 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,16 +1,19 @@ { "dependencies": [ + "fmt", "freeglut", + "glbinding", "glew", "glm", - "soil", { "name": "imgui", "default-features": false, "features": [ - "opengl3-binding", - "glfw-binding" + "glfw-binding", + "opengl3-binding" ] - } + }, + "soil", + "stb" ] }