SDL text input

Started by
2 comments, last by Drew_Benton 18 years, 10 months ago
Hello, I was just wondering how, in SDL, would you be able to type directly onto a surface? Let's say I had a game window called SDL_Surface *GameWindow, and the user had to enter their name for a Highscores table, how would I do it? I know how to draw/blit text to the screen, I just need to know how do I pass it in for drawing? I'd also like it to be like you see in arcade games, with the blinking underscore character and each letter appearing as you type it. But I want to be able to actually type to the screen first of all. Any thoughts?
Advertisement
Look into SDL_ttf. Basically input and graphics are separate so you'll have to piece together the components, tracking input, aggregating it into a string that you add to with each keypress, passing that string to a font rendering function, and putting the results of that onto the screen.
I believe there's a link in Drew Benton's signature that has code to do exactly this. I read over it once. ;)

click!
----------------------------------------------------------No matter how eloquently you state your argument, the fact remains that the toilet seat is a bistable device. Therefore it's natural position is no more down than it is up.[SDL Smooth Tile Scrolling]
Quote:Original post by wasted_druid
I believe there's a link in Drew Benton's signature that has code to do exactly this. I read over it once. ;)


[smile] Thanks Wasted_druid! I am still working on commenting those projects in my sig and updating them, but I don't have my dev computer, so I've been delayed from doing so for another week. If you want to have a blinking cursor you should be able to simply have a time toggle that sets 'buffer[index]' to let's say "|" every 5 seconds, then toggle it so it does not. Or, if you wanted to seperate it from the text input, you can just make another font and do virtual tracking so the text entered is sent to a second font, but none of it is displayed, just the cursor. Since this code doesn't work so well with VS8 I will do some reworks on it in Dev-CPP and try to update soon.

I would however, suggest taking Kylotan's suggestion to use SDL_ttf. That font code I inluded was from Cone3D and SDL_ttf is far superior [wink] You should be able to plug in SDL_ttf in and use that rather than the font code. Good luck!

This topic is closed to new replies.

Advertisement