'' SDL2-Example program:
'' Using SDL2 to create an OpenGL application window
'' adapted by TJF 2013

#INCLUDE ONCE "SDL2/SDL2.bi"
#INCLUDE ONCE "GL/gl.bi"

'/* Initialize SDL */
IF SDL_Init(SDL_INIT_VIDEO) < 0 THEN
  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, _
    !"Couldn't initialize SDL: %s\n", SDL_GetError())
  END 2
END IF

'' Window mode MUST include SDL_WINDOW_OPENGL for use with OpenGL.
VAR windw = SDL_CreateWindow( _
    "SDL2/OpenGL Demo", 0, 0, 640, 480, _
    SDL_WINDOW_OPENGL OR SDL_WINDOW_RESIZABLE)

'' Create an OpenGL context associated with the window.
VAR glcontext = SDL_GL_CreateContext(windw)

'' now you can make GL calls.
glClearColor(0, 0, 0, 1)

DIM event AS SDL_Event
DO
  glClear(GL_COLOR_BUFFER_BIT)
  ' ...
  SDL_GL_SwapWindow(windw)
  SDL_Delay(40)
LOOP UNTIL (SDL_PollEvent( @event ) <> 0) ANDALSO ((event.type = SDL_KEYDOWN) ORELSE (event.type = SDL_MOUSEBUTTONDOWN))

'' Once finished with OpenGL functions, the SDL_GLContext can be deleted.
SDL_GL_DeleteContext(glcontext)
SDL_DestroyWindow(windw)
SDL_Quit()
