Advertisement
Tkap1

Untitled

Feb 7th, 2025
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv     CREATE WINDOW START     vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  2. {
  3.  
  4.     window.handle = CreateWindowEx(
  5.         0,
  6.         class_name,
  7.         "Window",
  8.         WS_POPUP | WS_VISIBLE,
  9.         CW_USEDEFAULT,
  10.         CW_USEDEFAULT,
  11.         args.window_w ? args.window_w : g_window_width,
  12.         args.window_h ? args.window_h : g_window_height,
  13.         0,
  14.         null,
  15.         hinstance,
  16.         null
  17.     );
  18.  
  19.     if(!window.handle)
  20.     {
  21.         print_win32_error();
  22.         platform_exit();
  23.     }
  24.  
  25.     HMONITOR monitor = MonitorFromWindow(
  26.         window.handle,
  27.         MONITOR_DEFAULTTONEAREST
  28.     );
  29.  
  30.     MONITORINFO monitor_info = zero;
  31.     monitor_info.cbSize = sizeof(monitor_info);
  32.     GetMonitorInfoA(
  33.         monitor,
  34.         &monitor_info
  35.     );
  36.  
  37.     int monitor_w = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
  38.     int monitor_h = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
  39.     g_window_width = args.window_w ? args.window_w : monitor_w;
  40.     g_window_height = args.window_h ? args.window_h : monitor_h;
  41.  
  42.     SetWindowPos(
  43.         window.handle,
  44.         0,
  45.         args.window_x,
  46.         args.window_y,
  47.         g_window_width,
  48.         g_window_height,
  49.         0
  50.     );
  51.  
  52.  
  53. }
  54. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     CREATE WINDOW END       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  55.  
  56.  
  57.  
  58.  
  59.  
  60. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv     CREATE CONTEXT START        vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  61. {
  62.     HGLRC gldc = 0;
  63.     window.dc = GetDC(window.handle);
  64.  
  65.     if(!window.dc)
  66.     {
  67.         print_win32_error();
  68.         platform_exit();
  69.     }
  70.  
  71.     int pixelFormat[32];
  72.     UINT numFormats;
  73.     const int pixelAttribs[] = {
  74.         WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
  75.         WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
  76.         WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
  77.         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
  78.         // WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, // @Note(tkap, 16/07/2024): It appears we don't need this?
  79.         WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
  80.         // WGL_COLOR_BITS_ARB, 32,
  81.         WGL_COLOR_BITS_ARB, 24,
  82.         WGL_DEPTH_BITS_ARB, 24,
  83.         WGL_ALPHA_BITS_ARB, 8,
  84.         // WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
  85.         // WGL_SAMPLES_ARB, 4,
  86.         0
  87.     };
  88.  
  89.     int contextAttributes[] = {
  90.         WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
  91.         WGL_CONTEXT_MINOR_VERSION_ARB, 3,
  92.         WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  93.  
  94.         #ifdef m_debug
  95.         WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
  96.         #endif
  97.         0
  98.     };
  99.  
  100.     if(!wglChoosePixelFormatARB(window.dc, pixelAttribs, null, 1, pixelFormat, &numFormats))
  101.     {
  102.         print_win32_error();
  103.         platform_exit();
  104.     }
  105.     assert(numFormats);
  106.  
  107.     PIXELFORMATDESCRIPTOR pfd = zero;
  108.     DescribePixelFormat(window.dc, pixelFormat[0], sizeof(PIXELFORMATDESCRIPTOR), &pfd);
  109.  
  110.     if(!SetPixelFormat(window.dc, pixelFormat[0], &pfd))
  111.     {
  112.         print_win32_error();
  113.         platform_exit();
  114.     }
  115.  
  116.     gldc = wglCreateContextAttribsARB(window.dc, 0, contextAttributes);
  117.     if(!gldc)
  118.     {
  119.         print_win32_error();
  120.         platform_exit();
  121.     }
  122.  
  123.     if(!wglMakeCurrent(window.dc, gldc))
  124.     {
  125.         print_win32_error();
  126.         platform_exit();
  127.     }
  128.  
  129. }
  130. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     CREATE CONTEXT END      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement