Jump to content
  • Advertisement
Sign in to follow this  
thejelmega

[C++] Changing Fore And Back Color Of Text

This topic is 793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been interesting in making something in the style of dwarf fortress, so I want to find a way to change the fore and background color of individual characters.

I'm on Windows, so I've looked at SetConsoleTextAttribute(), but It is very limited in color and I'd prefer having a way of changing the colors using rgb values.

 

Seeing that I'vs tried SetConsoleTextAttribute(), so It's no problem even if it is a platform specific way.

 

If you know a way to do it, please let me know.

Edited by thejelmega

Share this post


Link to post
Share on other sites
Advertisement
If you aim in the direction of Dwarf Fortress you might be better served by something like pdcurses. There is also libtcod but there are some design decisions in there that never sat well with me and it's not in active development. Different libraries may have sprung up since the last time I investigated the DF-related ecosystem though.

Share this post


Link to post
Share on other sites

I don't know the game, but it looks text-ish.

 

There is nothing that prevents you from "cheating", and draw text-like graphics to a window. After all, this is how a real console also works.

Share this post


Link to post
Share on other sites

@OP: Dwarf Fortress is not using the system terminal/console for graphics. It has its own rendering system. Two actually, one using SDL and one using OpenGL. While some 'old skool' ASCII games do have support for the system terminal, most of them still have custom renderers. libtcod is pretty widely used for this sort of thing. See CogMind for a relatively popular recent example using it.

 

 

If you aim in the direction of Dwarf Fortress you might be better served by something like pdcurses. There is also libtcod but there are some design decisions in there that never sat well with me and it's not in active development. Different libraries may have sprung up since the last time I investigated the DF-related ecosystem though.

FYI, libtcod is still active under a different maintainer over at bitbucket.

Share this post


Link to post
Share on other sites

@OP: Dwarf Fortress is not using the system terminal/console for graphics. It has its own rendering system. Two actually, one using SDL and one using OpenGL.

Well, last time I did that research (which was admittedly a few years ago) they were simply using the SDL-variant of pdcurses. Personally I would advise someone new to use that as starting point instead of trying to roll something by hand. The startup time is going to be significantly quicker and if you are interested in text mode games you probably don't want to spend too much time messing about with OpenGL...

Share this post


Link to post
Share on other sites

The OpenGL renderer in DF was implemented quite some time ago. You can see several old bug reports for it in their issue tracker.

And for clarity, I wasn't recommending the OP to use OpenGL, but rather libtcod. My intent was to express that most such games take that approach these days and libtcod is an easy way to get going with it. It can use either SDL or OpenGL under the hood.

Share this post


Link to post
Share on other sites

Thanks for the replies, in the meantime I've also been searching some more on the internet and it seems that newer version of dwarf fortress which can be run on linux seem to use SDL, so I'll look into SDL, which also would give me a system to handle input more easily, because I was planning to use getch, but it is a bit annoying when it comes to arrow keys and things like that.

Edited by thejelmega

Share this post


Link to post
Share on other sites

Thanks for the replies, in the meantime I've also been searching some more on the internet and it seems that newer version of dwarf fortress which can be run on linux seem to use SDL, so I'll look into SDL, which also would give me a system to handle input more easily, because I was planning to use getch, but it is a bit annoying when it comes to arrow keys and things like that.

 

Even if you were to use OpenGL directly, you would still want SDL (or something similar, like GLFW) to handle window creation and input in a cross-platform manner. I still recommend libtcod. It uses SDL for input and such. More importantly, it has several features that, if you start from scratch, you would need to implement yourself when you need them, such as a 'console' to draw your ASCII characters to, loading of ASCII fonts and tile sheets, pathfinding & line of sight, and more. You can choose between renderers based on SDL and OpenGL, and can implement any custom rendering you need on top.

Of course, if you want to do it all from scratch, that's fine, but libtcod will save you a good bit of time. I'm not a fan of its API myself, but it's the most complete solution I know that's usable in multiple languages.

Edited by Aldacron

Share this post


Link to post
Share on other sites

I've tried using sdl, but than I remembered I could also do it with sfml last night, in which I have a bit more experience and for me, it seems a bit easier.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!