Commit c7acd2b2 authored by bbguimaraes's avatar bbguimaraes
Browse files

open.gl: context

parent e21a84b1
CPPFLAGS = -std=c++11
context: context.cpp -lglfw -lGLEW -lGLU -lGL
.PHONY: clean
clean:
rm -f context
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow * create_window(int width, int height, const char * title);
void init_glew();
void loop(GLFWwindow * window);
void check_gl_error();
int main() {
glfwInit();
GLFWwindow * window = create_window(800, 600, "OpenGL");
glfwMakeContextCurrent(window);
init_glew();
GLuint vertex_buffer;
glGenBuffers(1, &vertex_buffer);
std::cout << vertex_buffer << std::endl;
loop(window);
glfwTerminate();
return 0;
}
GLFWwindow * create_window(int width, int height, const char * title) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
return glfwCreateWindow(width, height, title, nullptr, nullptr);
}
void init_glew() {
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if(err != GLEW_OK) {
std::cerr << "glewInit: failed" << std::endl;
exit(1);
}
// https://www.opengl.org/wiki/OpenGL_Loading_Library
glGetError();
}
void loop(GLFWwindow * window) {
while(!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
check_gl_error();
}
}
void check_gl_error() {
GLenum error;
if((error = glGetError()) != GL_NO_ERROR) {
std::cerr << "glGetError: " << gluErrorString(error) << std::endl;
exit(1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment