PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Tips & help to convert 3D to work in PocketFrog

As a registered user of PocketGL ( a shareware 3D toolkit $49 ) and a user of PocketFrog I have started to look at how to merge both toolkits. Obviously anything I do can only be of real use to people who have registered PocketGL as I can't rip off Pierre's source & give it away.

PocketGL creates an offscreen bitmap as it's back buffer & has it's own GAPI which works for the iPaq 36/38 & Casio devices only. The bitmap is created as:-
Code:
// Create the offscreen bitmap used as a secondary surface to build next image.
OffscreenBitmap.bmWidth = DISP_X;
OffscreenBitmap.bmHeight = DISP_Y;
OffscreenBitmap.bmBitsPixel = 16;
OffscreenBitmap.bmPlanes = 1;
OffscreenBitmap.bmBits = NULL; // (unsigned short *)malloc(DISP_X * DISP_Y * 2);

The contents of this buffer are then blitted to the screen as required once all the 3D rendering has been done.

My questions are inter-related.
1. Can this bitmap buffer be Blitted in it's current form using PocketFrog's display update function
2. if not & I create a surface 240 x 320 what do I need to know about a PF surface to allow me to re-write the function which sets the pixels in bitmap so it will write correctly to a surface.
3. Would I be able to simply utilise the existing code having removed it's GAPI initialisation stuff leaving PocketFrog's GAPI untouched?

Note: I'm still working out how the code works as I have only used the 3D functions up till now & not looked at the engine. There is a Z-Buffer in use which I still dont understand fully but it looks like it's controlling how deep into the screen to draw.

I'm planning to use the original version of PocketGL as it's simpler than later versions so I have less stuff likely to conflict.
Hi Conan,

Blitting a bitmap to the backbuffer is a piece of cake:

HBITMAP hBitmap = ...
HDC hdc = display->GetBackBuffer()->GetDC());
Blit( hdc, ...)
display->GetBackBuffer()->ReleaseDC();

Or something close to that...

BTW, I just received my J720, I will add support as soon as I have some time.
Conan · 06 Jul 2002, 06:38 UTC — 3d and Jornada 720's
Thanks for the pointer re: Bliting bitmaps.
Once I have posted my next article ( it's 99% done but I keep tweeking the code ) I will settle down to try getting the 3D in. Assuming it works well it will actually improve PocketGL as it currently has no high level 2D.

Good news about your Jornada. Looking forward to seeing PocketFrog on J710/720
Conan · 09 Jul 2002, 14:01 UTC — What's an HBITMAP
Ive managed to combine all the source & get it to build cleanly in only 1 hour so I'm very pleased so far.
I can execute both the 3D init & game loop functions leaving me with Blitting the data but I don't know how to get the BITMAP into the correct format.
To start with I don't know what HBITMAP is supposed to do. I can see a sample in the help but it does not make things clearer. What do I need to do to a BITMAP using HBITMAP ????

HBITMAP hBitmap = ...


Once I get past this I just need to figure out the Z-buffer & I will reach running code.

Thanks in advance
What does PocketGL provides you with? I though it was giving you a HBITMAP, but it seems from your last message that this is not the case?

What do you have to work with?
Conan · 09 Jul 2002, 19:04 UTC — PocketGL Bitmaps
it (PocketGL) does use an HBITMAP for it's 'PC' mode and a BITMAP for the GAPI mode. I took out the GAPI approach & changed over to the HBITMAP method but I can't get Blit to use the HBITMAP directly. I will post the error message I get later & also look at your sample code again.

I will post the little bit of blit code from PocketGL as this will probably explain things better.

( I'm actually very happy that both packages are working together as I expected mega conflicts )
Conan · 09 Jul 2002, 21:34 UTC — code from PocketGL's display
Here's the code. I was latterly trying to give Blit the HBITMAP defined near the end

//**** from the display.h
extern BITMAP OffscreenBitmap;
//******** from the display.cpp
BITMAP OffscreenBitmap;

#ifdef GAPI
#include "..\\gapi\\arm\\gx.h"
GXDisplayProperties DisplayProperties;
#else
HBITMAP hOffscreenBitmap;
HDC hDCMem;
#endif

// ----------------------
// Display initialisation
unsigned char DISPLAYinit(HWND hWnd)
{
#ifdef GAPI
GXOpenDisplay(hWnd, GX_FULLSCREEN);
DisplayProperties = GXGetDisplayProperties();

// Create the offscreen bitmap used as a secondary surface to build next image.
OffscreenBitmap.bmWidth = DISP_X;
OffscreenBitmap.bmHeight = DISP_Y;
OffscreenBitmap.bmBitsPixel = 16;
OffscreenBitmap.bmPlanes = 1;
OffscreenBitmap.bmBits = NULL; // (unsigned short *)malloc(DISP_X * DISP_Y * 2);



#else // code pc

long Data[256];
unsigned long *ColorMask;
BITMAPINFO *BitmapInfo;
HDC hDC = GetDC(hWnd);

// For Win32, create a DIB section compatible with original main game window DC.
BitmapInfo = (BITMAPINFO *)Data;
BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo->bmiHeader.biBitCount = 16;
BitmapInfo->bmiHeader.biWidth = DISP_X;
BitmapInfo->bmiHeader.biHeight = -DISP_Y;
BitmapInfo->bmiHeader.biPlanes = 1;
BitmapInfo->bmiHeader.biCompression = BI_BITFIELDS;
BitmapInfo->bmiHeader.biSizeImage = DISP_X * DISP_Y * 2;
BitmapInfo->bmiHeader.biClrUsed = 0;
BitmapInfo->bmiHeader.biClrImportant = 0;
BitmapInfo->bmiHeader.biXPelsPerMeter = 0;
BitmapInfo->bmiHeader.biYPelsPerMeter = 0;
ColorMask = (unsigned long *)&BitmapInfo-;>bmiColors[0];
ColorMask[0] = 0xF800;
ColorMask[1] = 0x7E0;
ColorMask[2] = 0x1F;
hOffscreenBitmap = CreateDIBSection(hDC, BitmapInfo, DIB_RGB_COLORS, &OffscreenBitmap.bmBits;, NULL, 0);
OffscreenBitmap.bmWidth = DISP_X;
OffscreenBitmap.bmHeight = DISP_Y;
OffscreenBitmap.bmBitsPixel = 16;
OffscreenBitmap.bmPlanes = 1;

// And create a memory DC used to blit offscreen bitmap to main window.
hDCMem = CreateCompatibleDC(hDC);
ReleaseDC(hWnd, hDC);
#endif
return(1);
}


//****** DISPLAY UPDATE CODE FOR PC version
#else // code for PC
HBITMAP OriginalBitmap;

OriginalBitmap = (HBITMAP)SelectObject(hDCMem, hOffscreenBitmap); // Blit from memory DC to game window DC.
unsigned short *VirtualScreen = (unsigned short *)OffscreenBitmap.bmBits;

for (int i=0; i<DISP_X*DISP_Y; i++)
{
VirtualScreen[i] = VScreen[i];
VScreen[i] = 0;
ZBuffer[i] = FAR_CLIP;
}

BitBlt(hDC, 0, 0, DISP_X, DISP_Y, hDCMem, 0, 0, SRCCOPY);
SelectObject(hDCMem, OriginalBitmap);