Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "glm/ext/matrix_clip_space.hpp"
- #include "glm/ext/matrix_float4x4.hpp"
- #include "glm/ext/matrix_transform.hpp"
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb_image.h"
- #include "include/glad/glad.h"
- #include "canned_glfw_window.hpp"
- #include "glm/glm.hpp"
- #include "glm/gtc/matrix_transform.hpp"
- #include "glm/gtc/type_ptr.hpp"
- #include <GLFW/glfw3.h>
- #include <algorithm>
- #include <iostream>
- #include <memory>
- #include <vector>
- void log_callback(GLenum source, GLenum type, GLuint id, GLenum severity,
- GLsizei length, const GLchar *msg, const void *userparam) {
- std::cout << std::string_view(msg) << std::endl;
- }
- int main() {
- GLFWWindow main_window(800, 600, "This might be a pretty solid screensaver", NULL, NULL, 3, 3, GLFW_OPENGL_CORE_PROFILE);
- glEnable(GL_DEBUG_OUTPUT);
- glEnable(GL_DEPTH_TEST);
- glDebugMessageCallback(log_callback, nullptr);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- float vertices[] = {
- -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
- 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
- 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
- 0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
- -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
- -0.5f, 0.5f, 0.5f, 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vec3( 2.4f, -0.4f, -3.5f),
- glm::vec3(-1.7f, 3.0f, -7.5f),
- glm::vec3( 1.3f, -2.0f, -2.5f),
- glm::vec3( 1.5f, 2.0f, -2.5f),
- glm::vec3( 1.5f, 0.2f, -1.5f),
- glm::vec3(-1.3f, 1.0f, -1.5f)
- };
- std::unique_ptr<GLShader> vertex_shader(new GLShader("./obamium_shaders/vertex_shader_with_perspective.glsl", GL_VERTEX_SHADER));
- std::unique_ptr<GLShader> fragment_shader(new GLShader("./obamium_shaders/fragment_shader_with_perspective.glsl", GL_FRAGMENT_SHADER));
- std::cout << "vertex_shader: " << vertex_shader->get_compile_status() << std::endl;
- std::cout << "fragment_shader: " << fragment_shader->get_compile_status() << std::endl;
- GLShaderProgram shader_program({&vertex_shader, &fragment_shader});
- VAObject vao(1);
- vao.bind_vao();
- BufferObject vertex_buffer(1, GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float)));
- glEnableVertexAttribArray(1);
- shader_program.use_shader_program();
- while (!main_window.should_close()) {
- main_window.set_color(0.0f, 0.0f, 0.0f, 0.0f);
- main_window.clear_buffer(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -3.0f));
- glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f/600.0f, 0.1f, 100.0f);
- shader_program.set_uniform_matrix<4>("view", 1, GL_FALSE, glm::value_ptr(view));
- shader_program.set_uniform_matrix<4>("projection", 1, GL_FALSE, glm::value_ptr(projection));
- vao.bind_vao();
- for (glm::vec3 position : positions) {
- glm::mat4 model = glm::translate(glm::mat4(1.0f), position);
- model = glm::rotate(glm::mat4(1.0f), static_cast<float>(glfwGetTime()) * glm::radians(-55.0f), glm::vec3(1.0f, 0.0f, 1.0f));
- shader_program.set_uniform_matrix<4>("model", 1, GL_FALSE, glm::value_ptr(model));
- glDrawArrays(GL_TRIANGLES, 0, (sizeof(vertices) / sizeof(float)) / 6);
- }
- main_window.main_loop_setup();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment