PocketMatrix forums

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

3D working, need to understand Pitch

My attempt to merge PocketFrog with PocketGL (PGL) has worked and I can render 3D objects correctly on my iPaq H3650.

I realised that PGL was only using bitmaps & HBITMAP in the final drawing stages so I skipped this & borrowed from BurningSheep's plasma demo to get the direct pixel access.

I understand from the plasma post that BurningSheep is not handling pitch correctly so on Casio the display is wrong. Can someone explain how pitch should be handled to ensure device independant drawing works?

Performance is reasonable & I have a rotating PGL mesh with a 2D sprite on top.

( ps: I don't understand swizzle / unswizzle in relation to the buffer lock & unlock so any info about this would help)

Note: PGL is a shareware product so while I can tell people what I did to merge PF & PGL I unfortunately cannot give out source code for PocketGL cause it's not mine to give. ( it's $49 )
Hi Conan,

I will break down your message in two questions:

Q1: What is the pitch and how to work with it?

A1: The pitch represents the offset in bytes between two row of pixels. A typical error is to use the width of the surface to calculate this offset (where the pitch should be used). You typically won't have to deal with the pitch until you want to use direct access. Basically, you Lock() a surface and the pitch is returned to you. Pixels are then addressed in the following manner:

Pixel(x,y) = (startOfBuffer) + y * pitch + x * 2


Q2: What is Swizzle()/Unswizzle()?

A2: Each device has a different screen orientation (ie: the actual display hardware is mounted sideway on the iPAQ36xx). In fact, the iPAQ36xx has a 320x240 pixels display (not a 240x320!). Doing "rotation" of the backbuffer in real time is slow. Because of this, PocketFrog pre-rotate all surfaces to match the hardware orientation. This is transparent: you draw on a surface using a rasterizer which takes care of this orientation for you.

When doing direct access (or GDI), PocketFrog will rotate the surface to a "normal" orientation by calling Swizzle(). When you have finished updating the surface, PocketFrog rotate the surface back to match the hardware, this is Unswizzle().

Now, there is no need to Swizzle() if you are going to overwrite all the pixels (ex: loading an image, rendering a 3D scene). In the same manner, there is no need to Unswizzle() if you didn't change any of the pixels. This is exposed in the appropriate methods (Lock, Unlock) by the "bDiscard" boolean.

Of course, if the display hardware orientation is already "normal", Swizzle() and Unswizzle() won't do anything (ie: no performance hit).
BurningSheep · 03 Aug 2002, 14:55 UTC
I'm still not getting the pitch, on my desktop pc, compiled under VC++ 6 this seems to work just fine:

Code:

Surface::LockInfo buffer;
m_hitarea->Lock(buffer, false);

int color = *(buffer.pixels + a_point.y * buffer.pitch /2 + a_point.x );

// Discard changes
bool Unlock( true );


however I can't get it to work properly on my iPAQ
I figured I would have to use this, but it doesn't work.

Code:

int color = *(buffer.pixels + a_point.y * buffer.pitch + a_point.x * 2);


What am I missing here?!?
Why do you use a different method on the iPAQ? The first piece of code should work on both PC and iPAQ...
BurningSheep · 03 Aug 2002, 18:31 UTC
The first method doesn't work on my iPAQ, I'm probably doing something funky. I'm going to try to figure it out later.
It just isn't my day I guess, ActiveSync doesn't even want to install anymore, so debugging on the device is also out of the question at the moment. :\