Author Topic: [NDS App] µLibrary  (Read 18213 times)

0 Members and 1 Guest are viewing this topic.

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
[NDS App] µLibrary
« on: March 21, 2007, 06:18:21 AM »
Here is my entry: µLibrary!

µLibrary is a new library for Nintendo DS. Basically, it is meant to use the 3D GPU to create nice 2D games very easily :)


Please visit this page for more information: http://brunni.palib.info/new/index.php?page=ndssoft_ulib

Here is a small list of functionalities provided by µLibrary:
  * Supported image formats: PNG, GIF, JPG
  * Special image effects: stretching, tinting (4 corners), mirroring, rotation (with a defined center), selection of an image frame to display (just like on spritesheets).
  * Can control both screens! (look at my site or the documentation for more information)
  * Compatible with PALib (can be used together in the same project) and integrates with programs already written with libnds. PALib or your own code can be used to control the second screen
  * Virtual file system: it is possible to load files independantly from the actual support (RAM, libFat, GBFS are supported by default, but you can define your own). Allows to create more easily software that are compatible with all existing linkers
  * Untextured geometry (rectangles, gradients, lines, etc.)
  * Basic message box system
  * VideoGL wrapper for texture and palette loading in VRAM: it is now possible to load and unload things dynamically. Furthermore, it is more flexible (you can choose which banks you want to use for what, etc.)
  * Keypad and touchscreen handler namely with support of stylus speed and double click and support of autorepeated keys (menus for example).
  * Includes 2 splash screens
  * Low level wrapper to draw primitives
  * Text system using the same font format as OSLib

Performance is good, one of the examples shows that an unoptimized C++ code that draws 400 balls bouncing on the screen uses less than 15% of CPU :D

Examples are supplied. The doxygen documentation is available here: http://brunni.palib.info/new/ulib/doc/doxygen/index.html

Some examples are directly downloadable there if you want to test them (please test them either on real DS or with no$gba):
http://brunni.palib.info/new/ulib/tmp/Example01b.rar
http://brunni.palib.info/new/ulib/tmp/Example09.rar

The source code will come in about a week, I just need to clean it a bit ;)
« Last Edit: March 21, 2007, 06:59:39 AM by Brunni »

Offline mollusk

  • Jr. Member
  • **
  • Posts: 82
Re: [NDS App] µLibrary
« Reply #1 on: March 21, 2007, 06:49:26 AM »
I haven't had the chance to test the lib itself, but I have been following it closely for the past few days, and have seen a few demos, and I can confirm it's a great piece of work :)

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
Re: [NDS App] µLibrary
« Reply #2 on: March 21, 2007, 07:06:04 AM »
Thanks :)
If you want to see what the code looks like, I post here a simple code, which loads a character from FAT and makes it follow the stylus :)

Code: [Select]
#include <ulib/ulib.h>

int main()
{
UL_IMAGE *imgChara;
   
//Initialize µLibrary
ulInit(UL_INIT_ALL);
//Initialize the graphical part
ulInitGfx();
//Initialize libFat
ulInitLibFat();

//Show some splash screens!
ulShowSplashScreen(1);
ulShowSplashScreen(2);

//We will use the touchscreen this time
ulSetMainLcd(0);

//Use bright pink as a transparent color
ulSetTransparentColor(RGB15(31, 0, 31));

//We load our 16-color character image from the active source (libFat here)
imgChara = ulLoadImageFilePNG("/chara.png", 0, UL_IN_VRAM, UL_PF_PAL4);

//Define the image center, so that the stylus will control the center of the image.
ulImageSetRotCenter(imgChara);

while(1)
{
//Read keys
ulReadKeys(0);
   
//We place our character to the same position as the touchscreen stylus, making it follow it
imgChara->x = ul_keys.touch.x;
imgChara->y = ul_keys.touch.y;
   
//Start our drawing
ulStartDrawing2D();

//Draw a gradient background
ulDrawGradientRect(0, 0, 256, 192, RGB15(0, 0, 24), RGB15(0, 0, 0), RGB15(0, 0, 0), RGB15(0, 0, 24));

//Draw our cuty character on the screen!
ulDrawImage(imgChara);

//End the drawing
ulEndDrawing();

//Wait the VBlank (synchronize at 60 fps)
ulSyncFrame();
}

return 0;
}

Offline kodea

  • Newbie
  • *
  • Posts: 2
Re: [NDS App] µLibrary
« Reply #3 on: March 22, 2007, 10:26:42 AM »
you should get bonus points for using james pond art.

i remember travelling the memory bitplanes on AR in the AMIGA seeking those sprites.

kickass game :)

Offline theNinjaBunny

  • Newbie
  • *
  • Posts: 10
Re: [NDS App] µLibrary
« Reply #4 on: March 22, 2007, 11:33:58 PM »
This is ..... aWeSoMe!!  :-* :-*

PALib+(micra)Library =   ??? ??? (me going crazy)

I have a little problem, playing with this example i try to load a png from fat but colors... they were messed (perhaps not, the image has a lot of gray and that appeared as black)

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
Re: [NDS App] µLibrary
« Reply #5 on: March 23, 2007, 02:16:17 AM »
Thanks, that's very nice of you :)

For your problem, I think the problem is about the pixel format; notice the arguments to ulLoadImageFile:
imgChara = ulLoadImageFilePNG("/chara.png", 0, UL_IN_VRAM, UL_PF_PAL4);
The UL_PF_xxxx specifies the pixel format: PAL4 is paletted, 4 bits per pixel. The limit in this mode is 15 colors (+1 transparent), so if your image has more than 15 colors, it will actually appear as messed up :(
You should upgrade to UL_PF_PAL8 (256 colors), however it will cost twice the memory, something you should think about if you have a big game with a lot of sprites ;)
If your image has even more than 256 colors or is of JPG format, you'll have to use the UL_PF_5551 or 5550 formats, which are true-color :)
The best thing is to use gif or png formats and use as few colors as possible to have a lot of memory available for a large number of images at once ^^

