void renderFB() { glm::vec2 WindowSize(this->getWindowSize()); glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y); glClearNamedFramebufferfv(0, GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], this->UniformBlockSize, this->UniformBlockSize); glBindTextureUnit(0, TextureName[texture::COLORBUFFER]); glBindVertexArray(VertexArrayName); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0, 0); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, WindowSize.x * 0.5f, WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); glBindProgramPipeline(PipelineName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName); glBindVertexArray(VertexArrayName); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); glViewportIndexedf(0, 0, 0, WindowSize.x * 0.5f, WindowSize.y); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE); glViewportIndexedf(0, WindowSize.x * 0.5f, 0, WindowSize.x * 0.5f, WindowSize.y); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); return true; }
void renderFBO() { glEnable(GL_MULTISAMPLE); glEnable(GL_SAMPLE_SHADING); glMinSampleShading(4.0f); glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); glViewportIndexedf(0, 0, 0, static_cast<float>(FRAMEBUFFER_SIZE.x), static_cast<float>(FRAMEBUFFER_SIZE.y)); glClearNamedFramebufferfv(FramebufferName[framebuffer::RENDER], GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]); glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize); glBindSamplers(0, 1, &SamplerName); glBindTextureUnit(0, TextureName[texture::TEXTURE]); glBindVertexArray(VertexArrayName); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0, 0); glDisable(GL_MULTISAMPLE); }
GameEngine::GameEngine(const std::string& application_name, WindowMode windowMode) { glfwSetErrorCallback(ErrorCallback); if (!glfwInit()) { std::terminate(); } // Window creation GLFWmonitor *monitor = glfwGetPrimaryMonitor(); const GLFWvidmode *vidmode = glfwGetVideoMode(monitor); #ifdef USE_DEBUG_CONTEXT glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); #else glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); #endif glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_DEPTH_BITS, 24); glfwWindowHint(GLFW_STENCIL_BITS, 8); if (windowMode == WindowMode::kFullScreen) { window_ = glfwCreateWindow(vidmode->width, vidmode->height, application_name.c_str(), monitor, nullptr); } else { window_ = glfwCreateWindow(vidmode->width, vidmode->height, application_name.c_str(), nullptr, nullptr); } if (!window_) { std::cerr << "FATAL: Couldn't create a glfw window. Aborting now." << std::endl; glfwTerminate(); std::terminate(); } // Check the created OpenGL context's version int ogl_major_version = glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MAJOR); int ogl_minor_version = glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MINOR); std::cout << "OpenGL version: " << ogl_major_version << '.' << ogl_minor_version << std::endl; int width, height; glfwGetFramebufferSize(window_, &width, &height); std::cout << "Resolution: " << width << " x " << height << std::endl; if (ogl_major_version < 4 || (ogl_major_version == 4 && ogl_minor_version < 5)) { std::cerr << "At least OpenGL version 4.5 is required to run this program\n"; std::terminate(); } glfwMakeContextCurrent(window_); // No V-sync needed. glfwSwapInterval(0); bool success = gladLoadGL(); if (!success) { std::cerr << "gladLoadGL failed" << std::endl; std::terminate(); } #ifdef USE_DEBUG_CONTEXT glDebugMessageCallback(&DebugCallback, nullptr); #endif success = Label::InitializeTextRendering(); if (!success) { std::cerr << "Label::InitializeTextRendering failed" << std::endl; std::terminate(); } MeshRenderer::InitializeMeshDataStorage(); // Only initialize after the OpenGL context has been created shader_manager_ = make_unique<ShaderManager>(); // OpenGL initialization gl::Enable(gl::kDepthTest); glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); // GLFW callbacks glfwSetWindowUserPointer(window_, this); glfwSetKeyCallback(window_, KeyCallback); glfwSetCharCallback(window_, CharCallback); glfwSetFramebufferSizeCallback(window_, ScreenResizeCallback); glfwSetScrollCallback(window_, MouseScrolledCallback); glfwSetMouseButtonCallback(window_, MouseButtonPressed); glfwSetCursorPosCallback(window_, MouseMoved); }
void set_clip_control (GLenum origin, GLenum depth) { glClipControl(origin, depth); }