Glfw
Biblioteca livre de plataforma que serve para criar uma janela OpenGL, além de fazer outras funções utilitárias como manusear entrada com mouse e teclado. Ela e multiplataforma, suporta OpenGL moderno, alem de OpenGL ES e Vulkan.
Código simples
O código mais simples que permite criar uma janela OpenGL funcionando é a seguinte
(Código GLFW3+)
#include <GLFW/glfw3.h> int main(){ GLFWwindow *window; /* Initialize the library */ if( !glfwInit() ) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow( 640, 480, "Hello World", NULL, NULL ); if( !window ) { glfwTerminate(); return -1; } /* Make thw window's context current */ glfwMakeContextCurrent(window); /* Loop until the user closes the window */ while( !glfwWindowShouldClose(window) ){ /* Render Here */ /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); } glfwTerminate(); return 0; }
(Código GLFW2)
#include <GL/glfw.h> int main(){ if( !glfwInit() ) return -1; if( !glfwOpenWindow( 640, 480, 8, 8, 8, 0, 24, 0, GLFW_WINDOW ) ) return -1; glClearColor( 1.0f, 0.0f, 0.0f, 1.0f ); while( glfwGetWindowParam( GLFW_OPENED ) ){ glClear( GL_COLOR_BUFFER_BIT ); glfwSwapBuffers(); } return 0; }
Links
http://www.glfw.org/ Página da API
revisão da página: 7, última edição: 21 Jun 2016 00:11