Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void create_window(int width, int height)
- {
- const char* class_name = "RocketJump!_CLASS";
- HINSTANCE instance = GetModuleHandle(NULL);
- PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
- PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = NULL;
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv dummy start vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- WNDCLASSEX window_class = {};
- window_class.cbSize = sizeof(window_class);
- window_class.style = CS_OWNDC;
- window_class.lpfnWndProc = DefWindowProc;
- window_class.lpszClassName = class_name;
- window_class.hInstance = instance;
- check(RegisterClassEx(&window_class));
- HWND dummy_window = CreateWindowEx(
- 0,
- class_name,
- "dummy",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL,
- NULL,
- instance,
- NULL
- );
- assert(dummy_window != INVALID_HANDLE_VALUE);
- HDC dc = GetDC(dummy_window);
- PIXELFORMATDESCRIPTOR pfd = {};
- pfd.nSize = sizeof(pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 24;
- pfd.iLayerType = PFD_MAIN_PLANE;
- int format = ChoosePixelFormat(dc, &pfd);
- check(DescribePixelFormat(dc, format, sizeof(pfd), &pfd));
- check(SetPixelFormat(dc, format, &pfd));
- HGLRC glrc = wglCreateContext(dc);
- check(wglMakeCurrent(dc, glrc));
- wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)load_gl_func("wglCreateContextAttribsARB");
- wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)load_gl_func("wglChoosePixelFormatARB");
- check(wglMakeCurrent(NULL, NULL));
- check(wglDeleteContext(glrc));
- check(ReleaseDC(dummy_window, dc));
- check(DestroyWindow(dummy_window));
- check(UnregisterClass(class_name, instance));
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ dummy end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv window start vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- WNDCLASSEX window_class = {};
- window_class.cbSize = sizeof(window_class);
- window_class.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
- window_class.lpfnWndProc = window_proc;
- window_class.lpszClassName = class_name;
- window_class.hInstance = instance;
- window_class.hCursor = LoadCursor(NULL, IDC_ARROW);
- window_class.hIcon = LoadIcon(instance, MAKEINTRESOURCE(MY_ICON));
- check(RegisterClassEx(&window_class));
- DWORD style = (WS_OVERLAPPEDWINDOW) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX;
- RECT rect = {};
- rect.right = width;
- rect.bottom = height;
- AdjustWindowRect(&rect, style, false);
- g_window.handle = CreateWindowEx(
- 0,
- class_name,
- "Rocket Jump!",
- style,
- CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top,
- NULL,
- NULL,
- instance,
- NULL
- );
- assert(g_window.handle != INVALID_HANDLE_VALUE);
- center_window();
- g_window.dc = GetDC(g_window.handle);
- int pixel_attribs[] = {
- 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,
- WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
- WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
- WGL_COLOR_BITS_ARB, 32,
- WGL_DEPTH_BITS_ARB, 24,
- WGL_STENCIL_BITS_ARB, 8,
- #if m_multisample
- WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
- WGL_SAMPLES_ARB, 4,
- #endif
- 0
- };
- PIXELFORMATDESCRIPTOR pfd = {};
- pfd.nSize = sizeof(pfd);
- int format;
- u32 num_formats;
- check(wglChoosePixelFormatARB(g_window.dc, pixel_attribs, NULL, 1, &format, &num_formats));
- check(DescribePixelFormat(g_window.dc, format, sizeof(pfd), &pfd));
- SetPixelFormat(g_window.dc, format, &pfd);
- int gl_attribs[] = {
- WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
- WGL_CONTEXT_MINOR_VERSION_ARB, 3,
- WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
- // WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
- 0
- };
- HGLRC glrc = wglCreateContextAttribsARB(g_window.dc, NULL, gl_attribs);
- assert(glrc);
- check(wglMakeCurrent(g_window.dc, glrc));
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ window end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement