GP32 Doublebuffering With Mrmirko's Sdk


manika

Still Fresh
Joined
Mar 20, 2004
Messages
5
ok, so here is my problem:
I'm using doublebuffering as explained in synkro's tutorial no. 3
but for some reason it doesn't work and I just don't know why.
in the program below I was trying to draw a circle on framebuffer[0], display it and the start drwaing the same circle on framebuffer[1] and display it when it's done and then start at the begionning, so basically it should display a circle at the same position all the time.
BUT for some reason there are circles at 3 different positions flickering all the time, although both framebuffers use the same starting point and the same radius and the same drawCircle fuction.
If you comment the nflip++ and the nflip = nflip%2 there is only one circle at the same postion all the time flickering.
If somebody can help me solve this problem I'd really appreciate it cause it starts to drive me insane.
So thanks in advance.



Code:
#include <gp32.h>
#include <stdlib.h>
#include <math.h>

#define WIDTH 320
#define HEIGHT 240
u16 *framebuffer[2];
int nflip = 0;

void clrScreen (int x);
void drawCircle (int x, int y, int radius, int flip);

int i,j,cox,coy;
int wander =100;
float coskreis[360];
float sinkreis[360];
float radian;

int main() {
    gp_SetCpuSpeed(66);
    framebuffer[0] = (u16*) FRAMEBUFFER;
    framebuffer[1] = (u16*) (FRAMEBUFFER + (WIDTH +HEIGHT)*2);
    gp_SetScreen (framebuffer[1], 16);

    // set both frames white
    for (i = 0; i< WIDTH * HEIGHT;i++) {
        framebuffer[0][i] = 0xFFFF;
        framebuffer[1][i] = 0xFFFF;
    }

    // sine und cosine precalc
    for (i = 0;i<360;i++){
        radian = ((2*M_PI*i)/360);
        coskreis[i]= cos(radian);
        sinkreis[i]= sin(radian);
    }

    while (1) {

          clrScreen (nflip);
          drawCircle (wander,wander, 50, nflip);
          gp_SetView(framebuffer[nflip]);
          nflip++;
          nflip = nflip % 2;

    }
}

// clearScreen function
void clrScreen (int x) {

     for (i=0;i<WIDTH*HEIGHT;i++) {
         framebuffer[x][i] = 0xFFFF;
     }
}

// drawCircle function
void drawCircle (int x, int y, int radius, int flip) {

     for (i=0;i<360;i++) {
         cox = (int) (radius * sinkreis[i]);
         coy = (int) (radius * coskreis[i]);
         gp_SetPixel16(x+cox, y+coy, 0, framebuffer[flip]);
     }
}
 
Code:
framebuffer[1] = (u16*) (FRAMEBUFFER + (WIDTH +HEIGHT)*2);

Shouldn't it be...

Code:
framebuffer[1] = (u16*) (FRAMEBUFFER + (WIDTH *HEIGHT)*2);

That may be it...
 
jesus f...... christ
I'm so stupid, thanks so much, i even doublechecked that line and didn't see it the first time and the second time I wrote that program.
Thanks again.
 
Back
Top