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 

GU Texture Problem

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



Joined: 10 May 2006
Posts: 376

PostPosted: Tue Sep 19, 2006 9:18 am    Post subject: GU Texture Problem Reply with quote

Hey.

I'm having issue with using GU to correctly display a texture.

I'm using an Ortho projection.

This is my drawing code:

Code:
void IMG_Draw(float sx, float sy, float width, float height, Image* image, float dx, float dy)
{
 if (!isDrawingStarted)
        return;
 
 sceKernelDcacheWritebackInvalidateAll();
 
 sceGumLoadIdentity();
 ScePspFVector3 pos = {dx + (width/2), dy + (height/2), 0};
 sceGumTranslate(&pos);
 
 if(image->rotation > 0.0f)
                    sceGumRotateZ(image->rotation);
 
 if(image->isSwizzled == 1)
        sceGuTexMode(GU_PSM_8888, 0, 0, GU_TRUE);
 
 sceGuTexImage(0, image->textureWidth, image->textureHeight, image->textureWidth, (void*) image->data);
 float u = 1.0f / ((float)image->textureWidth);
 float v = 1.0f / ((float)image->textureHeight);
 sceGuTexScale(u, v);
 
 float j = 0.0f;
   while (j < width) {
      VertexUV* vertices = (VertexUV*) sceGuGetMemory(4 * sizeof(VertexUV));
      float sliceWidth = 32.0f;
      if (j + sliceWidth > width) sliceWidth = width - j;
 
                vertices[0].u = sx + j;
                vertices[0].v = sy;
                vertices[0].x = (0 - (width/2)) + j;
                vertices[0].y = 0 - (height/2);
                vertices[0].z = 0;
                vertices[1].u = sx + sliceWidth + j;
                vertices[1].v = sy;
                vertices[1].x = (0 - (width/2)) + j + sliceWidth;
                vertices[1].y = 0 - (height/2);
                vertices[1].z = 0;
                vertices[2].u = sx + sliceWidth + j;
                vertices[2].v = sy + height;
                vertices[2].x = (0 - (width/2)) + j + sliceWidth;
                vertices[2].y = 0 + (height/2);
                vertices[2].z = 0;
                vertices[3].u = sx + j;
                vertices[3].v = sy + height;
                vertices[3].x = (0 - (width/2)) + j;
                vertices[3].y = 0 + (height/2);
                vertices[3].z = 0;
 
      sceGumDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 1*4, 0, vertices);
      j += sliceWidth;
   }

        sceGuTexMode(GU_PSM_8888, 0, 0, 0);
}


The problem is that I seem to get two horizontal lines across the screen (regardless of the image used).

Ilustrated in this screenshot:

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



Joined: 10 May 2006
Posts: 376

PostPosted: Tue Sep 26, 2006 6:17 pm    Post subject: Reply with quote

I'm still having problems with this if anyone has anything to suggest.

After extensive testing with Raphael it came to light that I need to change this line:

Code:
vertices[3].v = sy + height;


To this to correctly display a 512x512 texture:

Code:
vertices[3].v = sy + height + 2;


However this is not universal as it seems to change dependant upon the size of the texture. I'm not sure why this extra addition is needed as it should work without it.

I've tried stripping the function down to the bare minimum and used GU_SPRITES, not scaled the texture and given absolute U/V co-ordinates and still have the same issue.

Note that I'm using:

Code:
sceGuTexFilter(GU_NEAREST,GU_NEAREST);


If I change this to the following then I get no corruption - but the quality leaves very much to be desired:

Code:
sceGuTexFilter(GU_LINEAR,GU_LINEAR);


If anybody has any ideas I'd be happy to hear them.

Thanks.
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