Wie verwende ich GETRAWFRAMEBUFFER ? (gapi und VGA auf PocketPC)
-
Hallo
ich befasse mich gerade mit der Grafikprogrammierung auf dem PocketPc. Bin dabei auf die gapi gestoßen und möchte sie mit VGA-Auflösung nutzen.
Wenn ich qvga benutze funktioniert auch alles super, nur wenn ich - wie nach dieser Anleitung auf VGA umschalte - bekomme ich fehler.Link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppcgen/html/dpi_awareness.asp
VGA habe ich, nur bekomme ich die gapi nicht mit Fullscreen.
Laut dem Link soll GETRAWFRAMEBUFFER benutzt werden und zwar mit folgendem Code:
#define GETRAWFRAMEBUFFER 0x00020001 #define FORMAT_565 1 #define FORMAT_555 2 #define FORMAT_OTHER 3 typedef struct _RawFrameBufferInfo { WORD wFormat; WORD wBPP; VOID *pFramePointer; int cxStride; int cyStride; int cxPixels; int cyPixels; } RawFrameBufferInfo; // ... RawFrameBufferInfo rfbi; HDC hdc = GetDC(NULL); ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); ReleaseDC(NULL, hdc);Hab nun schon ein wenig versucht, ich bekomme es leider nicht hin. Kann mir jemand von euch helfen?
Hier mein Programm:
#define GETRAWFRAMEBUFFER 0x00020001 #define FORMAT_565 1 #define FORMAT_555 2 #define FORMAT_OTHER 3 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <windows.h> #include <wingdi.h> #include <gx.h> #include <winuserm.h> #include <aygshell.h> #include "bitmaps.h" // Defines // // Some handy globals that are fine for a sample app. // GXDisplayProperties g_gxdp; // GX struct GXKeyList g_gxkl; // GX struct BOOL g_fPause = FALSE; // paused or not BOOL g_bFullScreen = TRUE; BYTE *g_pMainBuffer = NULL; HINSTANCE g_hInstance = 0; HDC hdc; HWND hWnd, hWndFullScreenButton, hWndDescriptionText; DWORD g_dwLastMouseClick = 0; typedef struct _RawFrameBufferInfo { WORD wFormat; WORD wBPP; VOID *pFramePointer; int cxStride; int cyStride; int cxPixels; int cyPixels; } RawFrameBufferInfo; const int gcBitsPerByte = 8; BOOL g_bOrientation = PORTRAIT; long g_wKeyLoc[MAX_BUTTONS][2][MAX_ORIENTATION]; // ex : [UP][X][PORTRAIT] BOOL g_bKeyInverted[MAX_BUTTONS]; int x1=0,y1=0; // // Forward declarations. // ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass); BOOL InitInstance(HINSTANCE hInstance, int nCmdShow); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); BOOL ClearScreen(); void DrawRect(); void FillLocations(BOOL); void DrawButtons(BOOL); void DrawBitmap(DWORD *, WORD, WORD, long, long, BOOL); void DrawViereck(); void DrawLine( int lOrigX, int lOrigY, int lDestX, int lDestY ); // // Code Body // int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { MSG msg; // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } // Main message loop. while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // ATOM MyRegisterClass( HINSTANCE hInstance, LPTSTR szWindowClass ) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = szWindowClass; return RegisterClass(&wc); } BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ) { TCHAR szTitle[] = L"GXSample"; // The title bar text TCHAR szWindowClass[] = L"GXSample"; // The window class name BOOL bDRAMBuffer; INT iScreenWidth = GetSystemMetrics(SM_CXSCREEN); INT iScreenHeight = GetSystemMetrics(SM_CYSCREEN); // IMPORTANT: see if this app is already running. If so just bring // it to the front and quit. All CE apps need to do this. g_hInstance = hInstance; hWnd = FindWindow(szWindowClass, szTitle); if (hWnd) { SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01)); return 0; } MyRegisterClass(hInstance, szWindowClass); // In order to create a full screen app CreateWindow() needs to be // called with absolute coordinates that cover the entire display. // Using CW_USEDEFAULT will not work correctly. hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } if (GXOpenDisplay(hWnd, GX_FULLSCREEN) == 0) { return FALSE; // we won't be able to draw. } if (GXIsDisplayDRAMBuffer()==FALSE ) return FALSE; //if (GXSetViewport(0, 260, 0, 0)==0) return FALSE; GXSetViewport(0, 640, 0, 0); GXOpenInput(); g_gxdp = GXGetDisplayProperties(); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; short vkKey; switch (message) { case WM_COMMAND: break; case WM_CREATE: break; case WM_ACTIVATE: { //BOOL bActivating = LOWORD(wParam) != WA_INACTIVE; if (WA_INACTIVE == LOWORD(wParam)) { // Always, always call GXSuspend() here. GXSuspend(); } else { // And always call GXResume() here. GXResume(); PostMessage(hWnd, WM_PAINT, 0, 0); } break; } case WM_KILLFOCUS: break; case WM_SETFOCUS: break; // If your app can only draw directly to the screen then you need to make // sure it is frontmost before drawing. case WM_PAINT: hdc = BeginPaint(hWnd, &ps); g_pMainBuffer = (BYTE*)GXBeginDraw(); ClearScreen(); DrawLine(0,0,200,200); GXEndDraw(); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: PostMessage(hWnd, WM_CLOSE, 0,0); break; case WM_DESTROY: GXCloseInput(); GXCloseDisplay(); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } void GameXSetPixel( WORD nX, WORD nY, DWORD color ) { DWORD byteIndex; byteIndex = (DWORD)(nY * g_gxdp.cbyPitch) + (nX * g_gxdp.cbxPitch); if (g_gxdp.ffFormat & kfDirectInverted) { color = ~color; } switch (g_gxdp.cBPP) { case 1: // Mask off the appropriate 1 bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0x80 >> ((nX & 0x07))); g_pMainBuffer[byteIndex] |= ((color & 0x01) << 8) >> ((nX & 0x07)); break; case 2: // Mask off the appropriate g_gxdp.cBPP (2) bits, then or it in from the color. g_pMainBuffer[byteIndex] &= ~(0xC0 >> ((nX & 0x03) * g_gxdp.cBPP)); g_pMainBuffer[byteIndex] |= ((color & 0x03) << 6) >> ((nX & 0x03) * g_gxdp.cBPP); break; case 4: // If the nX is even the top g_gxdp.cBPP (4) bits need to be set. g_pMainBuffer[byteIndex] &= 0x0F << ((nX & 0x01) * g_gxdp.cBPP); g_pMainBuffer[byteIndex] |= (color & 0x0F) << ((!(nX & 0x01)) * g_gxdp.cBPP); break; case 8: g_pMainBuffer[byteIndex] = (BYTE)color & 0xFF; break; case 16: *(WORD*)(&g_pMainBuffer[byteIndex]) = (WORD)color & 0xFFFF; break; case 32: *(DWORD*)(&g_pMainBuffer[byteIndex]) = color; break; } } // // 0 clears the screen to black. // any other value clears the screen to a random value. // BOOL ClearScreen() { BYTE color = 0; if (g_gxdp.ffFormat & kfDirectInverted) { color = ~color; } for (WORD x=0; x<g_gxdp.cxWidth; x++) for (WORD y=0; y<g_gxdp.cyHeight; y++) { GameXSetPixel(x, y, color); } return FALSE; } void DrawViereck() { for (int x2=0;x2<5;x2++) for (int y2=0;y2<5;y2++) { for (int a=0;a<20;a++) { for (int b=0;b<20;b++) { GameXSetPixel(x1+a+10+(x2*21),y1+b+10+(y2*21),(x2+4)*666); } } } } void DrawLine( int lOrigX, int lOrigY, int lDestX, int lDestY ) { //int dX = abs( lDestX-lOrigX ); // store the change in X and Y of the line endpoints //int dY = abs( lDestY-lOrigY ); int dX, dY; int CurrentX = lOrigX; // store the starting point (just point A) int CurrentY = lOrigY; // Draw none if all point outside the screen... //if( IsPointOutside( lOrigX, lOrigY ) && IsPointOutside( lDestX, lDestY ) ) return TRUE; int Xincr, Yincr; if( lOrigX > lDestX ) { Xincr=-1; dX = lOrigX - lDestX; } else { Xincr=1; dX = lDestX - lOrigX; } // which direction in X? if( lOrigY > lDestY ) { Yincr=-1; dY = lOrigY - lDestY; } else { Yincr=1; dY = lDestY - lOrigY; } // which direction in Y? if( dX >= dY ) // if X is the independent variable { int dPr = dY << 1; int dPru = dPr - ( dX << 1 ); int P = dPr - dX; for ( ; dX >= 0; dX -- ) { GameXSetPixel( CurrentX, CurrentY, RGB(255, 0, 0) ); if (P > 0) { CurrentX += Xincr; CurrentY += Yincr; P += dPru; } else { CurrentX += Xincr; P += dPr; } } } else { int dPr = dX << 1; int dPru = dPr - ( dY << 1 ); int P = dPr - dY; for( ; dY >= 0; dY -- ) { GameXSetPixel( CurrentX, CurrentY, RGB(0, 255, 255) ); if ( P > 0 ) { CurrentX += Xincr; CurrentY += Yincr; P += dPru; } else { CurrentY += Yincr; P += dPr; } } } return; }Ich danke euch schon mal!
-
Kann mir jemand von euch helfen?
Wobei?
-
To bypass the emulation layer, an application should not call GXBeginDraw or GXEndDraw. Instead, it should call ExtEscape with the nEscape parameter equal to GETRAWFRAMEBUFFER and use the returned frame pointer for drawing.
Wenn ich es richtig verstehe soll ich
g_pMainBuffer = (BYTE*)GXBeginDraw();durch
RawFrameBufferInfo rfbi; HDC hdc = GetDC(NULL); ExtEscape(hdc, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char *) &rfbi); ReleaseDC(NULL, hdc);ersetzen.
Nur bekomme ich das nicht hin bzw. weiß nicht wie es gemeint ist.