Texture Mapping with the Gu Lib

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Texture Mapping with the Gu Lib

Post by BlackDragon777 »

Hi! I am trying to texture map my 3d object using the gulib.

So far, I can see my 3d model. it renders fine. However If I try to add a texture to it, the texture turns to a pink color and is distorted but the model still stays in tact.

I modified the samples/gu/cube example.

I have a model with 756 faces. One face contains example data such as,

Code: Select all

//Triangle(Polygon / Face): 1
	{0.718750, 0.062500, 0x00000000, 0.206043, 3.961590, 14.356922},
	{0.707031, 0.105469, 0x00000000, -0.356571, 5.847838, 15.658901},
	{0.687500, 0.074219, 0x00000000, -1.833433, 4.500518, 14.877714},
First 2 values are the u/v coords of my face and the third is the color of the face (Black), and the last 3 represents my vertex on the face.

My texture is 256x256. I saved it as a RAW format just like in the Cube example. I converted my texture from a 24-bit True color BMP to an Interleaved Ordered RAW image.

I used the same intialization code as in the cube example. All of my code is pretty much the same as the Cube exmaple except for the following lines,

Code: Select all

		sceGuTexImage(0,256,256,256,body_start);
		sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,756*3,0,vertecies);
However not in that order.

My body (body.raw) texture is linked in with my code just fine using bin2o.


Any ideas about what I am doing wrong?

Thanks!
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

The cube-sample uses 16-bit ABGR4444 for the texture. Is your texture in the correct format, or have you changed the sceGuTexMode() call to match your format? If you need 32-bit textures, set sceGuTexMode(GU_PSM_8888,...); and make sure your texture is in ABGR format, which is what the PSP expects.
GE Dominator
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

What software can I use to make a raw texture that reads as ARGB as I don't think my Adobe photoshop 7 does that?
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Can someone please convert my texture to a 32-bit or a 16-bit ABGR RAW format texture so that I can see if there is a problem with my code or my image software. The link to the texture is here.

http://www.jujikasoft.com/PSP/body1.bmp

Thanks!
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I'm not sure RAW supports ARGB, only RGB (at least with PSP8, PSCS and Gimp). The way I did it was like this:

Variable Definitions:

Code: Select all

extern unsigned char plasmaTex_start[];
extern unsigned char plasmaTexGrey_start[];
unsigned char *plasmaTex_temp;
Load Texture to RAM:

Code: Select all

plasmaTex_temp = convertimagealph(plasmaTex_start,plasmaTexGrey_start,32);
Main Function:

Code: Select all

