• Welcome to SCdev.org. Please log in.

Welcome to the new SCdev forums!

Programming Help Wanted!

Started by FearnleyP, March 01, 2006, 01:49:27 PM

Previous topic - Next topic

FearnleyP

For my third DS tutorial I have written a simple game using MODE 0, text only (trying to keep it simple...).

The only thing I cannot figure out for myself (and I have searched just about every DS guide and Wiki on the web!) is how to change the text color (and remember, I am not using PA_Lib, just basic ndslib with devkitPro).  I can change the full screen of text to any color, but I just want to print certain words or characters in a particular color, leaving the existing text 'as is'.  It's driving me crazy!!! :evil:

Can anyone point me in the direction of an existing tutorial or give me guidance?  All help very much appreciated (I will even give you the credit!!! :D  :D)

Thanks in advance.
K DS (Silver) / Supercard CF / 1Gb SanDisk Ultra II CF / FlashMe v7

//www.dsprogramming101.com

omaemad

SUB_BG0_CR = BG_MAP_BASE(31);
   
   BG_PALETTE_SUB[255] = RGB15(31,31,31);   //by default font will be rendered with color 255
   
   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);


the bg paletlet part
man fears time but time fears the pyramid"

FearnleyP

Ummm.... nope, sorry :? .  That will change the color of ALL the text on the screen.

I want to change just one bit of text on the screen. Ideally, the bit I am about to 'printf'.

Thanks anyway!
K DS (Silver) / Supercard CF / 1Gb SanDisk Ultra II CF / FlashMe v7

//www.dsprogramming101.com

bitblt

Quote from: "FearnleyP"I can change the full screen of text to any color, but I just want to print certain words or characters in a particular color, leaving the existing text 'as is'.

I only use mode 0 to output debugging information, so I'm not an expert regarding this mode.  From what I understand mode 0 is a special tile mode that draws text by referencing a monochrome font bitmap.  I believe there is only one color register for mode 0, so all text will be displayed in the same color.  If you want multi-color text and multi-color fonts you need to make your own font bitmaps, and write your own code to display them.  I don't think using PALIB in your tutorials would be a bad thing.

EDIT: (maybe ask Aaron Rogers how he did it in PALIB)

omaemad

why not change the Pallette color before drawing your printf

then return it
man fears time but time fears the pyramid"

bitblt

Quote from: "omaemad"why not change the Pallette color before drawing your printf then return it

Does that work? Please show FearnleyP (and me) that one line of code.

FearnleyP

Looking on Aaron's site, he says you can only have one color for text per screen.

However, I am certain that I have seen a demo where every letter of the 'Hello World!' message was in a different color...  But of course, now I want to use that method, I can't find the tutorial!! If and when I do find it, I just know it won't be using MODE 0...

I have tried the following:

BG_PALETTE_SUB[255] = RGB15(31,31,31);
printf("hello");
BG_PALETTE_SUB[255] = RGB15(31,0,0);
printf("world");

This prints all the text in red. (i.e. by changing palette 255, you are cxhanging every white pixel for red).  I want to change which ink in the palette is being used.

I have tried ANSI codes (which look like this):

printf("\x1b[31mHello");

This prints llo on the screen.... in the same color.... :x

I have also tried to locate the code in the PA_lib that runs when PA_SetTextCol() is called (to be honest, I haven't tried printing multiple colors using PA_lib but I will have a go...) but haven't found it...yet!

I will have another look at PA_lib today and see if I can suss it out.... In the meantime, thanks bitblt and omaemad for trying!!!  And any suggestions/links/thoughts from anyone welcomed!
K DS (Silver) / Supercard CF / 1Gb SanDisk Ultra II CF / FlashMe v7

//www.dsprogramming101.com

FearnleyP

Well, I have to admit defeat.... sort of!  PA_lib uses a tile mode to display the font in different colors and my site is basic programming, so it's too much to write a tutorial on at the moment.... :(

Thanks again, bitblt and omaemad for your help.  You are duly mentioned on my homepage... :D

For anyone else interested, I have posted tutorial number 3 - a simple game.  Give it a go - homebrew programming isn't that hard to do.... :roll:
K DS (Silver) / Supercard CF / 1Gb SanDisk Ultra II CF / FlashMe v7

//www.dsprogramming101.com

bitblt

Excellent work FearnleyP. I think you are providing a great service for those trying to get started programming Nintendo DS.  Yes, there are sometimes difficulties working with consoles like GBA/DS, but in general I believe they are good platforms to learn game programming.