gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > textured_quad

#163176 - sverx - Wed Sep 24, 2008 3:30 pm

In this post, Sausage Boy wrote:
The textured_quad example in devkitPro should be a great starting point. Or, optionally, this, which is the same example, but with a paletted texture. You'll want to get rid of GL_TEXTURE_COLOR0_TRANSPARENT if you decide to use that though.


I made a search on that forum and I found NeHe's tutorial: I'm reading it because I really don't even know what OpenGL is! I'm reading lesson 1 and -even if the tutorial seems well written- I guess it's too soon to say I understand what I'm reading...
Yes, I noticed the textured_quad example: I gave a look to it but it was before, so I really didn't understand any of the few lines of code. :|
Anyway I'll also give a look to your link -later-, thanks :)

Sausage Boy wrote:
Now, you need to set 3D up so one pixel on the texture maps exactly to one pixel on the screen. This is done through orthographic projection. Replace glViewport with something like this
Code:
glOrthof32(0, 256, 0, 192, -1, 1)

This means the screen will go from 0 to 256 horizontally in 3D space, and 0-192 vertically (obviously).


That's good, in fact I need to 'drive' pixels on the screen changing texels (right?) on the texture so that they corresponds.

Sausage Boy wrote:
It also sets the near clipping plane to -1, and the far clipping plane to 1. Anything in between will get drawn. Orthographic projection means we don't care about how far away something is from the camera, everything is drawn at the same size.


So it's ok if my quad has the 4 corners all with Z=0, right?

Sausage Boy wrote:
All you need to do now is put a quad with your texture in there, and update it every frame.


Right. Well, I've got to decide if it's better to use one big texture (256x256) or some smaller textures to save some memory... it shouldn't be hard to show some 12 (4x3) textures each 64x64, right?

Sausage Boy wrote:
The greatest reference for all this is GBATEK. It might look complicated at first, but it really pays off when you get used to it.


Thanks, it's one of my preferred, but it isn't good for a topic where I'm a complete beginner ;)

Thanks :)

#163190 - Sausage Boy - Wed Sep 24, 2008 9:16 pm

Wow, you're a great beginner. Everything you say sounds sane and correct. :)
_________________
"no offense, but this is the gayest game ever"

#163197 - TwentySeven - Thu Sep 25, 2008 2:48 am

Quote:
glOrthof32(0, 256, 0, 192, -1, 1)



should be

glOrthof32(0, 255, 0, 191, -1, 1)

right?

#163211 - Sausage Boy - Thu Sep 25, 2008 12:43 pm

TwentySeven wrote:
Quote:
glOrthof32(0, 256, 0, 192, -1, 1)



should be

glOrthof32(0, 255, 0, 191, -1, 1)

right?


Hm, I don't think so actually. I have no idea why it is like that, but I'm pretty sure that the other values create the intended result.

Also, it turns out I lied. gluPerspective() is what needs to be replaced, not glViewport().
_________________
"no offense, but this is the gayest game ever"

#163215 - sverx - Thu Sep 25, 2008 3:31 pm

Hi there :)
I started experimenting on the textured_quad example because I need to understand a lot of things before going on with the effect I want to achieve.

First I tryed changing this:
Code:
gluPerspective(70, 256.0 / 192.0, 0.1, 40);

with this:
Code:
glOrthof32(0, 256, 0, 192, -1, 1)

as Sausage Boy suggested.

The quad disappeared from the screen. In the example, if I understood it right, (and I hope so) the program draws a quad with 4 vertices:

(-0.5,-0.5,0) - (0.5,-0.5,0) - (0.5,0.5,0) - (-0.5,0.5,0)

so I thought I had to change glOrthof32() parameters, so now it's
Code:
glOrthof32(-128, +128, -96, +96, -1, +1);

but the quad didn't reappear :|

I'm keeping on reading and reading codes & examples & tutorials... by the way in the while if someone of you has an idea about why this quad doesn't show up... it's welcome :)

Thanks :)

#163518 - Cydrak - Sat Oct 04, 2008 1:24 am

sverx wrote:
[well, there's still an open question about the orthographic projection in this very same topic...]

Oh! Sorry, I hadn't realised that.

Hmm... one thing to watch for is floats vs. fixed point. The "3f" or "f" functions take floats, while "f32" (like glOrthof32, and in fact the DS itself) want 20.12 fixed point. Functions like "glVertex3v16" (4.12) and "glNormal" (three packed 0.10's) take yet other formats. No, I can hardly remember what's what either. :-)

So in practice the floats are *usually* multiplied by 0x1000 (= 1<<12, or 4096). A value like 0.5 becomes 0x00000800 in the eyes of the "f32" functions. If the projection is only (0x100, 0x0c0), such a quad will be bigger than expected!

If you're after an OpenGL guide, you can also have a look at the Red Book. Lengthly, but also full of examples. It's not DS-specific, of course, so much of it could be skipped. But the general concepts such as the viewport, transformations and matrix stacks, lighting, materials and textures are largely relevant.

#163886 - sverx - Tue Oct 14, 2008 2:40 pm

Back again, sorry, I was busy these days...

Cydrak wrote:
Hmm... one thing to watch for is floats vs. fixed point. The "3f" or "f" functions take floats, while "f32" (like glOrthof32, and in fact the DS itself) want 20.12 fixed point.


Aw, I didn't notice that... btw I changed the code in the textured_quad example so that my figures would be left shifted by 12 bits, like that:

Code:
glOrthof32(-128<<12, +128<<12, -96<<12, +96<<12, -1<<12, +1<<12);


but I still can't see that quad :| And it's strange because the quad it's the same, it has these vertices
(-0.5,-0.5,0) - (0.5,-0.5,0) - (0.5,0.5,0) - (-0.5,0.5,0)

any idea? (and can we split this parts from the topic?)

Thanks! :)