Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv CREATE WINDOW START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- window.handle = CreateWindowEx(
- 0,
- class_name,
- "Window",
- WS_POPUP | WS_VISIBLE,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- args.window_w ? args.window_w : g_window_width,
- args.window_h ? args.window_h : g_window_height,
- 0,
- null,
- hinstance,
- null
- );
- if(!window.handle)
- {
- print_win32_error();
- platform_exit();
- }
- HMONITOR monitor = MonitorFromWindow(
- window.handle,
- MONITOR_DEFAULTTONEAREST
- );
- MONITORINFO monitor_info = zero;
- monitor_info.cbSize = sizeof(monitor_info);
- GetMonitorInfoA(
- monitor,
- &monitor_info
- );
- int monitor_w = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
- int monitor_h = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
- g_window_width = args.window_w ? args.window_w : monitor_w;
- g_window_height = args.window_h ? args.window_h : monitor_h;
- SetWindowPos(
- window.handle,
- 0,
- args.window_x,
- args.window_y,
- g_window_width,
- g_window_height,
- 0
- );
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ CREATE WINDOW END ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv CREATE CONTEXT START vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- HGLRC gldc = 0;
- window.dc = GetDC(window.handle);
- if(!window.dc)
- {
- print_win32_error();
- platform_exit();
- }
- int pixelFormat[32];
- UINT numFormats;
- const int pixelAttribs[] = {
- WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
- WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
- WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
- WGL_SWAP_METHOD_ARB, WGL_SWAP_COPY_ARB, // @Note(tkap, 16/07/2024): If we don't have this, using the zoomit program's pencil feature, we get an outdated image of the game
- // WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, // @Note(tkap, 16/07/2024): It appears we don't need this?
- WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
- // WGL_COLOR_BITS_ARB, 32,
- WGL_COLOR_BITS_ARB, 24,
- WGL_DEPTH_BITS_ARB, 24,
- WGL_ALPHA_BITS_ARB, 8,
- // WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
- // WGL_SAMPLES_ARB, 4,
- 0
- };
- int contextAttributes[] = {
- WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
- WGL_CONTEXT_MINOR_VERSION_ARB, 3,
- WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
- #ifdef m_debug
- WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
- #endif
- 0
- };
- if(!wglChoosePixelFormatARB(window.dc, pixelAttribs, null, 1, pixelFormat, &numFormats))
- {
- print_win32_error();
- platform_exit();
- }
- assert(numFormats);
- PIXELFORMATDESCRIPTOR pfd = zero;
- DescribePixelFormat(window.dc, pixelFormat[0], sizeof(PIXELFORMATDESCRIPTOR), &pfd);
- if(!SetPixelFormat(window.dc, pixelFormat[0], &pfd))
- {
- print_win32_error();
- platform_exit();
- }
- gldc = wglCreateContextAttribsARB(window.dc, 0, contextAttributes);
- if(!gldc)
- {
- print_win32_error();
- platform_exit();
- }
- if(!wglMakeCurrent(window.dc, gldc))
- {
- print_win32_error();
- platform_exit();
- }
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ CREATE CONTEXT END ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement