[fpc-pascal] OpenGL and SDL frustrations

Anthony Walter sysrpl at gmail.com
Thu May 25 09:30:50 CEST 2017


You need to tell SDL what OpenGL kind and version before you create a
window. For example if you want OpenGLES 2.0 you would write:

SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
If you want normal OpenGL 4.0 you would write:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

Then you can create the SDL and load the appropriate OpenGL function
prototypes using:

glClear := SDL_GL_GetProcAddress('glClear');
It's up to you to know which functions are part of which which OpenGL spec,
and you should need to load the functions dynamically to stubs:

var glClear: procedure(mask: GLbitfield); cdecl;
Don't forget, if you want a specific values for stencil bits, pixel order,
multisampling levels and other stuff, you need to set those values before
you create a window. Check the return values of SDL_CreateWindow and
SDL_GL_CreateContext to see if anything above fails, for example the target
device doesn't support OpenGL 4.0.

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8); // 8x anti-aliasing,
must be called before SDL_CreateWindow
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 16); // 16 bit stencil buffer,
must be called before SDL_CreateWindow
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170525/b8675e16/attachment.html>


More information about the fpc-pascal mailing list