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 > Inaccuracies and no texture

#114079 - NeX - Wed Jan 03, 2007 6:02 pm

My code is below. On Dualis, the texture appears, and there are no visible seams between the quads. However, on the DS itself, the texture does not appear, and there are seams between the landscape tiles. The texture is black and white, and I am intending upon using the colour function to make grass and dirt seamlessly fade from one to another. Help!

Code:
/*---------------------------------------------------------------------------------

RTS

---------------------------------------------------------------------------------*/
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gbfs.h>

extern const GBFS_FILE  data_gbfs; //Don't touch the red button
u32 totalframes;
int texture[8];
v16 heightmap[65536];
   float rotateX = 0.0;
   float rotateY = 0.0;
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
   touchPosition touchXY;
   
   powerON(POWER_ALL);
   videoSetMode(MODE_0_3D);   //not using the main screen
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);   //sub bg 0 will be used to print text
   vramSetBankA(VRAM_A_TEXTURE);
      glViewPort(0,0,255,191);

   glClearColor(0,0,0);
   glClearDepth(0x7FFF);
   irqInit();
   irqEnable(IRQ_VBLANK);
   const void *terrain_dta_bin = gbfs_get_obj(&data_gbfs, "terrain.dta.bin", NULL);    
   glGenTextures(1, &texture[0]);
   glBindTexture(0, texture[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD,  (u8*)terrain_dta_bin);
   const void *test_heightmap_raw = gbfs_get_obj(&data_gbfs, "test.heightmap.raw", NULL);    
      dmaCopy(test_heightmap_raw, (void*)heightmap, 65536);
      u32 i=0;
      
      while(i<65536)
      {
         heightmap[i]=heightmap[i]*0.1;
         i++;
      }
   while(1) {
   totalframes++;
   
      glReset();

      //any floating point gl call is being converted to fixed prior to being implemented
      gluPerspective(35, 256.0 / 192.0, 0.1, 40);

      gluLookAt(   0.0, 0.0,1.0,      //camera possition
               0.0, 0.0, 0.0,      //look at
               0.0, 1.0, 0.0);      //up
               glTranslate3f32(0, 0, floattof32(-1));
      glRotateX(rotateX);
      glRotateY(rotateY);
      
      glPushMatrix();

      //move it away from the camera





      glMatrixMode(GL_MODELVIEW);



      //not a real gl function and will likely change
      glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);

      scanKeys();
      
      u16 keys = keysHeld();
      
      if((keys & KEY_UP)) rotateX += 3;
      if((keys & KEY_DOWN)) rotateX -= 3;
      if((keys & KEY_LEFT)) rotateY += 3;
      if((keys & KEY_RIGHT)) rotateY -= 3;


   glBindTexture(0, texture[0]);
      //draw the obj
      
      u8 i=0;
      u8 j=0;
      while(j<32)
      {
      glBegin(GL_QUAD_STRIP);
      while(i<32)
      {
         glColor3b(0,255,0);
         glTexCoord1i(TEXTURE_PACK(inttot16((j*32)%256), inttot16((i*32)%256)));
         glVertex3v16(floattov16(i*0.1),heightmap[(j*256)+i],floattov16(-0.05));



         glColor3b(0,255,0);
         glTexCoord1i(TEXTURE_PACK(inttot16(((j+1)*32)%256), inttot16((i*32)%256)));
         glVertex3v16(floattov16(i*0.1), heightmap[((j+1)*256)+i], floattov16(0.05));
      i++;
      }
      glEnd();
      glTranslate3f32(0, 0, floattof32(0.1));
      i=0;
      j++;
      }
      

      glPopMatrix(1);

      glFlush();

      swiWaitForVBlank();

   }

   return 0;
}


Amendment: Could it be caused by the use of floats to rotate the terrain?

#114082 - NeX - Wed Jan 03, 2007 7:28 pm

I've gotten around the inaccuracies by overlapping the tiles by 0.5%. The texture is still a no-show, however. If I remove the colour commands, it goes black....
Have I got to set bit 15 on the textures?

#114108 - tepples - Thu Jan 04, 2007 1:30 am

When in doubt, set bit 15.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.