Temple of The Roguelike Forums

Development => Programming => Topic started by: toggle on March 27, 2016, 05:47:49 PM

Title: Prettier Graphics with Libtcod?
Post by: toggle on March 27, 2016, 05:47:49 PM
Hello, I've been lurking on the forums for a while and working away at a little rogue game, but I'm very new to Python/Libtcod.

As weird as this sounds (being a rogue game) I kind of want to upgrade the standard ASCII tile output to something nicer. Even if I could get it looking something like Dwarf Fortress (with tiles) that would be awesome (something like this would be fantastic: http://i.imgur.com/FQaND.png).

But so far I can't get anything working (other than just changing the tileset). It seems like tiles in libtcod console are just 1 colour (with different transparencies). I tried overlaying multiple tiles over each other but that doesn't seem to work, it just deletes the tile underneath (even when using a new console layer). It also seems like a lot of trouble (7 different layers and 7 different tilesets overlaid for a 7-colour tile). Is it even possible?

My other question was: perhaps I'm going about this the wrong way? I'm thinking maybe there's a better way to output graphics in Python if I want more colours/options?

Any help or advice would be appreciated, thanks in advance.  :)
Title: Re: Prettier Graphics with Libtcod?
Post by: Quendus on March 27, 2016, 07:29:47 PM
Take a look at BearLibTerminal (http://foo.wyrd.name/en:bearlibterminal). In terms of tile display and keyboard input it has almost the same capabilities as libtcod, plus the features you want (coloured tilesets, tile composition using transparency) and other nice things like unicode characters, multi-tile sprites, and pixel offsets. It doesn't have libtcod's map generation and field-of-vision facilities.
Python support is quite mature, and Mac support (if you need it) is a recent addition which still needs a couple of bugfixes.
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on March 28, 2016, 04:22:26 AM
Take a look at BearLibTerminal (http://foo.wyrd.name/en:bearlibterminal). In terms of tile display and keyboard input it has almost the same capabilities as libtcod, plus the features you want (coloured tilesets, tile composition using transparency) and other nice things like unicode characters, multi-tile sprites, and pixel offsets. It doesn't have libtcod's map generation and field-of-vision facilities.
Python support is quite mature, and Mac support (if you need it) is a recent addition which still needs a couple of bugfixes.
Hey, this looks great. Thanks for the tip.
In theory I think I could use Libtcod for my lighting engine/pathfinding and then use BearlibTerminal for my graphics output, if I still wanted to use those libtcod features. I think.
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on March 28, 2016, 05:47:28 AM
libtcod actually supports multicolored tiles, I'm just not sure where it's documented since it was added much later than the original feature set, so it might not be in the regular documentation.

Here's a shot (http://i.imgur.com/SHKrAOa.jpg) of one of the first libtcod games to make heavy use of it. (Though that game was never finished, and this was about three years ago.)
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on March 28, 2016, 12:48:40 PM
libtcod actually supports multicolored tiles, I'm just not sure where it's documented since it was added much later than the original feature set, so it might not be in the regular documentation.

Here's a shot (http://i.imgur.com/SHKrAOa.jpg) of one of the first libtcod games to make heavy use of it. (Though that game was never finished, and this was about three years ago.)
Wow, that's incredible! I would love to know how on earth they did that. There's almost no information at all online about how to fiddle with libtcod's console output. In that example they definitely weren't just layering, unless they used hundreds of layers.

The only thing I was able to find was this: http://roguecentral.org/doryen/forum/index.php?topic=1468.45
From what I can gather the dev just layered 4 or more tiles over each other to get the effect but it seems like a really lengthy process.
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on March 28, 2016, 12:55:30 PM
Ah yeah, there you go, one of the discussion threads. I wasn't sure those forums were still around since libtcod stuff has disappeared before and some of it hasn't returned.

Really no matter what tile solution you use, you're going to end up with multiple layers, at least for the ground and whatever's sitting on top of it at that position (if anything). Unless you go the black background route, which generally calls for simpler tiles. pat's example in that thread looks pretty good, and is fairly simple to implement. That only requires one layer (though he's also demonstrating the use of subtile sizes there, something you don't necessarily need).
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on March 28, 2016, 01:17:06 PM
I'm fine with layering, like layering characters over ground tiles, or layering a GUI over the top, etc. But I don't want to have to do a layer for each individual colour. For example, if I wanted a 16-colour font, it would mean 16-layers for the ground, 16 for the character, meaning possibly hundreds of layers per tile. But if you're saying there's a simple solution that would be great. There doesn't seem to be any documentation or examples I can find.

When I try and use coloured tiles I just get a silhouette, like this http://imgur.com/OUl56zM

I can change the colour of that black blob but that's about the extent of my graphical abilities haha.
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on March 28, 2016, 01:28:50 PM
Nah, I've never heard of anyone doing a layer per color. That's... unheard of :P

I do know that libtcod can take those sprites and put them down on the map as a single tile, but I've never done it before and didn't see it in the docs so I can't help you there :/
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on March 28, 2016, 01:38:32 PM
Nah, I've never heard of anyone doing a layer per color. That's... unheard of :P

I do know that libtcod can take those sprites and put them down on the map as a single tile, but I've never done it before and didn't see it in the docs so I can't help you there :/

Yeah at first I thought I could use for loops to print hundreds of layers and then I figured it's probably not the most efficient way of doing things. ;)
Yeah it seems like there's not much info available, but thanks anyway! I've managed to get BearLibTerminal up and running so perhaps I'll have more success with that.
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on March 28, 2016, 01:47:15 PM
Yeah by all means go with another display method if you can get it working more easily!
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on March 28, 2016, 02:55:45 PM
Yeah by all means go with another display method if you can get it working more easily!
Wow, this BearLib thing is really powerful and works well, really simple design. Already in half an hour I've got fancy tiles jumping all over my screen.
Though I'm hoping to not get too carried away, I'm intending to strike a good balance between ASCII and pixel art. Nothing too elaborate, but also I want to steer away from just being a white '@' on a black background. I was just peeping at the RexPaint gallery in your signature, there's certainly much to be said for ASCII when it's done well. :)
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on March 28, 2016, 03:02:13 PM
For sure :). Remember one primary rule to get the best results: Stay consistent!

