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 > Alpha blending quads

#171933 - headspin - Sun Jan 03, 2010 8:04 am

How can you alpha blend a quad?

Turn on blend with glEnable(GL_BLEND); but there seems to be no glBlendFunc(). How is it done on the DS?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171935 - DiscoStew - Sun Jan 03, 2010 10:01 am

http://nocash.emubase.de/gbatek.htm#ds3dpolygonattributes

Code:
40004A4h - Cmd 29h - POLYGON_ATTR - Set Polygon Attributes (W)

  0-3   Light 0..3 Enable Flags (each bit: 0=Disable, 1=Enable)
  4-5   Polygon Mode  (0=Modulation,1=Decal,2=Toon/Highlight Shading,3=Shadow)
  6     Polygon Back Surface   (0=Hide, 1=Render)  ;Line-segments are always
  7     Polygon Front Surface  (0=Hide, 1=Render)  ;rendered (no front/back)
  8-10  Not used
  11    Depth-value for Translucent Polygons  (0=Keep Old, 1=Set New Depth)
  12    Far-plane intersecting polygons       (0=Hide, 1=Render/clipped)
  13    1-Dot polygons behind DISP_1DOT_DEPTH (0=Hide, 1=Render)
  14    Depth Test, Draw Pixels with Depth    (0=Less, 1=Equal) (usually 0)
  15    Fog Enable                            (0=Disable, 1=Enable)
  16-20 Alpha      (0=Wire-Frame, 1..30=Translucent, 31=Solid)
  21-23 Not used
  24-29 Polygon ID (00h..3Fh, used for translucent, shadow, and edge-marking)
  30-31 Not used

Writes to POLYGON_ATTR have no effect until next BEGIN_VTXS command.
Changes to the Light bits have no effect until lighting is re-calculated by Normal command. The interior of Wire-frame polygons is transparent (Alpha=0), and only the lines at the polygon edges are rendered, using a fixed Alpha value of 31.


With using glPolyFmt() in libnds, use the inline function POLY_ALPHA() with a value between and including 0 and 31, and combine it will your other values. 0 means it will display the wireframe, but if you want it completely invisible, just don't draw the poly.
_________________
DS - It's all about DiscoStew

#171936 - headspin - Sun Jan 03, 2010 10:47 am

Thanks I did try that but it didn't seem to work.. turns out you need to set glPolyFmt(POLY_ALPHA(n)); before calling glBegin(GL_QUAD);
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171944 - DiscoStew - Sun Jan 03, 2010 8:02 pm

Yes, it is required to be done before your glBegin call (or maybe you can do it between complete polys if you aren't changing with glBegin?). Were you attempting to change the alpha value at each vertex? If so, then expect disappointment, as it can't be done that way. The poly format is designed to affect the entire poly, not just parts of it.

If you still wanted to try per vertex alpha blending, you could try with textures.

http://nocash.emubase.de/gbatek.htm#ds3dtextureformats
Code:
Format 1: A3I5 Translucent Texture (3bit Alpha, 5bit Color Index)
Each Texel occupies 8bit, the 1st Texel is located in 1st byte.

  Bit0-4: Color Index (0..31) of a 32-color Palette
  Bit5-7: Alpha       (0..7; 0=Transparent, 7=Solid)

The 3bit Alpha value (0..7) is internally expanded into a 5bit Alpha value (0..31) as follows: Alpha=(Alpha*4)+(Alpha/2).

Format 6: A5I3 Translucent Texture (5bit Alpha, 3bit Color Index)
Each Texel occupies 8bit, the 1st Texel is located in 1st byte.

  Bit0-2: Color Index (0..7) of a 8-color Palette
  Bit3-7: Alpha       (0..31; 0=Transparent, 31=Solid)


You become limited to the number of colors for the texture when you incorporate the inclusion of an alpha value with these formats. With glTexImage2d() or glTexParameter() in libnds, you use the enum GL_RGB32_A3 or GL_RGB8_A5 to specify which format to use.
_________________
DS - It's all about DiscoStew

#171977 - headspin - Wed Jan 06, 2010 1:33 pm

Okay I spoke too soon, this method doesn't seem to work on hardware. No alpha fading at all. It works in No$ though.

Here is how I'm doing it

Code:
glBindTexture(...);
glColorTable(...);

// Set color to blue
glColor3b(0, 0, 255);

for (...)
{
   glPolyFmt(POLY_ALPHA(...));

   glBegin(GL_QUAD);
   
   glPushMatrix();
   
   drawQuad(...);
   
   glPopMatrix(1);

   glEnd();
}

// Set color back to white
glColor3b(255, 255, 255);

glPolyFmt(POLY_ALPHA(31));


I'm sure it's something to do with the order or something like that?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171984 - ritz - Wed Jan 06, 2010 5:50 pm

I have a feeling you may need to use POLY_ID() in your glPolyFmt() calls. Also, where is your glFlush()? Maybe it's a sorting issue... try diff params in your glFlush() call.

Just some thoughts.

#171987 - headspin - Wed Jan 06, 2010 8:19 pm

Thanks ritz I needed to turn on GL_BLEND using glEnable() and also use POLY_ID() to set the a unique Id for each quad I wanted a different alpha value.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game