It's very, very barebones (just enough to GL up to do a thing), but it's quite good in that role.
It's very, very barebones (just enough to GL up to do a thing), but it's quite good in that role.
When wrapping OpenGL code myself, at least the dubious design decisions are my own and I understand them intuitively.
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
if (!glfwInit())
return -1;
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
/* Render here */
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
VS #include <GL3/gl3.h>
#include <SDL.h>
/* Our program's entry point */
int main(int argc, char *argv[])
{
SDL_Window *mainwindow;
SDL_GLContext maincontext;
SDL_Event event;
int running = 1;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
exit(1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (!mainwindow)
exit(1);
maincontext = SDL_GL_CreateContext(mainwindow);
SDL_GL_SetSwapInterval(1);
while (running) {
while (SDL_PollEvent(&event) {
if ( event == SDL_WINDOWEVENT_CLOSE ) {
running = 0;
break;
}
/* render */
}
SDL_GL_SwapWindow(mainwindow);
}
SDL_GL_DeleteContext(maincontext);
SDL_DestroyWindow(mainwindow);
SDL_Quit();
return 0;
}
It's got SDL beat a bit in simplicity for OpenGL, sorry dude.There's nothing wrong with using SDL for making a game (well, maybe a couple of things, but that's not relevant here), but it simply isn't the smallest GL scaffolding library out there.
But I got bit by half-assed "GL" ways of doing things before. SDL has everything, in layers, so you can grow into it. Unlike "portable GL" libraries which are discrete, isolate dead-ends.
GLFW does not attempt to handle OpenGL for you, it handles windowing and input for you. I personally really don't want SDL anywhere near my projects because it imposes its own structure upon me. (I don't use Allegro, even for 2D code, for similar reasons.) I am simply not all that fussed by writing up a VBO handler and some pretty simple OpenAL code myself--it isn't difficult enough for me to warrant the huge blob of extraneous SDL stuff.
window = glfwCreateWindow(640, 480, "Hello World", glfwGetPrimaryMonitor(), NULL);
Requesting a specific version with a particular depth: glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_DEPTH_BIT, 24);
There you go.