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 > Tips and warnings for using 3D Engine

#121747 - Lick - Wed Mar 14, 2007 2:28 pm

A topic to collect general knowledge for people using 3D Engine.

My tips:

- If you want to use a texture with alphabits, make sure that you disabled anti-aliasing(incorrect) and have rendered a polygon behind it. If there's no polygon behind it, all pixels with alpha will be entirely invisible. [related to silent_code's tip about glClearColor]

- If you want to modulate texture color with vertex color, use glMaterialf(GL_EMISSION, RGB15(31,0,0));. Here, the texture will be modulated with red. Default should be 0x7FFF (white).
I use this for my font rendering. ;D

[edit]spelling..
_________________
http://licklick.wordpress.com


Last edited by Lick on Thu Mar 15, 2007 11:41 pm; edited 3 times in total

#121749 - simonjhall - Wed Mar 14, 2007 2:37 pm

Good idea! A tips thread would be teh bonze.

Here's me:
When you draw a transparent poly, the poly you draw behind it needs a different poly id (I'm sure)... Never had a problem with AA and transparency though!

Polygons with different ids give a cool edge-detected/wireframe look. For example, if I render a scene like normal but change the polygon id for ever poly, the scene gets rendered (like normal) but a wireframe gets overlaid onto the image on poly boundaries. Looks cool :-)

I've found that if you exceed the polygon limit then there's a good chance you'll get seriously weird graphical corruption (not just invisible polys). So avoid.
_________________
Big thanks to everyone who donated for Quake2

#121850 - silent_code - Thu Mar 15, 2007 8:19 am

@Lick: this is a great idea!

- if you get wierd looking textures, try swapping the uvs.

- to set the propper clear color, don't use the function glClearColor(...) provided by libnds (true for realease 20 and preceeding), but set it in GFX_CLEAR_COLOR along with it's alpha value (e.g. GFX_CLEAR_COLOR = RGB15(0, 31, 0) | (31 << 16) | etc.). it needs to be opaque in order to make aa work. glClearColor(...) seems to only be changing bg palette entry 0 to the specified color, but again, that isn't the "clear plane" (as opposed to the "clear image", which is an alternative [i think it is enabled by setting bit 14 in gfx control or something and will replace the color buffer and depth buffer with images - both eat up each a whole vram bank - though useful for resident evil style games]).

- if you want full control over glEnable/Disable/Reset (e.g. being able to diable outlining etc.): copy and rename them, then redefine them, e.g.:

Code:

static const uint16 constant_bits = 0; or GL_TEXTURE_2D | ((1<<12) | (1<<13);

static uint16 enable_bitsFIX = constant_bits;

void glEnableFIX(int bits)
{
   enable_bitsFIX |= bits | constant_bits;
   GFX_CONTROL = enable_bitsFIX;
}

etc.


- polygons and vertices can share colors, so don't call glColor/Material for every vertex if not neccessary. transparency (set in poly format) is only on a per poly base, so don't try to set it for each vertex.

- use triangles (or triangle strips) instead of quads, when you get strange lighting. (sorry again, gabebear, my fault!)

- always leave a bit of space in poly and vertex ram to compensate for clipping. the geometry engine creates new vertices and polys when clipping, which are first saved into v/p ram and then rendered by the 3d engine.

more to be edited into this post.


Last edited by silent_code on Mon Aug 20, 2007 12:47 pm; edited 2 times in total

#121960 - Dark Knight ez - Thu Mar 15, 2007 11:39 pm

Important one:
If you decide to use glNormal calls... make sure they come BEFORE glColor calls. If you do it the other way around, the glColor might not work as you expect it to.
_________________
AmplituDS website

#122507 - Dark Knight ez - Mon Mar 19, 2007 10:04 pm

And another important one:
libnds automaticly uses VRAM_E bank for texture palettes. So if you use 3D, stay away from using VRAM_E bank yourself. (I tried to use it for sprites on the main screen; had me stumped for two/three days).
_________________
AmplituDS website

#122511 - simonjhall - Mon Mar 19, 2007 10:32 pm

And a similar tip,
if start your writing you app with consoleDemoInit and forget to change that at a later date, you'll only be able to get a hold of 384k of VRAM for textures!

So change to consoleInitDefault and use some smart params to relocate the console to a block that's less useful.

For instance, I've got my console set up like this:
Code:
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
   vramSetBankH(VRAM_H_SUB_BG);
   SUB_BG0_CR = BG_MAP_BASE(15) | BG_256_COLOR;
      
   BG_PALETTE_SUB[255] = RGB15(31,31,31);
   
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(15), (u16*)CHAR_BASE_BLOCK_SUB(0), 8);
...so I've got my console in VRAM H which is 32k in size and can't be used for textures.

Thanks goes to elhobbs for the code. I've now got 512k for textures!
_________________
Big thanks to everyone who donated for Quake2

#122893 - qw3rty - Fri Mar 23, 2007 9:11 am

Damn - I should've known earlier !
I tried almost every upper VRAM-Bank, and could only get BankE working for the main-screen - which is a bank, that's also used by DS-GL (for texture-palettes)..I had to copy the opengl-texture routines and adapt them to use VRAM-F exclusively for palettes.

Edit : I just noticed, you use the SUB screen for the console...maybe vramE was indeed the only I could use for my needs

#122920 - Payk - Fri Mar 23, 2007 2:32 pm

Here my tipp does come:
If you want to use a wireframe model, enable AA and set alphablend to 0 (polyfmt). You can also let models slowly turn into a wireframe. The alphablend (0...31) value controls just the blending of the polygone it self, not the blending of the outlineborder (AA uses the outlineborder)

The wireframe lines should depend on texture if AA is enabled (that just works with r20 and cvs updated libnds afaik)

BTW: Even if your entiry model just has one polyID:
When blending <31 and AA is enabled you get a real wireframe thingy!

#122970 - Touchstone - Sat Mar 24, 2007 1:11 am

Lick wrote:
- If you want to use a texture with alphabits, make sure that you disabled anti-aliasing(incorrect) and have rendered a polygon behind it. If there's no polygon behind it, all pixels with alpha will be entirely invisible.

If you set up blending between planes properly you can blend your 3D layer with any 2D layer behind it and does not need a polygon behind you AA polygons.
_________________
You can't beat our meat

#123130 - qw3rty - Sun Mar 25, 2007 11:22 am

glBegin() and glEnd() seem to consume lots of CPU-time !

Use them as little as possible !

Or maybe the NDS-hardware can only render a limited amount of glBegin/End packets in one frame - I don't know exactly...