Please see the documentation about image loading routines if you want more information ;)
« Last Edit: March 23, 2007, 02:24:18 AM by Brunni »

Offline theNinjaBunny

  • Newbie
  • *
  • Posts: 10
Re: [NDS App] µLibrary
« Reply #6 on: March 23, 2007, 02:55:35 AM »
Thanks, perhaps you should open a thread at PALib forums or somewhere else (i'll have a lot of questions!!)

And for memory,... is for a GPS app, in the worst case i have to load 4 png's of 256x256px each one one top screen. So, i think i'll be fine with a lot of colors ^^  ::sm-18.gif:: ::sm-18.gif::

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
Re: [NDS App] µLibrary
« Reply #7 on: March 23, 2007, 03:11:03 AM »
Now I think about something which is written in the doc but not clearly stated: by default you have 128 kilobytes of memory available for images, it was done in order to let as much memory available for other libs. But if you are using PALib, you can get 128 more kilobytes by allocating the bank B to µLibrary (just search about ulSetTexVramParameters in the doxygen documentation). :)

4 [images] x 256x256 [pixels] x 8 [bits per pixel] = 2 Mbits = 256 kBytes.
This is clearly too much.
 1) Do you really need 256x256 images? Wouldn't 256x192 be enough? With µLibrary, unlike with libnds, image height does not have to be a power of two ;)
 2) Do you really need all 4 loaded in VRAM at the same time? You can move them from RAM <=> VRAM everytime you want with ulRealizeImage/ulUnrealizeImage ::sm-19.gif::
 3) Use lower color depth (4 bits), it will fit in 128k and you'll just have to apply the hint above to get 256 kB ;)

PS: I should effectively open a thread somewhere, I haven't got any for now (except here), so please post here meanwhile 8)
« Last Edit: March 23, 2007, 03:13:57 AM by Brunni »

Offline theNinjaBunny

  • Newbie
  • *
  • Posts: 10
Re: [NDS App] µLibrary
« Reply #8 on: March 23, 2007, 03:19:03 AM »
256x256 its not my decision, it comes from googlemaps, who uses square tiles.

The reason for 4 images, is that think if you are in the (0,0) of a tile, i have to load the three tiles next to it in order to get "well positioned" in the map.

For me is easier to modify the images (don't know what to do with satellites ones) and get them using UL_PF_PAL4.

Thanks (again)

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
Re: [NDS App] µLibrary
« Reply #9 on: March 23, 2007, 03:26:34 AM »
It is possible to dynamically reduce the number of colors. Search about octree: it gives good results and is quite fast IIRC.
But anyway if I understood correctly, you'd have to load images in diagonal as well... that is 9 images in total:
0 1 2
3 H 5
6 7 8
With H being me. Am I wrong?

Offline theNinjaBunny

  • Newbie
  • *
  • Posts: 10
Re: [NDS App] µLibrary
« Reply #10 on: March 23, 2007, 03:43:57 AM »
Yes, you are wrong

Images are 256x256
Screen is 256x192

A - If you are in the middle of a tile, the tile is greater than the screen so only one tile to load.

B - If you move to left (for example) you have to load two tiles.

C - If you move to a corner you have to load 4 images


Yeah! I'm the paint master!

Offline Brunni

  • Jr. Member
  • **
  • Posts: 96
Re: [NDS App] µLibrary
« Reply #11 on: March 25, 2007, 10:12:59 PM »
I've opened a forum for µLibrary!
You can access it from here: http://www.playeradvance.org/forum/forumdisplay.php?f=103
Don't hesitate to ask your questions here :) It's a french forum but you can speak in english without problem ;)
If you've got any problem with the library, a bug report, and so on, you know where to go ;)

theNinjaBunny> Okay, sorry :)

Offline theNinjaBunny

  • Newbie
  • *
  • Posts: 10
Re: [NDS App] µLibrary
« Reply #12 on: March 26, 2007, 01:00:10 AM »
bookmarked  ;D ::sm-29.gif::

I'm supossed to speak french,because i've study it for some years at a high level. Right now it's 5 years since i haven't speak it or write it so ... my french is terrible, like Godzilla taking tea with your sister's puppets.

Offline 0xtob

  • Newbie
  • *
  • Posts: 22
Re: [NDS App] µLibrary
« Reply #13 on: April 04, 2007, 01:01:33 AM »
Hey Brunni!

Sorry to post here, but I'm unable to register at your forum.

First off, great work with uLib! I'm impressed with the simplicity and all the features like support for multiple image formats, file systems etc. Really great job! (You got my vote by the way)

I'm currently experimenting with it a bit and I'm trying to load an image (PNG) with semitransparent pixels. I'm using the UL_PF_PAL5_A3 mode. When I try to display the image, however, it doesn't show up at all. When I use UL_PF_PAL8, the image is displayed and the fully transparent regions are fully transparent, but of course there's no semi-transparency, which is what I want.

Is there anything else I need to do or is this mode not useable yet?

Anyway, keep up the great work!
Tob

Offline Dr.Vince

  • Newbie
  • *
  • Posts: 2
    • PlayerAdvance
Re: [NDS App] µLibrary
« Reply #14 on: April 05, 2007, 08:21:41 PM »
Sorry to post here, but I'm unable to register at your forum.

Hi, can you tell me why you can't register you at our forum ??