diff options
author | chai <chaifix@163.com> | 2020-02-22 23:33:06 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-22 23:33:06 +0800 |
commit | b656c9415a8e7e3b5b7d8bf1f3c8a5444f830c79 (patch) | |
tree | f4f0578d58e5f12b00d2753efef83aaedc03137e /src/extern/wog.c | |
parent | 9c89460e136ed6c6c43704d9a3a15105e0f006b0 (diff) |
*misc
Diffstat (limited to 'src/extern/wog.c')
-rw-r--r-- | src/extern/wog.c | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/src/extern/wog.c b/src/extern/wog.c index 7b8af8d..6cdfb6f 100644 --- a/src/extern/wog.c +++ b/src/extern/wog.c @@ -41,6 +41,7 @@ typedef struct wog_Window { HWND hwnd; // Window handler HDC hdc; // Device Context + HDC mdc; // Memory Device Contexts #if WOG_API == WOG_GDI wog_Surface* surface; // render buffer #endif @@ -280,18 +281,21 @@ static int registerWindowClass() return TRUE; } -static void create_surface(HWND handle, int width, int height, wog_Surface **out_surface, HDC *out_memory_dc) { +/* + * for memory device context, see + * https://docs.microsoft.com/en-us/windows/desktop/gdi/memory-device-contexts + * also + * SDL_windowsframebuffer.c WIN_CreateWindowFramebuffer + */ +static void create_surface(wog_Window* wnd, int width, int height) { BITMAPINFOHEADER bi_header; - HDC window_dc; HDC memory_dc; HBITMAP dib_bitmap; HBITMAP old_bitmap; unsigned char *buffer; // color buffer wog_Surface *surface; - window_dc = GetDC(handle); - memory_dc = CreateCompatibleDC(window_dc); - ReleaseDC(handle, window_dc); + memory_dc = CreateCompatibleDC(wnd->hdc); /*memory device contexts*/ memset(&bi_header, 0, sizeof(BITMAPINFOHEADER)); bi_header.biSize = sizeof(BITMAPINFOHEADER); @@ -300,8 +304,8 @@ static void create_surface(HWND handle, int width, int height, wog_Surface **out bi_header.biPlanes = 1; bi_header.biBitCount = 32; bi_header.biCompression = BI_RGB; - dib_bitmap = CreateDIBSection(memory_dc, (BITMAPINFO*)&bi_header, - DIB_RGB_COLORS, (void**)&buffer, NULL, 0); + /*create bitmap*/ + dib_bitmap = CreateDIBSection(memory_dc, (BITMAPINFO*)&bi_header, DIB_RGB_COLORS, (void**)&buffer, NULL, 0); assert(dib_bitmap != NULL); old_bitmap = (HBITMAP)SelectObject(memory_dc, dib_bitmap); DeleteObject(old_bitmap); @@ -312,8 +316,8 @@ static void create_surface(HWND handle, int width, int height, wog_Surface **out surface->channels = 4; surface->buffer = buffer; - *out_surface = surface; - *out_memory_dc = memory_dc; + wnd->surface = surface; + wnd->mdc = memory_dc; } @@ -342,30 +346,6 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in if (hasbit(flags, WOG_DISABLE)) windowStyle |= WS_DISABLED; DWORD windowExtendedStyle = WS_EX_APPWINDOW; // Define The Window's Extended Style - - PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be - { - sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor - 1, // Version Number - PFD_DRAW_TO_WINDOW | // Format Must Support Window -#if WOG_API == WOG_GL - PFD_SUPPORT_OPENGL | // Format Must Support OpenGL -#endif - PFD_DOUBLEBUFFER, // Must Support Double Buffering - PFD_TYPE_RGBA, // Request An RGBA Format - 32, // Select Our Color Depth - 0, 0, 0, 0, 0, 0, // Color Bits Ignored - 0, // No Alpha Buffer - 0, // Shift Bit Ignored - 0, // No Accumulation Buffer - 0, 0, 0, 0, // Accumulation Bits Ignored - 16, // 16Bit Z-Buffer (Depth Buffer) - 0, // No Stencil Buffer - 0, // No Auxiliary Buffer - PFD_MAIN_PLANE, // Main Drawing Layer - 0, // Reserved - 0, 0, 0 // Layer Masks Ignored - }; RECT windowRect = { 0, 0, width, height }; AdjustWindowRectEx(&windowRect, windowStyle, 0, windowExtendedStyle); width = windowRect.right - windowRect.left; @@ -379,7 +359,7 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in width, height, HWND_DESKTOP, 0, - GetModuleHandle(0), + GetModuleHandle(NULL), wnd ); @@ -398,10 +378,31 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in } #if WOG_API == WOG_GDI - create_surface(wnd->hwnd, client_w, client_h, &wnd->surface, &wnd->hdc); + create_surface(wnd, client_w, client_h); #endif #if WOG_API == WOG_GL + PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be + { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, // Version Number + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, // Must Support Double Buffering + PFD_TYPE_RGBA, // Request An RGBA Format + 32, // Select Our Color Depth + 0, 0, 0, 0, 0, 0, // Color Bits Ignored + 0, // No Alpha Buffer + 0, // Shift Bit Ignored + 0, // No Accumulation Buffer + 0, 0, 0, 0, // Accumulation Bits Ignored + 16, // 16Bit Z-Buffer (Depth Buffer) + 0, // No Stencil Buffer + 0, // No Auxiliary Buffer + PFD_MAIN_PLANE, // Main Drawing Layer + 0, // Reserved + 0, 0, 0 // Layer Masks Ignored + }; // set pixel format unsigned int pixelformat; pixelformat = ChoosePixelFormat(wnd->hdc, &pfd); @@ -465,13 +466,9 @@ void wog_destroyGLContext(wog_GLContext* cxt) #endif void wog_updateSurface(wog_Window* wnd) { - HDC window_dc = GetDC(wnd->hwnd); - HDC memory_dc = wnd->hdc; - wog_Surface *surface = wnd->surface; - int width = surface->width; - int height = surface->height; - BitBlt(window_dc, 0, 0, width, height, memory_dc, 0, 0, SRCCOPY); - ReleaseDC(wnd->hwnd, window_dc); + if(wnd->surface == NULL) return ; + int width = wnd->surface->width, height = wnd->surface->height; + BitBlt(wnd->hdc, 0, 0, wnd->surface, height, wnd->mdc, 0, 0, SRCCOPY); } void wog_destroyWindow(wog_Window* wnd) |