🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Convert SDL commands to OpenGL

Started by
4 comments, last by Shaarigan 4 years, 2 months ago

HI

how would those sdl commands look in OpenGL?

Many thanks

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);

SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);

SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);

SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, kStencilBits);

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

SDL_GL_SwapWindow(window);

SDL_GL_DeleteContext(glContext);

Advertisement

These commands don't have an equivalent in OpenGL. OpenGL provides commands for drawing to an OpenGL context, but creating that context is outside of the domain of the OpenGL standard. There are several different platform-dependent ways of setting up an OpenGL context, and SDL provides a wrapper around these different methods to provide a single clean cross-platform API.

Nevermind, your right, it's the context. Even at a lower level of xcb/xlib in my case.

One can create one's own objects (framebuffers with depth and colour attachments) but in the end everything lands in the default buffer.

GLFW is a windowing library. It has very similar functions such as

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, verMajor);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, verMinor);
glfwWindowHint(GLFW_RED_BITS, redBits);
glfwWindowHint(GLFW_GREEN_BITS, greenBits);
glfwWindowHint(GLFW_BLUE_BITS, blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, refreshRate);
glfwSwapBuffers(window);
glfwPollEvents();

You could use GLFW with GLEW and have the start of a barebones OpenGL game/app. I have some simple .cpp code here

https://www.gamedev.net/forums/topic/699307-still-trying-to-debug-an-odd-glew-issue-please-help/

about halfway down the page that can help you get started.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

MikeCyber said:
how would those sdl commands look in OpenGL

One tip you should every try first before asking such things:

  • Read the docs
  • Read the source code if available
  • Set a breakpoint in your favourite IDE and follow the function step by step to se what's going on under the hood

You'll learn more on debugging and understanding running code than let someone else explain how it works

This topic is closed to new replies.

Advertisement