|
|
@@ -1,12 +1,21 @@
|
|
|
+#include <GL/glcorearb.h>
|
|
|
+#include <GL/wglext.h>
|
|
|
+#include <assert.h>
|
|
|
#include <shobjidl.h>
|
|
|
+#include <stdbool.h>
|
|
|
#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
#include <wchar.h>
|
|
|
#include <windows.h>
|
|
|
#include <windowsx.h>
|
|
|
#include <winuser.h>
|
|
|
|
|
|
+#include "DynArray.h"
|
|
|
+#include "DynString.h"
|
|
|
#include "log.h"
|
|
|
|
|
|
+HMODULE opengl_module = NULL;
|
|
|
+
|
|
|
// int _main() {
|
|
|
// return 0;
|
|
|
// }
|
|
|
@@ -18,6 +27,23 @@ typedef struct {
|
|
|
int num;
|
|
|
} State;
|
|
|
|
|
|
+void* gl_function_load(const char* name) {
|
|
|
+ assert(opengl_module != NULL);
|
|
|
+ void* gl_func = (void*) wglGetProcAddress(name);
|
|
|
+ if (gl_func == NULL || gl_func == (void*) 1 || gl_func == (void*) 2 || gl_func == (void*) 3 || gl_func == (void*) -1) {
|
|
|
+ void* gl32_func = (void*) GetProcAddress(opengl_module, name);
|
|
|
+ if (gl32_func == NULL || gl32_func == (void*) 1 || gl32_func == (void*) 2 || gl32_func == (void*) 3 || gl32_func == (void*) -1) {
|
|
|
+ LOG_ERRORF("wglGetProcAddress failed to load gl function %s. Returned %p\n", name, gl_func);
|
|
|
+ LOG_ERRORF("GetProcAddress failed to load gl function %s. Returned %p\n", name, gl32_func);
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return gl32_func;
|
|
|
+ }
|
|
|
+
|
|
|
+ return gl_func;
|
|
|
+}
|
|
|
+
|
|
|
void OnSize(HWND hwnd, UINT flag, int width, int height) {
|
|
|
printf("Window resize: flag: %d, width: %d, height: %d\n", flag, width, height);
|
|
|
}
|
|
|
@@ -94,8 +120,92 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+ PFNGLGETINTEGERVPROC glGetIntegerv = (PFNGLGETINTEGERVPROC) gl_function_load("glGetIntegerv");
|
|
|
+ if (glGetIntegerv == NULL) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ int major = 0;
|
|
|
+ int minor = 0;
|
|
|
+ glGetIntegerv(GL_MAJOR_VERSION, &major);
|
|
|
+ glGetIntegerv(GL_MINOR_VERSION, &minor);
|
|
|
+ printf("OpenGL version %d.%d\n", major, minor);
|
|
|
+
|
|
|
+ int profile_mask = 0;
|
|
|
+ glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile_mask);
|
|
|
+ if (profile_mask & GL_CONTEXT_CORE_PROFILE_BIT) {
|
|
|
+ printf("OpenGL profile: core\n");
|
|
|
+ } else if (profile_mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) {
|
|
|
+ printf("OpenGL profile: compatibility\n");
|
|
|
+ } else {
|
|
|
+ LOG_ERRORF(
|
|
|
+ "GL_CONTEXT_PROFILE_MASK did not contain either bit. profile_mask: %d",
|
|
|
+ profile_mask
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) gl_function_load("wglGetExtensionsStringARB");
|
|
|
+ if (wglGetExtensionsStringARB == NULL) {
|
|
|
+ LOG_ERROR("Could not load wgl extensions string.");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // const char* wgl_extensions = wglGetExtensionsStringARB(hdc);
|
|
|
+ char* wgl_extensions = (char*) wglGetExtensionsStringARB(hdc);
|
|
|
+ printf("wgl extensions: %s\n", wgl_extensions);
|
|
|
+
|
|
|
+ DynArray_DynString extensions_arr = { 0 };
|
|
|
+ if (!DynArray_DynString_alloc(&extensions_arr, 1)) {
|
|
|
+ LOG_ERROR("Failed to allocate");
|
|
|
+ }
|
|
|
+
|
|
|
+ char* wgl_extensions_copy = strdup(wgl_extensions);
|
|
|
+
|
|
|
+ char* ext = strtok(wgl_extensions_copy, " ");
|
|
|
+ if (ext == NULL) {
|
|
|
+ LOG_ERROR("wgl_extensions was empty");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ DynString ext_dstr = { 0 };
|
|
|
+ if (!DynString_alloc(&ext_dstr, ext, strlen(ext))) {
|
|
|
+ LOG_ERROR("Failed to allocate extension string");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!DynArray_DynString_push_back(&extensions_arr, &ext_dstr)) {
|
|
|
+ LOG_ERROR("Failed to push back extension string");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ // printf("ext: %s\n", ext);
|
|
|
+ while (true) {
|
|
|
+ ext = strtok(NULL, " ");
|
|
|
+ // printf("ext: %s\n", ext);
|
|
|
+ if (ext == NULL) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ DynString ext_dstr = { 0 };
|
|
|
+ if (!DynString_alloc(&ext_dstr, ext, strlen(ext))) {
|
|
|
+ LOG_ERROR("Failed to allocate extension string");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!DynArray_DynString_push_back(&extensions_arr, &ext_dstr)) {
|
|
|
+ LOG_ERROR("Failed to push back extension string");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ free(wgl_extensions_copy);
|
|
|
+
|
|
|
+ printf("count: %zu\n", extensions_arr.count);
|
|
|
+ for (size_t i = 0; i < extensions_arr.count; i++) {
|
|
|
+ printf("%s\n", extensions_arr.data[i].data);
|
|
|
+ }
|
|
|
+
|
|
|
// glClearColor(1.0, 1.0, 0.0, 1.0);
|
|
|
// glClear(GL_COLOR_BUFFER_BIT);
|
|
|
+ // const unsigned char* version = glGetString(GL_VERSION);
|
|
|
+ // printf("OpenGL version %s\n", version);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -144,6 +254,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
}
|
|
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) {
|
|
|
+ opengl_module = LoadLibraryA("opengl32.dll");
|
|
|
+
|
|
|
// Register the window class
|
|
|
const wchar_t* CLASS_NAME = L"Sample Window Class";
|
|
|
|