Zalo DS Blog

Monday, February 11, 2008

Painting in 2D using 3D (I)

Hi.

Well, now it is when I realize how annoying is to have a blog like this XDDD, why can't it just auto-update by itself... do I have to do everything :D? For those of you who think that I have abondoned DS homebrew I have something to say about it. I have been developing these moths, but I haven't updated the blog. And I think it is time to solve this. So I am going to explain deeply (well, more deeply than in previous posts) what I have been doing.

Let's begin with 2D stuff. For those of you not familiarized with the DS hardware you can think that it is stupid to write about painting in 2D using 3D. If you are familiarized with opengl then you know how to do that, and it is very simple:
1.- Call glOrtho and create a 2d View
2.- Paint a square with the texture you want to draw

As simple as this. And what happen with the DS then? Does this work? Well... hmm.. no. Why not? There are a few problems here.
1.- If you take a look at libnds implementation of glOrtho you can see the next line: MATRIX_MULT4x4 = divf32(inttof32(2), top - bottom); ; there is a division here. If you want to create a Canvas whose height has to be SCREEN_HEIGHT = 192 then you have a problem, because 2 / 192 = 0,010416666666666666666666... yes, one of those horrible numbers with infinite decimals. It doesn't matter if you use fixed point, it won't solve the problem

2.- Vertices format in DS is 4:12 so... What happen if you want to draw your texture
in (50, 50) for example? (remember that 4:12 range is -8 to 7)

Looking just to this two problems made me think if it was really possible to draw in 2D this way. What most games do is using the 2D capabilities of the DS in another layer and painting the sprites there... but this solution wasn't good for a multiplatform engine; and there is also the sprites size limitations this hardware have.

So, this was the problem. How can you solve this? See you on next post :D