Skip to content

Instantly share code, notes, and snippets.

@UplinkCoder
Created July 20, 2018 12:44
Show Gist options
  • Select an option

  • Save UplinkCoder/51696104aa4c3e9e81571acd94ef35f6 to your computer and use it in GitHub Desktop.

Select an option

Save UplinkCoder/51696104aa4c3e9e81571acd94ef35f6 to your computer and use it in GitHub Desktop.
Load sdl and gl into cling
#include "cling/Interpreter/Interpreter.h"
#include "SDL2/SDL.h"
#include "GL/gl.h"
SDL_GLContext ctx;
SDL_Window* win;
bool loadSDL();
bool loadGL();
bool sdlLoaded = false;
bool glLoaded = false;
void p()
{
sdlLoaded = loadSDL();
if (sdlLoaded)
{
gCling->execute("SDL_Init(SDL_INIT_VIDEO);");
}
glLoaded = loadGL();
if (glLoaded && sdlLoaded)
{
gCling->execute("win = SDL_CreateWindow(\"Hello Cling\", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 786, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);");
gCling->execute("ctx = SDL_GL_CreateContext(win)");
}
}
void swap()
{
gCling->execute("glEnd(); SDL_GL_SwapWindow(win);");
}
bool loadSDL()
{
return (gCling->loadLibrary("SDL2") ==
cling::Interpreter::CompilationResult::kSuccess
);
}
bool loadGL()
{
return (gCling->loadLibrary("GL") ==
cling::Interpreter::CompilationResult::kSuccess
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment