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 (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);
}
Ilustrated in this screenshot: