aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/windows
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-03-31 21:54:42 +0200
committerArisotura <thetotalworm@gmail.com>2019-03-31 21:54:42 +0200
commitf1628b98de5dcef702ca57ee363407d715d5b36e (patch)
tree0339c53d3dfa9d610904bb8aa1a56cbf5e1fcf38 /src/libui_sdl/libui/windows
parentb48fe5909bd9314c271f1cb729c9aa79d88a26f3 (diff)
adding that file might be good, too
Diffstat (limited to 'src/libui_sdl/libui/windows')
-rw-r--r--src/libui_sdl/libui/windows/gl.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/libui_sdl/libui/windows/gl.cpp b/src/libui_sdl/libui/windows/gl.cpp
new file mode 100644
index 0000000..fe21ae4
--- /dev/null
+++ b/src/libui_sdl/libui/windows/gl.cpp
@@ -0,0 +1,66 @@
+// 31 march 2019
+#include "uipriv_windows.hpp"
+
+struct uiGLContext
+{
+ uiControl* c;
+
+ HWND hwnd;
+ HDC dc;
+ HGLRC rc;
+};
+
+
+uiGLContext* uiGLNewContext(uiControl* c)
+{
+ uiGLContext* ctx;
+
+ ctx = uiNew(uiGLContext);
+
+ ctx->c = c;
+ if (c)
+ {
+ ctx->hwnd = (HWND)c->Handle(c); // welp
+ }
+ else
+ {
+ // windowless context
+ ctx->hwnd = GetDesktopWindow();
+ }
+
+ PIXELFORMATDESCRIPTOR pfd;
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 24;
+ pfd.cAlphaBits = 8;
+ pfd.cDepthBits = 24;
+ pfd.cStencilBits = 8;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+
+ ctx->dc = GetDC(ctx->hwnd);
+
+ int pixelformat = ChoosePixelFormat(ctx->dc, &pfd);
+ SetPixelFormat(ctx->dc, pixelformat, &pfd);
+
+ ctx->rc = wglCreateContext(ctx->dc);
+}
+
+void uiGLFreeContext(uiGLContext* ctx)
+{
+ wglDeleteContext(ctx->rc);
+ ReleaseDC(ctx->hwnd, ctx->dc);
+ uiFree(ctx);
+}
+
+void uiGLMakeContextCurrent(uiGLContext* ctx)
+{
+ wglMakeCurrent(ctx->dc, ctx->rc);
+}
+
+void *uiGLGetProcAddress(const char* proc)
+{
+ return (void*)wglGetProcAddress(proc);
+}