#32427 - QuantumDoja - Wed Dec 22, 2004 7:56 pm
Hi, I was just wondering, if i wanted to change the color of every pixel every vblank, what the fastest way to do it, because when i try, i get crazy black lines moving over my screen, sort of like a refresh.
Heres a link to my compiled *.gba.......
www.demonasp.co.uk/gba/Main.zip
.....how do people get over this problem so it looks smooth?
_________________
Chris Davis
#32431 - ScottLininger - Wed Dec 22, 2004 8:31 pm
A few questions before I think we'll be able to answer your question:
1. What screen mode are you using?
2. What's your code like? If you can post the key "loop" that's drawing the screen, people might suggest some optimizations
3. What compiler are you using and what optimization parameters (if any) are you using? You can probably copy and paste your "gcc" line from your make.bat or your makefile options.
-Scott
#32432 - DekuTree64 - Wed Dec 22, 2004 8:39 pm
There's not enough time in a VBlank to redraw the entire screen. That's what the backbuffer in mode4 is for, so you can draw to it outside of VBlank, and for as many frames as you need to to get it done before showing anything.
It is possible to copy a full solid screen if you draw it line by line from the top down starting at VBlank. You won't actually finish before the screen starts drawing again, but you can get enough of a head start to outrun the displaying scanline so it's all done before it's visible.
The fastest way to get data to the screen is DMA, but that pretty much means having a backbuffer in EWRAM, since it's a straight copy. You'll probably need to do that for mode3, although it's so slow I'd suggest trying to find another way (tile modes preferably, mode4 if it has to be bitmap)
EDIT: I just checked your demo and it looks like you are using mode4 already. To fix it, just flip flop between the two buffers each frame, waiting for VBlank each time you're finished drawing and ready to swap.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#32439 - QuantumDoja - Wed Dec 22, 2004 10:02 pm
Hi, Im a bit of a newbie, so I may just be bodging it to make it work, but have a look:
vars n stuff
Code: |
int MatrixLine[119]; //for x axis: color of first pixel (mode4 240/2)
|
color palette
Code: |
const u16 MatrixPalette[] = {
0x0000, 0x0101, 0x0202, 0x0303, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
....... 0xFFFF,};
|
plot pixel
Code: |
void PlotPixel(int x,int y, unsigned short int c)
{
FrontBuffer[(y) *120 + (x)] = (c);
}
|
draw screen
Code: |
void DrawScreen()
{
//drawing entire screen.
int i;
int j;
int tmp;
for (i=0;i<160;i++)
{
for (j=0;j<120;j++)
{
//holds the number location of the color.
tmp = MatrixLine[j];
if (i>0)
{
tmp = tmp + 1;
MatrixLine[j] = tmp;
}
if (tmp > 3)
{
MatrixLine[j] = 0;
tmp = 0;
}
PlotPixel(j,i,BG_PaletteMem[tmp]);
}
}
}
|
main
Code: |
int main() {
SetMode(MODE_4 | BG2_ENABLE);
//LOAD PALETTE
int i;
int r;
for (i = 0; i < 256; i++) {
BG_PaletteMem[i]=MatrixPalette[i];
}
while(1)
{
DrawScreen();
WaitForVsync();
}
return 0;
}
|
_________________
Chris Davis
#32441 - DekuTree64 - Wed Dec 22, 2004 10:21 pm
Yeah, you need to switch which buffer you're drawing to each frame. The first buffer is at address 0x6000000, and the second is 0x600a000.
All you need to do is make your FrontBuffer variable into a pointer and switch which of those addresses it points to each frame, and switch which is visible by flipping bit 4 in DISPCNT.
If the bit is clear, 0x6000000 is displayed, if it's set, you see 0x600a000. Just make sure you're drawing to the one that's NOT visible, and you shouldn't get any breaking at all.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku
#32453 - Datch - Thu Dec 23, 2004 1:08 am
Like mentionned previously, you're drawing in the same buffer which render your choice of mode 4 useless. If you want to keep things this way I would recommend two easy things. First invert DrawScreen() and WaitForVSync(). Also, I would do a macro with your PlotPixel function or I'd make it "inline".
#32547 - QuantumDoja - Thu Dec 23, 2004 8:16 pm
Hi, thanks I added the extra buffer and wrote to it alternately and it kinda works well, there is a slight slight flicker, but itll do.
THanks :-p
_________________
Chris Davis
#32739 - QuantumDoja - Sat Dec 25, 2004 4:05 pm
Hi, I have added the extra bufer, and now my sprites wont even appear, i am using an emulator to test my game, but no OAM data gets loaded....any ideas???
_________________
Chris Davis
#32741 - tepples - Sat Dec 25, 2004 5:06 pm
For one thing, when you use a bitmap mode such as mode 4, you need to use only tiles 512-1023 of sprite cel VRAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.