GU Texture Problem

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

Moderators: cheriff, TyRaNiD

Post Reply
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

GU Texture Problem

Post by Insert_witty_name »

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: Select all

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 &#40;j < width&#41; &#123;
		VertexUV* vertices = &#40;VertexUV*&#41; sceGuGetMemory&#40;4 * sizeof&#40;VertexUV&#41;&#41;;
		float sliceWidth = 32.0f;
		if &#40;j + sliceWidth > width&#41; sliceWidth = width - j;
 
                vertices&#91;0&#93;.u = sx + j;
                vertices&#91;0&#93;.v = sy;
                vertices&#91;0&#93;.x = &#40;0 - &#40;width/2&#41;&#41; + j;
                vertices&#91;0&#93;.y = 0 - &#40;height/2&#41;;
                vertices&#91;0&#93;.z = 0;
                vertices&#91;1&#93;.u = sx + sliceWidth + j;
                vertices&#91;1&#93;.v = sy;
                vertices&#91;1&#93;.x = &#40;0 - &#40;width/2&#41;&#41; + j + sliceWidth;
                vertices&#91;1&#93;.y = 0 - &#40;height/2&#41;;
                vertices&#91;1&#93;.z = 0;
                vertices&#91;2&#93;.u = sx + sliceWidth + j;
                vertices&#91;2&#93;.v = sy + height;
                vertices&#91;2&#93;.x = &#40;0 - &#40;width/2&#41;&#41; + j + sliceWidth;
                vertices&#91;2&#93;.y = 0 + &#40;height/2&#41;;
                vertices&#91;2&#93;.z = 0;
                vertices&#91;3&#93;.u = sx + j;
                vertices&#91;3&#93;.v = sy + height;
                vertices&#91;3&#93;.x = &#40;0 - &#40;width/2&#41;&#41; + j;
                vertices&#91;3&#93;.y = 0 + &#40;height/2&#41;;
                vertices&#91;3&#93;.z = 0;
 
		sceGumDrawArray&#40;GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 1*4, 0, vertices&#41;;
		j += sliceWidth;
	&#125;

        sceGuTexMode&#40;GU_PSM_8888, 0, 0, 0&#41;;
&#125;
The problem is that I seem to get two horizontal lines across the screen (regardless of the image used).

Ilustrated in this screenshot:

Image
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

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: Select all

vertices&#91;3&#93;.v = sy + height;
To this to correctly display a 512x512 texture:

Code: Select all

vertices&#91;3&#93;.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: Select all

sceGuTexFilter&#40;GU_NEAREST,GU_NEAREST&#41;;
If I change this to the following then I get no corruption - but the quality leaves very much to be desired:

Code: Select all

sceGuTexFilter&#40;GU_LINEAR,GU_LINEAR&#41;;
If anybody has any ideas I'd be happy to hear them.

Thanks.
Post Reply