-
February 8th, 2019, 11:32 AM
#1
Inverting axes in the back buffer
It's me again. The last time you explained to me well with my problem, I hope you will not refuse this time.
I want to invert the standard axes as in the traditional coordinate system .First I draw everything in the "back buffer" and then display it. But the text is mirrored, which is inconvenient to read.
Code:
void Draw()
{
HDC hdc = GetDC(m_hwnd);
RECT rect;
GetClientRect(m_hwnd, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
HDC hMemDC = CreateCompatibleDC(hdc);
HBITMAP hMemBitmap = CreateCompatibleBitmap(hdc, 500, 200);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hMemBitmap);
HBRUSH MemBrush = CreateSolidBrush(RGB(217, 171, 171));
SelectObject(hMemDC, MemBrush);
PatBlt(hMemDC, 0, 0, 500, 200, PATCOPY);
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, width, height, NULL);
SetViewportExtEx(hdc, width, -height, NULL);
SetViewportOrgEx(hdc, 0, height, NULL);
LineTo(hMemDC, 100, 100);
TextOut(hMemDC, 20, 30, "Hello world", 12);
BitBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, SRCCOPY);
SelectObject(hdc, hOldBitmap);
ReleaseDC(m_hwnd, hdc);
}
If the position of the axes is changed for the memory device context, then everything is displayed incorrectly and I do not understand why.
Code:
void Draw2()
{
HDC hdc = GetDC(m_hwnd);
RECT rect;
GetClientRect(m_hwnd, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
HDC hMemDC = CreateCompatibleDC(hdc);
HBITMAP hMemBitmap = CreateCompatibleBitmap(hdc, 500, 200);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hMemBitmap);
HBRUSH MemBrush = CreateSolidBrush(RGB(217, 171, 171));
SelectObject(hMemDC, MemBrush);
PatBlt(hMemDC, 0, 0, 500, 200, PATCOPY);
SetMapMode(hMemDC, MM_ISOTROPIC);
SetWindowExtEx(hMemDC, 500, 200, NULL);
SetViewportExtEx(hMemDC, 500, -200, NULL);
SetViewportOrgEx(hMemDC, 0, 200, NULL);
LineTo(hMemDC, 100, 100);
TextOut(hMemDC, 20, 30, "Hello world", 12);
BitBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, SRCCOPY);
SelectObject(hdc, hOldBitmap);
ReleaseDC(m_hwnd, hdc);
}
In the device context, everything is displayed as planned.
Code:
void Draw3()
{
HDC hdc = GetDC(m_hwnd);
RECT rect;
GetClientRect(m_hwnd, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, 500, 200, NULL);
SetViewportExtEx(hdc, 500, -200, NULL);
SetViewportOrgEx(hdc, 0, 200, NULL);
LineTo(hdc, 100, 100);
TextOut(hdc, 20, 30, "Hello world", 12);
ReleaseDC(m_hwnd, hdc);
}
How to make axes for the back buffer so that the image is displayed as in the function Draw3?
And help me understand. I change (0; 0) in the Draw function to (0; height) for the device context. Why is everything displayed in the upper left corner, if it should in the lower left?
-
February 10th, 2019, 11:35 AM
#2
Re: Inverting axes in the back buffer
Bitmaps in Win32 are usually up-side down.
See this article: https://docs.microsoft.com/en-us/win...bottom-up-dibs
-
February 10th, 2019, 01:51 PM
#3
Re: Inverting axes in the back buffer
Originally Posted by Marc G
Thank you very much for the article. However, it's still not clear how to fix the axes in the back buffer.
It is also not clear what the SetViewportOrgEx function does with the memory buffer. I mean this case.
Code:
SetMapMode(hMemDC, MM_ISOTROPIC);
SetWindowExtEx(hMemDC, 500, 200, NULL);
SetViewportExtEx(hMemDC, 500, -200, NULL);
SetViewportOrgEx(hMemDC, 0, 200, NULL);
The description says that it shifts the point (0; 0), but it doesn’t appear at all.
-
February 16th, 2019, 07:22 AM
#4
Re: Inverting axes in the back buffer
I am not programming with win GDI for a long time so i can't be 100% sure.
The function TextOut(hMemDC, 20, 30, "Hello world", 12); expects the origin (0,0) to be at the top left corner of the window.
As you are changing the origin before drawing the text you see wrong view.
When i was using OpenGL i faced with the same situation. glPush/glPop matrix function helped to solve that problem.
In your situation you can set origin back before drawing the text and set another after if you want to work in another axis set.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|