PocketMatrix forums

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

PocketFrog Framework Documentation Update

The PocketFrog Framework Documentation has been updated. Here is the link:

http://frog.flipcode.com/PocketFrog/docs_framework.html
Conan · 21 Jun 2002, 07:13 UTC — Thanks for the docs
Now wasn't that much more fun than playing Wolfenstein ?
I'm half way through my 3rd article on input & output. Things I still need to understand myself are:-
Clipping rectangle
Custom pixel shaders
Save any surface (including the back buffer) to a file (BMP)

I also don't know what the memory files are for.
Hehe... Yeah... Too much Wolfenstein gets boring =)


1) Clipping rectangle. Basically you can define the clipping rectangle and all rendering primitives will be clipped against this rectangle. The default rectangle is set to cover the entire size of the rendering target (surface). I am unsure how to properly explain this? Say you want to draw a line and one (or both) endpoint is outside the surface... The clipping rectangle will be used to properly cut the piece of line that will be visible. You can also use this to define where rendering is to take place on the surface. For example, SetClipping( Rect(10,10,40,40) will make this rectangle "drawable" and everything outside it won't be overdrawn by calls to the primitives.


2) Custom pixel shaders are used to define custom pixel blending effects. Say for example that you want to create an "Easy-CE infrared"-like effect: the idea is to only draw the RED channel of the color. You would first define a pixel shader:

Code:

struct InfraredShader : public PixelShader
{
Pixel operator()( Pixel src, Pixel dest ) const
{
return (src & RED_MASK);
}
};

Then you hand this to the rasterizer:

Code:

InfraredShader ir_shader;
GetDisplay()->SetPixelShader( &ir_shader );

Try it in the GameInit() function of the Blit() sample and you will see all rendering becoming red (the green/blue channels are dropped).

The PixelShader accepts two parameter: "src" and "dest" color. Basically, "src" is the source color specified to the primitive (line, circle, ...) and "dest" is the color already in the rendering target (backbuffer). The value returned is the final color that will be output to the rendering buffer.

The custom pixel shader is a really strong feature that begs to be exploited.


3) Saving a surface is as simple as calling the SaveImage() function. You specify the surface and the filename. For example, if you want to take a screenshot of your game, you would use:

Code:

SaveImage( GetDisplay()->GetBackBuffer(), _T("screen001.bmp") );


And voila! A screen shot named "screen001.bmp" will be created. By default, it will be placed in the same directory as your executable. If you want it somewhere else, you can specify the fullpath.

Hope this helps! I'm looking forward to your next articles!

Thierry
Conan · 21 Jun 2002, 08:06 UTC — clipping etc
Thanks, I understand clipping rectangles now I know what they are. One problem I have is the way things are named. I know the functionality but not the name used.

I will try out the custom shaders etc. Anything which makes a game cooler needs to be used.

Once I have tried everything I will start converting code from PocketC. Most code just needs a little tweek or a helper function as most of the syntax is the same. The major difference will be animation where I can do what I like without limits.

I had a quick look at my starfield code. All it needed was the addition of
Code:

DisplayDevice* display = GetDisplay();
Display->
to the setpixel function & it worked. Even though it uses floats it's far too fast :lol:
Forget to answer you about MemoryFile...

It is under the "Internal" namespace. Anything under "Internal" should not be used, will not be documented, and will not be supported. This namespace is used for implementation details and to experiment with new features when I don't like the interface.

Basically, MemoryFile is used internally to load files... But you should not use it as it will most probably change/disappear in the futur.