程式語言 - Simple DirectMedia Layer (SDL) - OpenGL ES 2.0 - C/C++ - Get Version



參考資訊:
https://wiki.libsdl.org/FrontPage
https://kaprikawn.wordpress.com/2018/01/07/learning-to-learn-opengl-es-2-0-part-01/

main.c

#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <GLES2/gl2.h>

int main(int argc, char **argv)
{
    SDL_Window *window = NULL;
    SDL_GLContext context = {0};
    const GLubyte *version = NULL;

    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);

    window = SDL_CreateWindow("main", 0, 0, 320, 240, SDL_WINDOW_OPENGL);
    context = SDL_GL_CreateContext(window);
    version = glGetString(GL_VERSION);
    printf("Version:%s\n", version);
    SDL_GL_DeleteContext(context);
    return 0;
}

編譯、執行

$ gcc main.c -lSDL2 -lGLESv2 -o main
$ ./main
    Version:OpenGL ES 3.0 Mesa 18.3.6