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 > libnds bug or a bug of mine?

#74347 - MrK - Sat Mar 04, 2006 5:53 pm

I have this code, heavily borrowed from the nehe's samples from libnds samples:

Code:

   // Turn on everything
   powerON(POWER_ALL);
   
   // Setup the Main screen for 3D
   videoSetMode(MODE_0_3D);
   vramSetBankA(VRAM_A_TEXTURE);                        //NEW  must set up some memory for textures

   // Set our viewport to be the same size as the screen
   glViewPort(0,0,255,191);
   
   // Specify the Clear Color and Depth
   glClearColor(0,0,0);
   glClearDepth(0x7FFF);
   
   while (1)
   {
      // Reset the screen and setup the view
      glReset();
      glOrtho (0,16,16,0,0,256);               // ortho screen from 0,0 to 16,16 mapped to 0,0 to 256,192 (should be 256,192 to 256,192, but otherwise I can't see the polys being drawn ;) )

      glPushMatrix();
      
      glMatrixMode(GL_TEXTURE);
      glIdentity();
   
      glMatrixMode(GL_MODELVIEW);

      //need to set up some material properties since DS does not have them set by default
      glMaterialf(GL_AMBIENT, RGB15(16,16,16));
      glMaterialf(GL_DIFFUSE, RGB15(16,16,16));
      glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8));
      glMaterialf(GL_EMISSION, RGB15(16,16,16));

      //ds uses a table for shinyness..this generates a half-ass one
      glMaterialShinyness();

      
      //ds specific, several attributes can be set here   
      glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
      
      // Set the current matrix to be the model matrix
      glMatrixMode(GL_MODELVIEW);
   
      //Push our original Matrix onto the stack (save state)
      glPushMatrix();   


      glLoadIdentity();                           // Reset The View

      glTranslatef(0.0f,0.0f,-5.0f);

static float XPOS=4.0f;

      glBegin (GL_QUADS);

      glColor3f (1,1,1);
      glVertex3f(XPOS,0,16);

      glColor3f (1,0,0);
      glVertex3f(XPOS+2,0,16);

      glColor3f (0,1,0);
      glVertex3f(XPOS+2,4,16);

      glColor3f (0,0,1);
      glVertex3f(XPOS,4,16);
         
      glEnd();

      // Pop our Matrix from the stack (restore state)
      glPopMatrix(1);

      // flush to screen   
      glFlush();
   
   }
   
   return 0;



my idea is putting an ortho perspective matching the real nds coordinates, 256,192, using this

Code:

glOrtho (0,256,192,0,0,256);



but using this for visibility's sake

Code:

glOrtho (0,16,16,0,0,256);



the sample works correctly, it just displays a colored quad in the screen, but if you change XPOS to 6.0f, does a weird thing to the quad. could this be a bug in libnds, or it's just I'm doing something wrong?

TIA
MrK


p.s. or maybe an emulator bug, but I've tried in two emulators and both do the same

#74352 - Dark Knight ez - Sat Mar 04, 2006 7:10 pm

I encountered some sort of wrap around with "high" values such as that, and am now using a 3d space of 1.0x1.0x1.0 to avoid problems, and scaling it to the size I actually want with glScalef (beforehand).

So, maybe you could try to scale everything with a factor of 100 and see if that helps. Meaning:

... some code ...
glScalef(100.0f, 100.0f, 100.0f);
... some code ....
glTranslate(0.0f, 0.0f, -0.05f);
XPOS = 0.04f;
... some code .... etc.

Hope this works out for you.

#74353 - Webez - Sat Mar 04, 2006 7:11 pm

vertex 4.12 fixed format .

1 bit is for sign. So you only have 3 bits-> 111=7 is max number you can use in vertex

#74357 - MrK - Sat Mar 04, 2006 7:33 pm

Webez wrote:
vertex 4.12 fixed format .

1 bit is for sign. So you only have 3 bits-> 111=7 is max number you can use in vertex


mmm... the wrap around makes sense then, I thought about it but as I saw f32 (1.19.12) was widely used it'd be an error of mine or a library error.

is this a libnds limitation or it's a hardware one?

#74362 - dovoto - Sat Mar 04, 2006 8:15 pm

The hardware accepts vertex data in 4.12 format only. To use a large range you need to use the scale functionality or use the view matrix.

As for errors in libnds there is definatly an error in in ortho at the moment with Z sorting which people are looking into.
_________________
www.drunkencoders.com

#74374 - MrK - Sat Mar 04, 2006 9:39 pm

I see, hardware limit then. no worries about the scale, my objective was to do a mapping as if I were working in the real ds display (256x192), but I'll change the rendering to match another resolution (0,0 to 1,1 in example).

btw, is there any way to bypass the z sorting? I'm sending the polys in the exact order I want to be displayed (in fact I only want openGL to render)

thanks to all for the speddy responses :)