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 > Help with 3D

#167999 - opearn - Mon Apr 06, 2009 2:38 pm

hi every one,

i'm trying to load and texture multiple 3D models on the nds,
errors:
my ground model isn't being drawn,
and the enemys texture dosn't wrap the entire model

i think the main error is with the tex_scale....
(i'm not really sure what to set tex_scale to so i ended up copying from an example)

the following is an extract from my code.
Code:
GLvector tex_scale = { 64<<16, -64<<16, 1<<16 };
GLvector tex_scale2 = { 64<<16, -64<<16, 1<<16 };

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//draw all our models
   //ground
      //position variables
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glScalev( &tex_scale2 );      //scale normals up from (-1,1) range into texcoords
      glRotateXi(0);
      glRotateYi(0);
      glMatrixMode(GL_POSITION);
      glLoadIdentity();
      glTranslate3f32(0,0,floattof32(0));   // x,y,z
      glRotateXi(0);
      glRotateYi(0);
     
      glMaterialf(GL_EMISSION, RGB15(31,31,31));
      glPolyFmt(POLY_ALPHA(31) | POLY_ID(8) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0);
     
      glBindTexture(0, texture[0]);         //wrap texture (non functional)
      glCallList((u32*)ground_model_bin);         //draw model

   //enemy
      //position variables
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glScalev( &tex_scale );      //scale normals up from (-1,1) range into texcoords
      glRotateXi(0);
      glRotateYi(0);
      glMatrixMode(GL_POSITION);
      glLoadIdentity();
      glTranslate3f32(p2x,p2y,floattof32(p2z));   // x,y,z
      glRotateXi(p2rotx);                     //xrot
      glRotateYi(p2roty);                     //yrot
     
      glMaterialf(GL_EMISSION, RGB15(31,31,31));
      glPolyFmt(POLY_ALPHA(31) | POLY_ID(8) | POLY_CULL_BACK | POLY_FORMAT_LIGHT0);
     
      glBindTexture(0, texture[3]);            //wrap texture (non functional)
      glCallList((u32*)enemy_model_bin);         //draw model


thanks for your help,
-opearn

#168052 - opearn - Wed Apr 08, 2009 1:42 pm

(desperate bump... because i really need help!)

please help me...

#168057 - Synthetic - Wed Apr 08, 2009 4:46 pm

What size are your textures, and did the example actually work?

From what I gathered, the texture matrix is stored internally in .12 fixed point format, and if you are packing your texture coordinates using floattot16, the t16 is .4 fixed point format already, so you when you scale the texture matrix it doesn't have to be 64<<16, just 64<<12, or whatever the size of your texture is.

#168102 - opearn - Fri Apr 10, 2009 7:58 am

so if i have a 256x256 texture i use
Code:
GLvector tex_scale = { 256<<12, -256<<12, 1<<12 };
?

or do i use 128?

(only one axis is wrapping!)

heres my texgen code
Code:
//tex 1
   sImage pcx;

   loadPCX((u8*)Ground_pcx, &pcx);
   
   image8to16(&pcx);
   
   glGenTextures(1, &texture[0]);
   glBindTexture(0, texture[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, GL_TEXTURE_WRAP_S|GL_TEXTURE_WRAP_T|TEXGEN_POSITION, pcx.image.data8);

#168111 - Synthetic - Fri Apr 10, 2009 9:16 am

If the texture coordinates in your model are stored as t16, and are normalized from 0 to 1, you should use 256<<12, I'm pretty sure. Try it and see.

Also, the - in front of your second coordinate could be causing a problem. If the texture is not set to repeat in the y/t/v direction, any negative texture coordinates will be be mapped to a blank region of texture space.
Or did you mean it looks like only one axis is wrapping, but both should be?

#168112 - opearn - Fri Apr 10, 2009 10:26 am

so i need to use what this config in the model converter?

texture size
256x256

scale
1.000

disable normals
no

normal flip
no

heres a .nds file to show what happens
http://www.sendspace.com/file/ti9fkb

alsoi removed the negative (-).

#168122 - Synthetic - Fri Apr 10, 2009 3:36 pm

Ok, just so we're clear:
-The internal format for texture coordinates on the DS is 1.11.4 fixed point. So, 1 bit sign, 11 bits for the integer, and 4 bits for the fraction.
-The DS does not automatically normalize texture space like a strict OpenGL implementation. So When you load a 256x256 texel texture and bind it, in texture space the texture goes from (0.0 , 0.0) out to (256.0,256.0) at the other corner.

So, if the model converter takes in a texture size, chances are that it is already recalculating all the texture coordinates so that they range from 0 to 256 instead from 0 to 1. If the model converter puts out a c file with the display list in it, you can look and see for yourself if the texture coordinates are already scaled, or you could just try not scaling the texture matrix at all, and see what you get.

#168123 - opearn - Fri Apr 10, 2009 4:21 pm

what model converter do you use?

I'm just using the one off the guy who made AmplituDS's website.
http://amplituds.drunkencoders.com/?s=download&proj=Tools%20for%203D%20models

#168124 - Synthetic - Fri Apr 10, 2009 4:30 pm

I'm a coder, so I don't really do much with modeling, but the guy I'm working with uses a python script written for blender. I can't remember who wrote it, but I found it on gbadev, so if you search around you could probably find it.

Anyway, does the texture mapping work when you don't scale it?

#168126 - opearn - Fri Apr 10, 2009 5:22 pm

getting rid of
Code:
glScalev( &tex_scale );

makes it a single color

and setting the scale in the converter to 0 makes the map not show up at all.
(0.000 = 0%|1.000=100%)

#168127 - opearn - Fri Apr 10, 2009 5:25 pm

maybe you could just post an example bit of code?

#168140 - Synthetic - Fri Apr 10, 2009 9:15 pm

Its hard to remotely debug. How about you zip up your code and post a link, and I'll take a look and see if I can spot the problem.

What version of libnds are you using?

#168142 - opearn - Sat Apr 11, 2009 12:49 am

[devkitARM]
Version=25

[libnds]
Version=1.3.2

i'll pm you a link.

also please use the delete link after downloading it.

thanks

#169246 - BusDriver - Thu Jun 25, 2009 4:21 am

anyone who can help with this... PLEASE. YOU ARE NEEDED.

#169258 - elhobbs - Thu Jun 25, 2009 5:34 pm

it is hard to help without the source code and the associated resources.