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 > A list of all the "WTF"s I'm having trouble with

#66901 - FireSlash - Sat Jan 14, 2006 6:27 am

Here we go.

#1. Fading a GL texture in and out.
Code:
bool dsIntro::update()
{
    nextScene ns;
    if((alpha < 62) && (state == state_LOADED) )
        alpha++;
    if((alpha > 0) && (state == state_UNLOADING) )
        alpha--;
    if(alpha >= 62)
        state = state_UNLOADING;
    if( (alpha <= 0) && (state = state_UNLOADING) )
    {
         ns = scene_menu;
        sceneController.changeScene(ns); 
    }   
   
    return true;
}

bool dsIntro::draw_bottom(uint32 frame)   
{
    byte a;
    if(alpha == 0)
        a=0;
    else
        a=alpha/2;
    update();

    glPolyFmt(POLY_ALPHA(a) | POLY_CULL_BACK  | POLY_FORMAT_LIGHT0);

   glLoadIdentity();
    glTranslatef(0,0,0);
   
   
   glBindTexture(GL_TEXTURE_2D, textures[1]);
   
   glBegin(GL_QUADS);
      glTexCoord2f(1.5f, 0.0f);
        glVertex3f(  0.0f,  0.0f, 0);
      glTexCoord2f(1.5f, 2.0f);
        glVertex3f(  1.0f,  0.0f, 0);
      glTexCoord2f(0.0f, 2.0f);
        glVertex3f(  1.0f,  1.0f, 0 );
      glTexCoord2f(0.0f, 0.0f);
        glVertex3f(  0.0f,  1.0f, 0);
   glEnd();
   
   return TRUE;
}

The scene properly waits for a few seconds before unloading, but the alpha NEVER changes from full. Even if I manually set it to, say, 5, it never changes. I made sure that glEnable(GL_BLEND); was set up in the init routine.

#2. Pallete entry 0 not transparent.
Code:
    pFile = FAT_fopen ("/data/lumiDS/base/sweep.pcx","r");
    if (!pFile) return false;
    FAT_fseek (pFile , 0 , SEEK_END);
    lSize = FAT_ftell (pFile);
    FAT_fseek(pFile, 0, SEEK_SET);
   
    buffer = (char*) malloc (lSize);
    if (!buffer) return false;
   
    FAT_fread (buffer,1,lSize,pFile);

   loadPCX((u8*)buffer, &pcx);
   
   image8to16(&pcx);

   glGenTextures(1, &textures[2]);
   glBindTexture(0, textures[2]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_32 , TEXTURE_SIZE_32, 0, GL_TEXTURE_COLOR0_TRANSPARENT | TEXGEN_TEXCOORD, pcx.data8);

   imageDestroy(&pcx);
    FAT_fclose (pFile);
    free (buffer);

I've verified (twice) that pallete entry 0 is indeed the background in these images, but they still show black.

#3 Using...
glOrtho(0,1,0,1,-6,6);
The Depth is based on the Y value, NOT the Z axis. Perhaps I missed something somewhere, but thats how its working for me. I can provide example binaries if needed :p

#4 If anyone has found a way to set up reg_capture without burning two VRAM banks, I'd love to see source for it. Another option would be a way to use banks past D for textures, or for a way to use banks E and F for reg_capture. (For source, see ecurtz's sample: ftp://ftp.nuprometheus.com/pub/Display_Capture.zip )
Important bits:
Code:
// ....
      if (frameCount & 0x1)
      {
         vramSetBankC(VRAM_C_SUB_BG);
         vramSetBankD(VRAM_D_LCD);
         SetRegCapture(true, 0, 15, 3, 0, 3, 0, 0);
         scene->draw_top(frameCount);
      } else {
            vramSetBankC(VRAM_C_LCD);
         vramSetBankD(VRAM_D_SUB_SPRITE);
         SetRegCapture(true, 0, 15, 2, 0, 3, 0, 0);
         scene->draw_bottom(frameCount);
      }
// .....

void SetRegCapture(bool enable, uint8 srcBlend, uint8 destBlend, uint8 bank, uint8 offset, uint8 size, uint8 source, uint8 srcOffset)
{
   uint32 value = 0;
   if (enable)
      value |= 1 << 31; // 31 is enable
   value |= 3 << 29; // 29-30 seems to have something to do with the blending
   value |= (srcOffset & 0x3) << 26; // capture source offset is 26-27
   value |= (source & 0x3) << 24; // capture source is 24-25
   value |= (size & 0x3) << 20; // capture data write size is 20-21
   value |= (offset & 0x3) << 18; // write offset is 18-19
   value |= (bank & 0x3) << 16; // vram bank select is 16-17
   value |= (srcBlend & 0xF) << 8; // graphics blend evb is 8..12
   value |= (destBlend & 0xF) << 0; // ram blend EVA is bits 0..4
   
   REG_CAPTURE = value;
}

#5 bitmap fonts in 3d without being able to generate display lists is blowing my mind. I can't seem to find a good way to do it. If anyone can at least point me in the right direction, that'd be awesome.

#6 CF cards are slow. If I load data from them, the DS goes kind of fruity while its being loaded, I assume due to vblank being called with incomplete data drawn. Is there a way to have the DS skip a vblank, or simply use the previous data? It may be simple since REG_CAPTURE is already using two VRAM banks to store the screen data, but I'm having trouble with it.

Thanks for the noob-help :)
_________________
FireSlash.net

#67134 - duencil - Sun Jan 15, 2006 8:22 pm

As for the first issue, are you calling the function glReset() every frame? Right now that resets GL_BLEND to off (its probably a bug), so you might want to call glEnable() every frame instead of only during initialisation. Better yet call GFX_CONTROL directly as the glEnable/glDisable functions are screwy right now ( http://forum.gbadev.org/viewtopic.php?t=8109 )

Enabling GL_BLEND and/or GL_ALPHA_TEST might be all that is necessary for your palette transparency issue too.

#67301 - duencil - Mon Jan 16, 2006 9:33 pm

#3. Whathappens if you use...
glOrtho(0,1,0,1,0,12);
instead?

#67374 - FireSlash - Tue Jan 17, 2006 5:24 pm

I made the changes to my code for alpha blending, didn't seem to help. I'll make another attempt later today without glEnable();

I'll also give the glOrtho adjustments a shot.
_________________
FireSlash.net

#69410 - FireSlash - Mon Jan 30, 2006 5:24 pm

Duencil, changing the Z coords like that give me two fully black screens. At first I thought maybe my Z values were just out of bounds, or behind the camera, but I double checked both cases. o.O

EDIT:
Fixed the black screen problem, silly mistake. Still get the same results though with the polygon ordering :/
_________________
FireSlash.net

#69453 - Extreme Coder - Mon Jan 30, 2006 9:13 pm

Try using 0xFFFF (pink) color and set poly_alpha(31), and that would make those parts transparent. Atleast it worked for me...

If you ever get an update on the ortho problem, tell me;)