Good luck.
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on April 10, 2016, 10:43:03 PM
I'm not sure whether to post this in this thread or to start a new thread somewhere. Anyway over the last 2 weeks I've fooled around with BearLibTerminal and I've managed to put a little rogue together. It's pretty much identical to the Libtcod tutorial, except the graphical output uses BearLib (instead of the Libtcod console). Plus I added a bunch of other little features, improved pathfinding, etc.

I've put it on Github: https://github.com/tomzimmer/rogue_project

I'm planning to keep working on it and adding new features, update graphics, etc. Right now it's just a kind of proof-of-concept.
Here's a screenshot of what it looks like:
(http://i.imgur.com/CPnNnTr.png)
Title: Re: Prettier Graphics with Libtcod?
Post by: Kyzrati on April 11, 2016, 12:08:33 AM
Looks great so far! You did all the art yourself?

Certainly a followup in this thread, to let others know how it went, was a good idea, though I'd suggest making a new thread about development of your game in particular (choose another appropriate board).
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on April 11, 2016, 12:47:55 AM
Thanks!  :) No, I downloaded some tilesets and stitched them together, but it's just placeholder graphics at the moment. I've done a lot of pixel art (and I've made an entire point-n-click adventure game) in the past so I'll most likely make custom tiles. Might even bump it up to 32x32 also. One of the next steps will be having proper tiles for the walls, so there's corner/edge tiles for all the rooms. Maybe other little elements like pillars/altars, etc. I have to think about the game though, I'd like to depart from the standard high fantasy setting.

I'm not sure how much interest there is in Libtcod at the moment, but perhaps someone would find my code useful. It would be a great starting point for a beginner who wants to build a rogue-style game but they want to take advantage of BearLib's graphical abilities.

I'll have a look and make a new thread. :)

(https://github.com/tomzimmer/rogue_project/blob/master/tiles/tiles.png?raw=true)
Title: Re: Prettier Graphics with Libtcod?
Post by: Cfyz on April 11, 2016, 12:14:13 PM
Since we're talking about prettier graphics, I have to note that with BearLibTerminal it is easy to use square tiles alongside 'normal' rectangular fonts:
1. Choose a font so that tile size is a multiple of character size, e. g. default font is 8x16 and tiles are 16x16.
2. Load tiles to separate indices with arbitrary offset so they will not overlap with font characters, e. g. terminal.set("300: tilesets/tiles.png, size=16x16")
3. Use tile indices with the offset you just specified, e. g. healing potion is now 300+24 instead of 24.
4. Voila.

Note: tileset offsets/indices are arbitrary but they and characters are in the same code space (Unicode). As long as your game text is in ASCII, any number above 128 will do (because you will not use them for text anyway), but if you plan to use various characters like β or Ω, it is better to place graphical tiles in the special Unicode Private Use Area: 0xE000-0xF8FF.
Title: Re: Prettier Graphics with Libtcod?
Post by: toggle on April 11, 2016, 07:21:29 PM
e. g. terminal.set("300: tilesets/tiles.png, size=16x16")
Wow, thanks Cfyz, that's really handy info, I'll definitely use that.
I've been trying to load different-sized tiles from multiple files but I thought it was impossible. Each time I used terminal.set() it would reset everything. I didn't know it was possible to use that extra term.

One thing I'd like to do also is load in a splash screen/image for the menu background. I managed to get it working (by loading in a giant tile) but I couldn't get it working in conjunction with my normal tiles. I guess this technique would work, unless you have a different suggestion? Libtcod has a special feature for this kind of thing. Sometimes it's really tough to figure out how to get Bearlib working, especially in Python.

though I'd suggest making a new thread about development of your game in particular (choose another appropriate board).
Do you know, should I post in 'Early Dev' or 'The Incubator' ?
Title: Re: Prettier Graphics with Libtcod?
Post by: Quendus on April 11, 2016, 10:32:44 PM
Definitely in Early Dev. The Incubator was intended for mutual support and feedback between developers working on mature projects. Now it just attracts a post every few months that would have been better placed somewhere like Announcements or Early Dev.

e. g. terminal.set("300: tilesets/tiles.png, size=16x16")
Wow, thanks Cfyz, that's really handy info, I'll definitely use that.
I've been trying to load different-sized tiles from multiple files but I thought it was impossible. Each time I used terminal.set() it would reset everything. I didn't know it was possible to use that extra term.

One thing I'd like to do also is load in a splash screen/image for the menu background. I managed to get it working (by loading in a giant tile) but I couldn't get it working in conjunction with my normal tiles. I guess this technique would work, unless you have a different suggestion? Libtcod has a special feature for this kind of thing. Sometimes it's really tough to figure out how to get Bearlib working, especially in Python.
Yes, loading different tilesets at different codepoints would let you display a splash screen or background without interfering with the normal tiles, using e.g. terminal.set("F000: tilesets/splash.png, size=640x480")