forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Texture Mapping with the Gu Lib

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Thu Sep 29, 2005 12:51 pm    Post subject: Texture Mapping with the Gu Lib Reply with quote

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:

//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:

      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!
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Thu Sep 29, 2005 5:43 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Thu Sep 29, 2005 11:09 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Sat Oct 01, 2005 1:31 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Sat Oct 01, 2005 5:01 pm    Post subject: Reply with quote

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:
extern unsigned char plasmaTex_start[];
extern unsigned char plasmaTexGrey_start[];
unsigned char *plasmaTex_temp;


Load Texture to RAM:
Code:
plasmaTex_temp = convertimagealph(plasmaTex_start,plasmaTexGrey_start,32);


Main Function:

Code:
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 (x=0;x<tsize;x++) {
    *(outptr++) = *(input++);
    *(outptr++) = *(input++);
    *(outptr++) = *(input++);
    *(outptr++) = *(inputGrey++);
  }
  vramaddr += tsize * 4;
  if ((vramaddr & 0xff) != 0)
    vramaddr = (vramaddr & 0xffffff00) + 0x100;
  return output;
}


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
Back to top
View user's profile Send private message
Tim



Joined: 12 Jul 2005
Posts: 38

PostPosted: Sat Oct 01, 2005 5:09 pm    Post subject: Raw file Reply with quote

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
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Sun Oct 02, 2005 3:08 am    Post subject: Reply with quote

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:


      // setup texture

      sceGuTexMode(GU_PSM_8888,0,0,0);
      sceGuTexImage(0,256,256,256,body_start);
      sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
      sceGuTexEnvColor(0xffff00);
      sceGuTexFilter(GU_LINEAR,GU_LINEAR);
      sceGuTexScale(1.0f,1.0f);
      sceGuTexOffset(0.0f,0.0f);
      sceGuAmbientColor(0xffffffff);

      // draw My Model

      sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,756*3,0,vertecies);

Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 2:19 am    Post subject: Reply with quote

Any ideas about what I am doing wrong?
Back to top
View user's profile Send private message
Tim



Joined: 12 Jul 2005
Posts: 38

PostPosted: Mon Oct 03, 2005 2:35 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 3:17 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Tim



Joined: 12 Jul 2005
Posts: 38

PostPosted: Mon Oct 03, 2005 6:34 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 6:44 am    Post subject: Reply with quote

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!!!!
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Mon Oct 03, 2005 11:05 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 11:47 am    Post subject: Reply with quote

I don't quite follow you Ector. What should I do to my texture coords? Thanks in advance!
Back to top
View user's profile Send private message
ashleydb



Joined: 03 Oct 2005
Posts: 26
Location: USA

PostPosted: Mon Oct 03, 2005 11:59 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 12:31 pm    Post subject: Reply with quote

So I should do both

u = 1.0f - u;

v = 1.0f - v;

or just

v = 1.0f - v;


?????
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 12:32 pm    Post subject: Reply with quote

So I should do both

u = 1.0f - u;

v = 1.0f - v;

or just

v = 1.0f - v;


?????
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 1:43 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Mon Oct 03, 2005 2:10 pm    Post subject: Reply with quote

Only V.
_________________
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 03, 2005 2:24 pm    Post subject: Reply with quote

I tired doing it only for V but it still doesn't map correctly but it is very close.
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Tue Oct 04, 2005 3:22 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Wed Oct 05, 2005 5:29 am    Post subject: Reply with quote

Thanks, I will play around with it. =)


GOD Bless you Always!!!!!!
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Wed Oct 05, 2005 2:36 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
BlackDragon777



Joined: 15 Sep 2005
Posts: 32

PostPosted: Mon Oct 10, 2005 8:38 am    Post subject: Reply with quote

No ideas?
Back to top
View user's profile Send private message
Paco



Joined: 09 Oct 2005
Posts: 54

PostPosted: Mon Oct 10, 2005 9:05 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group