How to display text on the screen?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Dreamcastfreak2004
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon Aug 30, 2021 6:42 pm
Has thanked: 0
Been thanked: 0

How to display text on the screen?

Post by Dreamcastfreak2004 »

Hey everyone, I have a question, so I want make a program that displays “Hello, Dreamcast!” on the screen, but how do I display text on the screen?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5659
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to display text on the screen?

Post by BlueCrab »

Assuming you're using a relatively modern version of KOS, the easiest way to do a simple "hello world" type thing with text on the screen is to use fb_console, and then just printf as normal. Essentially, this is all you need:

Code: Select all

#include <stdio.h>
#include <kos/dbgio.h>

int main(int argc, char *argv[]) {
    /* Switch printf to draw to the screen with fb_console */
    dbgio_dev_select("fb");

    /* The requisite line... */
    printf("Hello, Dreamcast!\n");

    return 0;
}
Now, if you wanted to go fancier, you could use the biosfont functionality directly. For that, I'd refer you to this example which shows the basic approach to using it to draw to the framebuffer.
These users thanked the author BlueCrab for the post (total 2):
1337Neoblast
Dreamcastfreak2004
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
Joined: Mon Aug 30, 2021 6:42 pm
Has thanked: 0
Been thanked: 0

Re: How to display text on the screen?

Post by Dreamcastfreak2004 »

UDATE: it compiled successfully, but when I try to test it on real hardware it just goes to a black screen. what should i do now?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5659
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to display text on the screen?

Post by BlueCrab »

It probably isn't actually going to a blank screen, but rather exiting quickly... This version will sit around a bit longer after the text appears, in this case 10 seconds:

Code: Select all

#include <stdio.h>
#include <kos/dbgio.h>
#include <kos/thread.h>

int main(int argc, char *argv[]) {
    /* Switch printf to draw to the screen with fb_console */
    dbgio_dev_select("fb");

    /* The requisite line... */
    printf("Hello, Dreamcast!\n");

    /* Sleep for a bit to see the results. The amount here is in milliseconds. */
    thd_sleep(10 * 1000);

    return 0;
}
Dreamcastfreak2004
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
Joined: Mon Aug 30, 2021 6:42 pm
Has thanked: 0
Been thanked: 0

Re: How to display text on the screen?

Post by Dreamcastfreak2004 »

Thanks I will try that when I get home, also is there and sdl for the Dreamcast that I can follow?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5659
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: How to display text on the screen?

Post by BlueCrab »

SDL? Yes, there's a port of version 1.2.x of SDL in kos-ports. It's not great (because it isn't really designed for how the Dreamcast hardware works), but it is there and you can use it if you really want.

I wouldn't recommend it, though.

There is not a port of SDL 2.x, and I wouldn't expect a full port of that to ever be available (once again, because it is designed for a much different hardware target than what the Dreamcast is).
1337
DCEmu Newbie
DCEmu Newbie
Posts: 7
Joined: Tue Nov 29, 2022 7:09 am
Location: Where sailors hang out
Has thanked: 9 times
Been thanked: 3 times

Re: How to display text on the screen?

Post by 1337 »

Is there a way to remove the black background behind the text? I just want to display the game score without importing complex libraries and lowering frame rate.
Post Reply