unsigned char *convertimagealph(unsigned char *inptr, unsigned char *inptrGrey, int size)
{
  // convert our raw image
  // saved as raw. no header .. interleaved and order RGB
  int x;
  unsigned char *input = inptr;
  unsigned char *inputGrey = inptrGrey;
  unsigned char *output,*outptr;
  int tsize = size*size;
  if (vramaddr == 0)
    vramaddr = (0x40000000 | 0x04000000) + VRAM_OFFSET;
  outptr = output = (unsigned char *)vramaddr;
  for &#40;x=0;x<tsize;x++&#41; &#123;
    *&#40;outptr++&#41; = *&#40;input++&#41;;
    *&#40;outptr++&#41; = *&#40;input++&#41;;
    *&#40;outptr++&#41; = *&#40;input++&#41;;
    *&#40;outptr++&#41; = *&#40;inputGrey++&#41;;
  &#125;
  vramaddr += tsize * 4;
  if &#40;&#40;vramaddr & 0xff&#41; != 0&#41;
    vramaddr = &#40;vramaddr & 0xffffff00&#41; + 0x100;
  return output;
&#125;
The function takes a 3channel (RGB) .raw file for the colour, and a 1channel (greyscale) .raw file for the alpha. This code is based on the texture loader from spharm.
Now you have your ARGB texture in memory, you can render it, but you will need to set the blend mode in order to see the alpha correctly.

You can find the rest of the sourcehere
Tim
Posts: 38
Joined: Tue Jul 12, 2005 4:40 am

Raw file

Post by Tim »

I wrote a quick program to convert an image to 32 bit ABGR. Program is at http://tim.strafenet.com/files/bmp2raw.zip

I also converted your file so you can see if it works: http://tim.strafenet.com/files/body1.bmp.zip
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Hmm I tried your converted image Tim. However this time it makes my body look orangish. Here is my texture mapping code. Is there anything that I am not doing corectly?

Code: Select all


		// setup texture

		sceGuTexMode&#40;GU_PSM_8888,0,0,0&#41;;
		sceGuTexImage&#40;0,256,256,256,body_start&#41;;
		sceGuTexFunc&#40;GU_TFX_ADD,GU_TCC_RGB&#41;;
		sceGuTexEnvColor&#40;0xffff00&#41;;
		sceGuTexFilter&#40;GU_LINEAR,GU_LINEAR&#41;;
		sceGuTexScale&#40;1.0f,1.0f&#41;;
		sceGuTexOffset&#40;0.0f,0.0f&#41;;
		sceGuAmbientColor&#40;0xffffffff&#41;;

		// draw My Model

		sceGumDrawArray&#40;GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,756*3,0,vertecies&#41;;

BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Any ideas about what I am doing wrong?
Tim
Posts: 38
Joined: Tue Jul 12, 2005 4:40 am

Post by Tim »

I probably had byte ordering wrong.

Try it now:
http://tim.strafenet.com/files/body1.bmp.zip


ector wrote a texture conversion tool that's probably way better than mine:
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip

I haven't used it recently, but I think it does what you want.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Hey Tim! Thanks for your help thus far. You have really tried to help me and I appreciate that.

The texture you converted for me no longer comes up as an orangish texture but rather a blueish texture now. What I did though was I tried using the PSPTEX converter that you sent me a link to in your last post.

I tried saving my texture in many formats such as

PSM_8888 Swizzle / and No Sizzle -- Works the best without swizzle however texture is not mapped properly

PSM_4444 Swizzle / and No Sizzle -- Works the best without swizzle however texture is not mapped properly

Maybe there is a problem in mym code then. What do you guyys think? Do you want to see more code?
Tim
Posts: 38
Joined: Tue Jul 12, 2005 4:40 am

Post by Tim »

It's possible I'm just doing the format wrong, did you try ector's tool? I'm just getting back into psp dev after not doing anything with it for awhile, so I'm still getting back up to speed with psp graphics stuff. If you post a link to your code though, I could play around with it and try to make it work.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Hey thanks TIM! I did try Ector's tool and it brought me closer to getting it to work. At least my texture shows up correctly but it isn't being mapped properly still.

So here is the link to my code, model, and model's texture.

What I did was I wrote a 3DS/ ASC 2 OpenGL commands tool just for quick testing to see if something works right. Then I actually load the model. So I modified it a little bit for the PSP and I contain all the verticies and UV coords in the code.

Here is a link.

http://www.jujikasoft.com/PSP/

Have a look and please let me know what I am doing wrong.

Thanks in advance!


-- Brandon Fogerty

GOD Bless you Always!!!!
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

3DS max exports texture coordinates weirdly: do a v=1.0f-v for all the texture coordinates.
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

I don't quite follow you Ector. What should I do to my texture coords? Thanks in advance!
ashleydb
Posts: 26
Joined: Mon Oct 03, 2005 2:06 am
Location: USA
Contact:

Post by ashleydb »

He said you should run the following line of code on each of your texture co-ordinates:

v = 1.0f - v;

Where v is one of the cordinates.
www.PSP-Files.com - PSP News, Hacks etc.

www.HiAsh.com - My work and stuff
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

So I should do both

u = 1.0f - u;

v = 1.0f - v;

or just

v = 1.0f - v;


?????
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

So I should do both

u = 1.0f - u;

v = 1.0f - v;

or just

v = 1.0f - v;


?????
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Ok, I did a

for(j=0; j<756*3; j++)
{
vertecies[j].u = 1.0f - vertecies[j].u;
vertecies[j].v = 1.0f - vertecies[j].v;
}

And I can tell that the model is VERY VERY close to being texture properly because now I can actually see some of the textures coming together however the model still isn't texture mapped properly. Any other tips?
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Only V.
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

I tired doing it only for V but it still doesn't map correctly but it is very close.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Then I'm out of ideas because that should work :)

Try making some trivial test models and textures where it's easy to see what should go where, and tweak it until it works :)
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

Thanks, I will play around with it. =)


GOD Bless you Always!!!!!!
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

I don't think anything is wrong with my structure holding my information about the model. Why do I think this? Well, I have written a basic 3d model loader in OpenGL that loads various file formats such as 3ds, obj, asc, x, custom formats, etc.

When I extract the info from the files, I can texture map them perfectly using OpenGL based on the uv coords that I have from the files.

Here is an example:

http://www.jujikasoft.com/PSP/3D_Engine.JPG

However, as ector suggested, I tried a different approach on the PSP. before I had been using a 3ds format and loading that on the PSP. The model loads fine but as previously stated, I can't map the texture correctly.

This time, I exported an OBJ of the model in the picture and tried loading that as well. Again, the model is displayed properly but the texture is not mapped correctly.

Here is my EBOOT

http://www.jujikasoft.com/PSP/EBOOT.PBP

This is my source code

http://www.jujikasoft.com/PSP/main.c

This is my OBJ of the model

http://www.jujikasoft.com/PSP/mdo.obj

Last but not least, here is my texture

http://www.jujikasoft.com/PSP/body.bmp

Can anyone please point me in the right direction. I don't unnderstand why my coords work fine in OpenGL and the model loads fine on the PSP but just the texture mapping screws up. my guess is that I am not adding some function for the texture mapping part in like I should but that I what I am asking you all for.

Thanks in advance!
BlackDragon777
Posts: 32
Joined: Thu Sep 15, 2005 8:26 am

Post by BlackDragon777 »

No ideas?
Paco
Posts: 54
Joined: Sun Oct 09, 2005 6:53 pm

Post by Paco »

Can you post a screenshot from the PSP? 3DSMax typically treats bitmaps as bottom-up instead of the classic "(0,0) is top left", that's why you have to flip the V coordinate (and it works fine for me).
Paco
Post Reply