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 > Texture Mapping / Orthoview problem on hardware

#123010 - zeGouky - Sat Mar 24, 2007 2:18 pm

Hi people,

I'm trying to draw a textured QUAD using the orthoview, but my code work on no$gba but not on the hardware :-/

here's the piece of the code :

Init :
Code:

   videoSetMode(MODE_0_3D);
   videoSetModeSub( MODE_0_2D | DISPLAY_BG0_ACTIVE );   // --- lower screen for console text
   vramSetMainBanks( VRAM_A_TEXTURE, VRAM_B_LCD, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE );

   glViewPort(0,0,255,191);
   glClearColor(0,0,0);
   glClearDepth(0x7FFF);

   glGenTextures(1, &textureID);
   glBindTexture(0, textureID);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);


Init Orthoview :
Code:

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrthof32(0, 256, 192, 0,0, 1);

   glMatrixMode(GL_TEXTURE);
   glIdentity();

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   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));

   glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);


Back to perspective :
Code:

   glMatrixMode(GL_PROJECTION);   
   glLoadIdentity();
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();


Rendering the quad :
Code:

      //   -- Rendering
      OrthoView();

      glPushMatrix();
      glBindTexture(GL_TEXTURE_2D, textureID);
      glBegin(GL_QUADS);
         glNormal(NORMAL_PACK(0,inttov10(-1),0));

         glTexCoord1i(TEXTURE_PACK(inttot16(128), 0));
         glVertex3v16( spr_x, spr_y+spr_h, 0);

         glTexCoord1i(TEXTURE_PACK(inttot16(128),inttot16(128)));
         glVertex3v16( spr_x+spr_w, spr_y+spr_h, 0);

         glTexCoord1i(TEXTURE_PACK(0, inttot16(128)));
         glVertex3v16( spr_x+spr_w, spr_y, 0);

         glTexCoord1i(TEXTURE_PACK(0,0));
         glVertex3v16( spr_x, spr_y, 0);
      glEnd();
      glPopMatrix(1);

      //   --- Bactk to perspective
      PerspectiveView();


On the device im just getting the QUAD with no texture but the QUAD is in color #0 of it.

If anyone can help :)

Thanks

#123062 - HyperHacker - Sat Mar 24, 2007 10:29 pm

The quad is a solid colour from the texture? Sounds like a problem with the texture matrix or coordinates.
_________________
I'm a PSP hacker now, but I still <3 DS.

#123090 - zeGouky - Sun Mar 25, 2007 1:23 am

Hi,

redone something more "proper" according to the examples and not its work but i have 2 weird problems.

1/ If I display 2 textured quads and when the front one go on the upper, left of the screen it go behind the 2nd quad. This bug dont happen on the emu ... :-/ Hope i'm clear :)

2/ if im loading 2 textures : one 128x128 and one 256x256, the 2nd loaded textures is not shown that only happen when i use a 256x256 texture, i can load a 128x128 and a 64x64 without problems.

Again hope i'm clear.

Thanks

#123133 - Lick - Sun Mar 25, 2007 1:48 pm

1) You need to set different Z-values for the quads. Otherwise they are on the same depth and it will result into unexpected output.

2) You need more VRAM. You could also try using a different texture format. GL_RGB is 2bytes per pixel, while there are other formats are 0.5bytes per pixel.
_________________
http://licklick.wordpress.com

#123177 - zeGouky - Sun Mar 25, 2007 10:11 pm

2/ hmm when im setting z values for the quad , the quad go off :-/ Im new to opengl so maybe im missing something ? here's the piece of code :

Code:

   glBindTexture( GL_TEXTURE_2D, texture[textureID]);
   glBegin(GL_QUADS);
      glNormal(NORMAL_PACK(0,inttov10(-1),0));

      glTexCoord1i(TEXTURE_PACK(inttot16(tex_w), 0));
      glVertex3v16( x, y+h, -1);

      glTexCoord1i(TEXTURE_PACK(inttot16(tex_w),inttot16(tex_h)));
      glVertex3v16( x+w, y+h, -1);

      glTexCoord1i(TEXTURE_PACK(0, inttot16(tex_h)));
      glVertex3v16( x+w, y, -1);

      glTexCoord1i(TEXTURE_PACK(0,0));
      glVertex3v16( x, y, -1);
   glEnd();


2/ argh yes, working now :)

#123181 - zeGouky - Sun Mar 25, 2007 11:44 pm

Finally got it working, i have added depth to my glOrtho and also change GFX_FLUSH = 2 to GFX_FLUSH = 0 in glFlush();