GP32 Making a surface.


AndrewN

Still Fresh
Joined
Apr 8, 2003
Messages
4
I'm trying to make a buffer, one that's a few times wider than the LCD. That shouldn't be a problem ... right? Here's how I'm going about it:

Code:
    GPDRAWSURFACE mySurface, LCD[2];

    GpLcdSurfaceGet(&LCD[0], 0);
    GpLcdSurfaceGet(&LCD[1], 1);

    GpSurfaceSet(&LCD[0]);

    mySurface.buf_w = LCD[0].buf_w * 2;
    mySurface.buf_h = LCD[0].buf_h;

    /* Scrawl on the surface (black BG with white diagonals) */
    GpRectFill(NULL, &mySurface, 0, 0, mySurface.buf_w, mySurface.buf_h, 0x00);
    GpLineDraw(&mySurface, 0, 0, mySurface.buf_w, mySurface.buf_h, 0xff);
    GpLineDraw(&mySurface, 0, mySurface.buf_h, mySurface.buf_w, 0, 0xff);

    /* Blit some of the surface onto the backbuffer */
    GpBitBlt(NULL, &LCD[1], 0, 0, LCD[1].buf_w, LCD[1].buf_h, mySurface.ptbuffer, 0, 0, mySurface.buf_w, mySurface.buf_h);

    /* Show the back buffer */
    GpSurfaceSet(&LCD[1]);

The trouble comes when I compile and run the gxb on GeePee32.exe to test it - It dies with an application error. It doesn't seem to crash when I coment out the lines to do with drawing on/blitting with mySurface ... :huh:
 
When you create a surface I believe they are fixed to being 320 x 240, atleast through the gp32 functions, anyway. What you're actually doing is just changing the value stored in the buf_w variable, and not actually changing the size itself. I'm afraid I don't know how to change the size of surfaces as I've never needed to do it before. Hopefully someone else will be able to help you with that bit :/
 
:blink:

Since you haven't initialised mySurface.ptbuffer, I'm not surprised that it crashes! The GpRectFill and GpLineDraw will be writing to random memory locations.

If you add
Code:
mySurface.ptbuffer = (unsigned char *)gm_malloc(2*320*240);
before you draw to mySurface, you'll have a better chance of it working.

Sorry, I'm at work and I can't test it right now. Hopefully this will get you closer to a solution :)
 
It works... yes! ... it seems obvious now that I wasn't actually setting up the buffer. :rolleyes:

Grateful for your help, thanks a lot.
 
Back
Top