Welcome! Log In Create A New Profile

Advanced

OpenGL glReadPixels equivalent and GX_CULL question

Posted by dashxdr 
OpenGL glReadPixels equivalent and GX_CULL question
September 12, 2010 04:45PM
Is there an equivalent to glReadPixels? I want to be able to capture the video buffer for a screenshot.

The sense for GX_CULL_FRONT and GX_CULL_BACK seem to be the opposite of OpenGL, and none of the example code seems to use culling. Does anyone have any insight into this? In the jewels game I just ported I turned on GX_CULL_BACK but I had to reverse the order of all vertices in the triangles / quads used in order to get everything to render correctly. I wonder if the #defines for GX_CULL_FRONT and GX_CULL_BACK are reversed...

Thanks!
Re: OpenGL glReadPixels equivalent and GX_CULL question
September 12, 2010 05:05PM
Quote
dashxdr
Is there an equivalent to glReadPixels? I want to be able to capture the video buffer for a screenshot.

I found mention of GRRLIB_Screen2Texture for a bloom effect which might serve, I found this section of code:


/**
 * Make a snapshot of the screen in a texture WITHOUT ALPHA LAYER.
 * @param posx top left corner of the grabbed part.
 * @param posy top left corner of the grabbed part.
 * @param tex A pointer to a texture representing the screen or NULL if an error occurs.
 * @param clear When this flag is set to true, the screen is cleared after copy.
 */
void  GRRLIB_Screen2Texture (int posx, int posy, GRRLIB_texImg *tex, bool clear) {
    if(tex->data != NULL) {
        GX_SetTexCopySrc(posx, posy, tex->w, tex->h);
        GX_SetTexCopyDst(tex->w, tex->h, GX_TF_RGBA8, GX_FALSE);
        GX_CopyTex(tex->data, GX_FALSE);
        GX_PixModeSync();
        GRRLIB_FlushTex(tex);
        if(clear)
            GX_CopyDisp(xfb[!fb], GX_TRUE);
    }
}

Presumably I can create a texture, do the above steps, then access the texture memory directly...

ETA: Wrapped code section inside proper tags



Edited 1 time(s). Last edit at 09/12/2010 07:54PM by dashxdr.
Re: OpenGL glReadPixels equivalent and GX_CULL question
September 13, 2010 01:58AM
Quote
dashxdr
Is there an equivalent to glReadPixels?
Yes, There is! I actually had to find it when porting the OGL code to GX for DesmumeWii. The code to do so is thus:
GX_SetTexCopySrc(x, y, w, h); 
GX_SetTexCopyDst(w, h, GX_TF_RGBA8, GX_FALSE);
GX_CopyTex(copyToThis, GX_TRUE);
GX_PixModeSync();
Just replace it with your numbers. You can see the whole thing in the ReadFramebuffer() function here. I would also recommend turning off the copy filter before copying, and re-setting it when you're done.
Quote
dashxdr
I wonder if the #defines for GX_CULL_FRONT and GX_CULL_BACK are reversed...
Front-facing on the Wii is the opposite direction as it is in OGL. This is intentional and part of the hardware. This is why we had to reverse the order of vertices here.
Re: OpenGL glReadPixels equivalent and GX_CULL question
September 13, 2010 04:13AM
Quote
dancinninja
Yes, There is! ... Front-facing on the Wii is the opposite direction ...

Thanks for your answer! BTW I did get the reading out of the screen to work, and captured a 640x480 image, which I used to update the wiibrew.org page for jewels.
Sorry, only registered users may post in this forum.

Click here to login