#119169 - Risine - Tue Feb 20, 2007 12:38 pm
I have just updated devkitpro from ??? version to 1.4.2 version, and it seems texturing does not work anymore.
I used this code to have good texture matrix :
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(Img_width/128.,Img_height/128.,1.);
But now that does not work anymore depending on texture sizes. ( still works for 128x128 textures, but no more for 256x128,128x64,...)
Has anyone been confronted to the same problem?
#119173 - Risine - Tue Feb 20, 2007 1:05 pm
I think I found the good way to scale the texture matrix :
instead of :
glScalef(Img_width/128.,Img_height/128.,1.);
I have now :
glScalef(Img_width/Img_height,Img_height/Img_width,1.);
If someone can confirm/explain that, many thanks, as I don't really understand why width texturing depends on height and height on width.
Really strange.
#119691 - gabebear - Sun Feb 25, 2007 9:18 am
Are you enabling textures with glEnable(GL_TEXTURE_2D) ? I know some older versions of libnds did this for you.
The texture coordinates(U and V) are swapped in all released versions of libnds. Texture coords are correct in the CVS version, but if you get the CVS libnds you will also want to grab the CVS examples since several other things have changed.
#119707 - Risine - Sun Feb 25, 2007 2:30 pm
I'm not using glEnable, but I use glBindTexture(GL_TEXTURE_2D,Textures_gl[face->Texture]);
Maybe that if I replace GL_TEXTURE_2D by 0, I'll be able to use back glScalef(Img_width/128.,Img_height/128.,1.); ?
#119748 - gabebear - Sun Feb 25, 2007 8:50 pm
The first argument of glBindTexture is ignored, the DS only supports 2D textures. You must enable textures with glEnable(GL_TEXTURE_2D); before using them. I'm a bit confused on what you are trying to do by scaling the texture matrix.
#119805 - Risine - Mon Feb 26, 2007 2:58 pm
If you want to use textures of different sizes ( 32x32,64x128,256x256...), you must adapt the texture matrix in order for the uv values [0,1] to fit to the real texture size
#119826 - Lick - Mon Feb 26, 2007 6:45 pm
The texture matrix is used to transform the UV values. It does not have anything to do with the pixel sizes of the textures, it rather zooms in and out or scrolls, as you scale and translate the matrix.
For example, by translating the texture matrix of a polygon with a water texture, you can simulate flowing water. (The water texture would be repetitious though.)
_________________
http://licklick.wordpress.com
#119833 - tepples - Mon Feb 26, 2007 7:56 pm
Lick wrote: |
For example, by translating the texture matrix of a polygon with a water texture, you can simulate flowing water. (The water texture would be repetitious though.) |
You can hide this to an extent by overlaying two water textures, one semi-transparent. Animal Crossing for GCN does this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#119933 - Risine - Tue Feb 27, 2007 5:24 pm
Yes, it has something to do, as your texels don"t take into account the size of the texture and evolve in [0,1].
If you don't change the texture matrix depending on its size then you won't have a good result ( when changing a 128x128 texture by a 256x128 for instance for the same texels )
or there is a bug somewhere!!!
#120025 - silent_code - Wed Feb 28, 2007 12:57 pm
no, just scale your uv coordinates to the textures dimensions (don't forget to swap u and v) when loading a mesh (or generating it otherwise) and there you go. i believe it's cheaper than adjusting the matrix every frame.
and if you want to implement texture lods, just scale your uvs to the size of the smallest lod and then shift left when rendering with a higher resolution texture. works pretty good for me.
#120177 - Risine - Thu Mar 01, 2007 4:31 pm
I just saw in videoGL.c that it's what is done in glTexCoord2f ( I use that function to push my texels ), not very efficient indeed.
But I still don't understand why I have to change the Texture Matrix :( Quite strange !!!
#120545 - Risine - Sun Mar 04, 2007 4:58 pm
Found the reason !!! For those who can get in the same troubles :
My texels do not depend on texture size and go from [0,0] for left/top texture corner to [1,1] right/bottom texture corner.
When rendering, the texels u/v have to be inverted - don't know why, maybe a bug of libnds? -, but the texture width/height are not inverted.
So I had to change the texture matrix and scale it with (Width/Height,Height/Width,...) in order to retrieve the good units.
( A better way to do it is to change glTexCoord2f function and invert x/y in the call of glTexCoord2t16. )
#120566 - gabebear - Sun Mar 04, 2007 6:52 pm
The CVS version of libnds has the texture coords correct, so whenever the next release of libnds comes out the inverted texture coords will be fixed.