3 ms·
SDL exists, is tiny, modular and efficient. Not to mention has loads of extensions.
by mahmud 13y ago
SDL exists, is tiny, modular and efficient. Not to mention has loads of extensions.
- angersock 13y ago#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.
- mahmud 13y agoYep, because main-loop boilerplate is all one ever does with graphics programming.
- angersock 13y agoHey, no reason to get snippy--you asked "Isn't SDL the simplest, most portable way to use OpenGL?", and asserted that it's a smaller library. I showed you a still-smaller alternative, and even dug up code to substantiate that point. 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.
- mahmud 13y agoHeh, you're right, I got a little snarky. Sorry :-P 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.
- eropple 13y agoCalling GLFW a "dead end" is misleading and unfair. 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.
- caf 13y agoAs someone who's used neither, I'd call that a draw. Neither of that boilerplate looks particularly scary or insane.
- wtallis 13y agoThat doesn't show that GLFW is simpler than SDL. It just shows that GLFW has some simple defaults. How much complexity is added to the GLFW code if you want to require a minimum GL version and depth buffer size? Or a fulllscreen window?
- angersock 13y agoSure. Fullscreen mode: 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.