Jump to content
  • Advertisement
Sign in to follow this  
ukdeveloper

SDL text input

This topic is 4879 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

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

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!