3 ms·
Isn't SDL the simplest, most portable way to use OpenGL? OpenGL by itself is useless, it just does 3D graphics, and its GLUT library is too bare-bones to be of
by mahmud 13y ago
Isn't SDL the simplest, most portable way to use OpenGL?
OpenGL by itself is useless, it just does 3D graphics, and its GLUT library is too bare-bones to be of much use. SDL is a good, portable chassis for OpenGL application that don't need native GUI integration. An SDL OpenGL app will compile and run almost anywhere, with minimal fuss. Compare that to using OpenGL contexts inside platform-specific toolkits.
- angersock 13y agoGLFW is an excellent library: http://www.glfw.org/ http://www.glfw.org/ It's very, very barebones (just enough to GL up to do a thing), but it's quite good in that role.
- mahmud 13y agoSDL 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?
- cfrss 13y agoUnfortunately, it is not yet available on Android and iOS. Also http://www.glfw.org/faq.html#12__what_is_glfw_not http://www.glfw.org/faq.html#12__what_is_glfw_not
- eropple 13y agoThe amount of code necessary to wire up a well-written application into iOS and Android is pretty minor. I'd rather do that where I can't use GLFW (I mean, GLEW does most of the hard work anyway, and that is portable). GLFW epitomizes a good library for this stuff, in that it's minimal and minimizes the amount of stuff you have to wrestle with when writing C++; on the other hand, SDL forces you to come to grips with its weight and its own dubious design decisions (and a lot of plumbing code to make it sane in C++). When wrapping OpenGL code myself, at least the dubious design decisions are my own and I understand them intuitively.