summaryrefslogtreecommitdiff
path: root/shared_cpp/WebglContext.h
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-05-16 19:50:15 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-05-16 19:50:15 -0400
commita00c0aab1eb5a7a55bef8ca08115bdd722ab5699 (patch)
tree45b5c4cc8c380d0630a8e0185af7229f26dc754a /shared_cpp/WebglContext.h
parent4941a1874b6ca9d142d94df70b2aec5e0b35b94e (diff)
Moved the frontend directory up so that it no longer exists
Diffstat (limited to 'shared_cpp/WebglContext.h')
-rw-r--r--shared_cpp/WebglContext.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/shared_cpp/WebglContext.h b/shared_cpp/WebglContext.h
new file mode 100644
index 0000000..017498f
--- /dev/null
+++ b/shared_cpp/WebglContext.h
@@ -0,0 +1,39 @@
+#pragma once
+#include "types.h"
+#include <emscripten.h>
+#include <emscripten/html5.h>
+#include <GLES2/gl2.h>
+#include <EGL/egl.h>
+
+struct WebglContext {
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context;
+ int width = 640;
+ int height = 480;
+
+ void init(const char* query, int inWidth = 640, int inHeight = 480) {
+ width = inWidth;
+ height = inHeight;
+ emscripten_set_canvas_element_size( query, width, height);
+
+ EmscriptenWebGLContextAttributes attrs;
+ emscripten_webgl_init_context_attributes(&attrs);
+
+ attrs.enableExtensionsByDefault = 1;
+ attrs.majorVersion = 3;
+ attrs.minorVersion = 0;
+
+ context = emscripten_webgl_create_context(query, &attrs);
+ makeCurrentContext();
+
+ glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ };
+
+ void makeCurrentContext() {
+ emscripten_webgl_make_context_current(context);
+ };
+
+ void destroy() {
+ emscripten_webgl_destroy_context(context);
+ }
+}; \ No newline at end of file