Page 1 of 1

RGB15 does not work

Posted: Tue May 12, 2009 6:11 pm
by Antoine_935
Hi there.

Still playing around to learn libnds, I'm in trouble understanding some basic things.
Maybe I could avoid lots of these questions if I could find some theory about bg and memory, but I still didn't find any really good :( Do you have some links ?

Ok, here are my problems.
(Note: I'm currently working under the Desmume emulator)

The first one is about MODE_FB, a little misunderstanding...
Consider this code:

Code: Select all

int main() {
    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);
    lcdMainOnTop();
    
    drawHorizontalLine(VRAM_A, 30, 30, 50, RGB15(31, 31, 31));
    drawVerticalLine(VRAM_A, 30, 30, 50, rand());
    
    drawRect(VRAM_A, 0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, rand());
    
    while(1) {
        swiWaitForVBlank();
    }
    
    return 0;
}
So far, the above works fine, but maybe you can spot some slight errors ?
When I have a look at the documentation: MODE_FB0
MODE_FB0 video display from main memory
MODE_FB1 video display directly from VRAM_A in LCD mode
Therefore I thought that using MODE_FB1 instead of FB0 would work, but no :( Why ?

My second problem is related to MODE_3_2D. Look for the comments, they contain the questions.
This code has been stolen from another post here, and a little bit changed: that's maybe where my error comes from, but... can't find

Code: Select all

int main(void) {
	PrintConsole console;
	touchPosition touch;
	int bgOffset;
	u16 *gfxBG;
	
	videoSetMode(0); // Disable main screen
	videoSetModeSub(MODE_3_2D);
	
	console = *consoleInit(0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, false, true);
	
	bgOffset = 2; // Why this ?
	
	bgInitSub(BG_PRIORITY_3, BgType_Bmp16, BgSize_B16_256x256, bgOffset, 0 );
	gfxBG = BG_GFX_SUB + ((bgOffset * 16384) >> 1);
	
	iprintf("Console works fine");
	
	while(1) {
		scanKeys();
		
		if(keysHeld() & KEY_TOUCH) {
			touchRead(&touch);
			
			// If I don't shift left RGB15, it will not display at all
			// where on the previous program it worked nicely. Did I miss something ?
			gfxBG[touch.py * SCREEN_WIDTH + touch.px] = RGB15(31, 31, 31) << 1;
		}
		
		swiWaitForVBlank();
	}
}
Edit: mmh, comments are not easy to find, sorry... let me tell questions here.
1. What's the use and meaning of this bgOffset I have to use in bgInitSub ?
2. RGB15 macro works weirdly this time. I have to shift it left in order to get it displayed...

Re: RGB15 does not work

Posted: Tue May 12, 2009 8:19 pm
by vuurrobin
not sure about MODE_FB1 or bgOffset, but if you're not working with the framebuffer, you need to set the alphabit that tells if the pixel is visible or not. if you use RGB16(1, 31, 31, 31) it should work with mode 3.

as for links, have you looked at pataters manual and dev-scenes tutorial? they may be a bit outdated, but there is still some good info on it.

Re: RGB15 does not work

Posted: Tue May 12, 2009 11:23 pm
by Antoine_935
Compiler can't find RGB16 macro, where is it defined ? (anyway I defined it right now, but duplication is a bad idea...)

I already read Patater's manual, but he's not really talking about this, or I missed it.
However I should have a deeper look at dev-scenes...

Thank you for your answer ;)

Re: RGB15 does not work

Posted: Wed May 13, 2009 9:03 pm
by vuurrobin
its ARGB16(), defined in sprite.h

sorry, my bad :oops:

Re: RGB15 does not work

Posted: Thu May 14, 2009 5:54 pm
by Antoine_935
Found it :) it was located in nds/arm9/video.h

Re: RGB15 does not work

Posted: Fri May 15, 2009 7:51 am
by eKid
Hmm, seems like an error in the docs there. FB0/1/2/3 modes should use VRAM_A,B,C,D, and I think MODE_FIFO should be that other mode it says MODE_FB0 is for.

Re: RGB15 does not work

Posted: Sun May 17, 2009 12:13 pm
by Antoine_935
Good to know, thx :)