gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Drawing a line

#51438 - iainprice - Fri Aug 19, 2005 4:14 pm

Yes I know this sounds like a silly question... but is there a nice simple way to draw a line when using Mode5? Or do I have to make a long thin sprite?

#51441 - natrium42 - Fri Aug 19, 2005 4:51 pm

You could plot pixels to the background using some line drawing algorithm like the ones given here: http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html

Darkain's Painter from DarkStar should have some line algorithm implemented for Mode5. Check his source code.
_________________
www.natrium42.com

#51459 - iainprice - Fri Aug 19, 2005 9:32 pm

I'm having some problems putting a pixel on the bottom screen. I am doing the following:

videoSetMode(MODE_0_3D);
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE);
vramSetMainBanks(VRAM_A_TEXTURE, VRAM_B_LCD, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE);

and then:
VRAM_B[(10*SCREEN_WIDTH)+21] = 0x7FFF;

or:
VRAM_C[(10*SCREEN_WIDTH)+21] = 0x7FFF;

but neither work... am I missing something somewhere?

any ideas?

Thanks.

#51465 - natrium42 - Sat Aug 20, 2005 12:22 am

This looks wrong. Check the Mode5 example in ndslib.
You need to write pixels to BG_GFX and not directly to the banks, for one thing.
_________________
www.natrium42.com

#51468 - iainprice - Sat Aug 20, 2005 12:47 am

even if I try setting BG3 for BMP image:

BG3_CR = BG_BMP8_256x256;

and then address the BG_GFX:

BG_GFX[(10*SCREEN_WIDTH)+20] = 0x7FFF;

still nothing...

#51477 - natrium42 - Sat Aug 20, 2005 3:36 am

Yes, you are using a paletted BG mode without setting the palette colors.

If you want 16-bit colors as you imply by "0x7FFF;" do the following:
Code:

powerON(POWER_ALL_2D);

videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_LCD, VRAM_C_SUB_BG , VRAM_D_LCD);

BG3_CR = BG_BMP16_256x256;

BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;

BG3_CX = 0;
BG3_CY = 0;

// to plot a pixel to position (x,y) with color values (R,G,B) do this:
BG_GFX[256*y + x] = RGB15(R, G, B) | (1 << 15);

_________________
www.natrium42.com

#51662 - iainprice - Mon Aug 22, 2005 8:30 pm

I am now trying:

[/code]
powerON(POWER_3D_CORE|POWER_2D_SUB);
videoSetMode(MODE_5_3D);
videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_ACTIVE);
vramSetMainBanks(VRAM_A_TEXTURE, VRAM_B_LCD, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE);
BG_PALETTE_SUB[255] = RGB15(31,31,31);

irqInitHandler(irqDefaultHandler);
irqSet(IRQ_VBLANK, 0);

glViewPort(0,0,255,191);
glClearColor(0,0,0);
glClearDepth(0x7FFF);

SUB_BG3_CR = BG_BMP8_256x256;
SUB_BG3_XDX = 1<<8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1<<8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0;


BG_GFX[256*50 + 50] = 100;


[/code]

but still no pixels... where am I going wrong????

#51666 - dovoto - Mon Aug 22, 2005 8:56 pm

If you want a pixel on the sub screen it is recomended that you address sub screen graphics memory via BG_GFX_SUB[] as apposed to BG_GFX
_________________
www.drunkencoders.com

#51667 - natrium42 - Mon Aug 22, 2005 9:01 pm

Again, you are using a paletted mode without setting palette colors.

BG_GFX_SUB[256*50 + 50] is actually 2 color indexes for two pixels in the mode you are using. Since 100 = 0x0064, one index is 0x00 and the second is 0x64. So if you set BG_PALETTE_SUB[0x64] = RGB15(31,0,0); you should see a red pixel. Index 0x00 is transparency.

If you don't want to use a palette and use 15-bit color instead, use code similar to the one I posted and/or follow the tutorial here: http://www.double.co.nz/nintendo_ds/nds_develop10.html

Also, BG_GFX should be BG_GFX_SUB or whatever the name is :)
_________________
www.natrium42.com

#51669 - iainprice - Mon Aug 22, 2005 9:04 pm

Doh!

Cheers.