Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <glm/glm.hpp>
- #include <iostream>
- #include <string>
- #include "util/shaderutil.hpp"
- #define WIDTH 800
- #define HEIGHT 600
- using namespace std;
- using namespace glm;
- GLuint vao;
- GLuint vbo;
- GLuint shaderprogram;
- static const GLfloat vertices[3 * 3] = {
- 0.0, 0.5, 0.0,
- 0.5,-0.5, 0.0,
- -0.5,-0.5, 0.0
- };
- bool found = false;
- void check(int line) {
- GLenum e = glGetError();
- if (e != GL_NO_ERROR && !found) {
- cerr << "ERROR FOUND @ LINE " << line << " WITH ERROR CODE " << e << endl;
- found = true;
- }
- }
- void initialize() {
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- string version = (char*) glGetString(GL_VERSION);
- cout << "Using OpenGL Version: " << version << endl << endl;
- glClearColor(0.5, 0.7, 0.9, 1.0);
- string vShaderPath = "shaders/shader.vert";
- string fShaderPath = "shaders/shader.frag";
- shaderprogram = ShaderUtil::createProgram(vShaderPath.c_str(), fShaderPath.c_str());
- }
- void render() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glUseProgram(shaderprogram);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- }
- void clean() {
- glDeleteProgram(shaderprogram);
- }
- int main(int argc, char** argv) {
- if (!glfwInit()) {
- cerr << "GLFW ERROR!" << endl;
- return -1;
- }
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- GLFWwindow* win = glfwCreateWindow(WIDTH, HEIGHT, "Stuff happening...", NULL, NULL);
- glfwMakeContextCurrent(win);
- glewExperimental = GL_TRUE;
- if (glewInit() != GLEW_OK) {
- cerr << "GLEW ERROR!" << endl;
- return -1;
- } else {
- glGetError();
- //GLEW BUG: SETTING THE ERRORFLAG TO INVALID_ENUM; THEREFORE RESET
- }
- initialize();
- while (!glfwWindowShouldClose(win)) {
- render();
- glfwPollEvents();
- glfwSwapBuffers(win);
- }
- clean();
- glfwDestroyWindow(win);
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment