Welcome! Log In Create A New Profile

Advanced

Issue with displaying a textured quad

Posted by DaveB1980 
Issue with displaying a textured quad
December 23, 2014 04:52AM
I'm working on building my first Wii game and I'm having a very, very confusing issue with texturing a quad. I'm relatively certain that I figured out how to include the texture file itself and to get it to be compiled with the binary at build time, but at run-time, it's all screwed up (for lack of a better way to say it). Below are two screen shots; one of what *should* be appearing on screen and one of what I'm seeing.

Working: http://www.webetry.com/misc/WorkingTexture.png
Broken: http://www.webetry.com/misc/BrokenTexture.png

The code that is being run at render time is as follows:

    // Before starting rendering
    guMtxIdentity(mGXmodelView2D);
    guMtxTransApply (mGXmodelView2D, mGXmodelView2D, 0.0F, 0.0F, -5.0F);
    GX_LoadPosMtxImm(mGXmodelView2D, GX_PNMTX0);


    // Begin Draw, set mode to Quads
    GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
    
    // Top Left
    GX_Position2f32(quadCoords[0][0], quadCoords[0][1]);
    GX_TexCoord2f32(texCoords[0][0], texCoords[0][1]);

    // Top Right
    GX_Position2f32(quadCoords[1][0], quadCoords[1][1]);
    GX_TexCoord2f32(texCoords[1][0], texCoords[1][1]);
    
    // Bottom Right
    GX_Position2f32(quadCoords[2][0], quadCoords[2][1]);
    GX_TexCoord2f32(texCoords[2][0], texCoords[2][1]);
    
    // Bottom Left
    GX_Position2f32(quadCoords[3][0], quadCoords[3][1]);
    GX_TexCoord2f32(texCoords[3][0], texCoords[3][1]);
    
    // End Draw
    GX_End();


    // After rendering
    GX_DrawDone();
    
    GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
    GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
    GX_SetAlphaUpdate(GX_TRUE);
    GX_SetColorUpdate(GX_TRUE);
    GX_CopyDisp(mFrameBuffers[mFrameBufferIndex], GX_TRUE);
    
    VIDEO_SetNextFramebuffer(mFrameBuffers[mFrameBufferIndex]);
    
    if(mFirstFrameBuffer)
    {
        VIDEO_SetBlack(FALSE);
        mFirstFrameBuffer = 0;
    }
    VIDEO_Flush();
    VIDEO_WaitVSync();
    mFrameBufferIndex ^= 1;

The weird grayscale thing going on with the image makes me wonder if it's a format issue. In my .scf file, I have colfmt set to 6 for PNG. That is correct, right?

Are there any quirks as far as image encoding, compression or color profiles that I need to be aware of when exporting graphical assets to use?
Re: Issue with displaying a textured quad
December 24, 2014 03:05AM
i think you set the GX stuff before you push the vertex info.

similar to how the lights are done in this post; [forum.wiibrew.org]
Re: Issue with displaying a textured quad
December 24, 2014 04:21AM
Quote
owen
i think you set the GX stuff before you push the vertex info.

similar to how the lights are done in this post; [forum.wiibrew.org]
Thanks for the replies, Owen. Very helpful!

So, I did some more experimentation today and took another closer look at the gxSprites example. As it turned out, the primary issue was that I wasn't loading the texture correctly. While all of the preparation was right, I misunderstood the part about having to load the texture into memory when needed. Once I changed things around and got that right, it started rendering.

The issue I have run into now is my texture is squashed; it's either too short or too wide. I didn't change any of the viewport or projection settings from gxSprites so I'm not sure what's causing it. Any ideas or suggestions?



Edited 1 time(s). Last edit at 12/24/2014 04:22AM by DaveB1980.
Re: Issue with displaying a textured quad
December 24, 2014 04:27AM
All I can say is the texture size should be a multiple of 2. Other than that you can look up the grrlib source code to get some hints as to why it's squished.
Re: Issue with displaying a textured quad
December 24, 2014 06:28AM
Yeah, the texture image size is definitely a multiple of 2 (64x64). It's actually coming from a sheet that contains frames for multiple animations.

As I change the sprite's state, the texture is updating accordingly, it's just oddly skewed. When I do a measurement against a screen capture, it seems as though the quad's height is what's wrong/shorter than it should be. I thought at first maybe it was the data driving it -- I have data files that are compiled at build time -- but even when I hard-code the dimensions, it's still not square. :(

Screenshot of the "smushed" texture: http://www.webetry.com/misc/SmushedTexture.png
Screenshot of the texture w/ correct proportions: http://www.webetry.com/misc/WorkingTexture.png

It's a different problem altogether, but something I noticed is when I try to load multiple textures using separate GX_LoadTexObj() calls, they get screwed up; I end up back with the weird black and white jumble in my first post. My uneducated guess is that if I want to use multiple sprite sheets, I need to use different GX_MAPX flags in GX_LoadTexObj(). Is that correct?

I dug through gx.h and noticed it has GX_MAP0 to GX_MAP7, so there's a limit to how many I can use at once basically?

Sorry for all the questions, fighting the learning curve. :)



Edited 1 time(s). Last edit at 12/24/2014 06:29AM by DaveB1980.
Re: Issue with displaying a textured quad
December 24, 2014 12:49PM
Or maybe you could have a big texture map. Or load each texture only before it us drawn.
Sorry, only registered users may post in this forum.

Click here to login