Simple Double-Buffering OpenGL Context Creation with Win32 (C/C++ on Windows)

preview_player
Показать описание
Create an OpenGL rendering context for the device context of a Win32 window that supports double-buffering using SwapBuffers, GetDC, ChoosePixelFormat, DescribePixelFormat, SetPixelFormat, wglCreateContext, wglMakeCurrent2, SetWindowLongPtr, SetLastError, wglDeleteContext, ReleaseDC, GetWindowLongPtr.

Chapters
0:00 Why Create a Simple OpenGL Context in 2023
1:32 Changes to the WinMain Function
3:40 Double-Buffering and SwapBuffers Function in Detail
6:57 Changes to the WndProc (Window Procedure)
8:37 Handling the WM_CREATE Message
13:01 Handling the WM_DESTROY Message
14:38 Creating an OpenGL Context using wglCreateContext
16:04 Selecting a Frame Buffer for the Device Context Using SetPixelFormat
20:30 Running the OpenGL Application Showing an Empty Window from the Front and Back Buffers
21:13 Outlook on Proper OpenGL Context Creation
Рекомендации по теме
Комментарии
Автор

Amazing videos! It'd be very nice if you kept making more windows-related videos. Some questions related to this video and also the last one:
- Is it important to manage resources ourselves? The gotos are sequential and just before exiting winMain. Doesn't that mean all allocated resources would be released by the OS upon exit?
- In the CMakeLists you define UNICODE and _UNICODE. Is this so that you don't need to do #define UNICODE and #define _UNICODE in the code? I thought calling the "W" versions explicitly we didn't need to define these. From what I gathered online they are helpful to ditch the "W" when calling functions with several implementations, and it'll pick that version as the default. But I'm confused since you do write out the "W".
- How would you go about error handling the C++ way?
- In the github repo I see you added DescribePixelFormat(hDC, format, sizeof pfd, &pfd) != 0 to the return of SetupPixelFormat. What's this for?

Pedro-jjgp