#include #include #include #include #include #include #include #include #include const int SCREEN_WIDTH = 1920; const int SCREEN_HEIGHT = 1080; static bool drawWireframe = false; static bool wireframeHeld = false; void window_resize_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } void processInput(GLFWwindow* window) { // Close on Escape if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); // Wireframe toggle if (glfwGetKey(window, GLFW_KEY_F1) == GLFW_PRESS && !wireframeHeld) { wireframeHeld = true; drawWireframe = !drawWireframe; if (drawWireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } } if (glfwGetKey(window, GLFW_KEY_F1) == GLFW_RELEASE) wireframeHeld = false; } int main(int argc, char* argv[]) { // Initialize GLFW glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Create GLFW Window GLFWwindow* window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Renderer", NULL, NULL); if (window == NULL) { std::cout << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); // Initialize GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } // Initialize Viewport & setup resize callback glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); glfwSetFramebufferSizeCallback(window, window_resize_callback); // Load Shader Shader shaderTest("assets/shaders/basicVertex.vert", "assets/shaders/basicFragment.frag"); std::vector vertices = { { 1, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f }, { 1, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }, { 0, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, { 0, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f } }; std::vector indices = { 0, 1, 3, 1, 2, 3 }; Mesh testMesh(vertices, indices); std::vector vertices2 = { { 0, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.6f, 1.0f }, { 0, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }, { -1, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, { -1, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f } }; Mesh testMesh2(vertices2, indices); Texture texture1("assets/wall.jpg"); Texture texture2("assets/awesomeface.png", true); shaderTest.Use(); // don't forget to activate/use the shader before setting uniforms! shaderTest.setInt("ourTexture", 0); shaderTest.setInt("decal", 1); // Render Loop while (!glfwWindowShouldClose(window)) { // Input processing processInput(window); // Rendering glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); shaderTest.Use(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture1.ID); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture2.ID); testMesh.Draw(); testMesh2.Draw(); // Call events & swap buffers glfwSwapBuffers(window); glfwPollEvents(); } // Clean up memory glfwTerminate(); return 0; }