How to get user writing input string in openGl?

Started by
15 comments, last by Mathimetric 10 years, 3 months ago

I need the way for allow users input text by writing (typing) , while users input text they see what's they input when user press enter jump for next line and when user end press on button to finish ?

note: I need user text input without opening a new window etc.

Advertisement

OpenGL is a graphics library only, and doesn't have (and shouldn't have) any GUI features built-in.

If you're using C++, consider using Qt for GUI-based applications.

Here's a screenshot of me using Qt to build an editor alongside my game: (still a work in progress)

cisd.png

Qt is for heavily GUI-driven applications, and takes over a great deal of your application. If text entry is really all you want, then Qt is way overkill, and you'd want something smaller like a OpenGL-based in-game GUI library - I don't have personal experience with any of those, but a half-dozen or so of them exist.

If you're looking for something with a lot smaller footprint than the Qt suggestion, you can use SDL. You can probably learn all the essentials of SDL in less than a day, and there are plenty of tutorials out there. Text input in SDL is just an event of type SDL_TEXTINPUT. If you need the key's state (down or up), you can track event types SDL_KEYDOWN and SDL_KEYUP instead.

SDL doesn't have any GUI capabilities, just events.


SDL doesn't have any GUI capabilities, just events.

SDL + SDL_ttf pretty much fits the bill, no?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

SDL doesn't have any GUI capabilities, just events.

SDL + SDL_ttf pretty much fits the bill, no?

Perhaps! I was reading the OP's request as a LineEdit or TextEdit-style widget (but just not in a Win32-style pop-up modal dialog box).

@moudy: Are you looking for something like this:

q676.png

Or similar to this:

qeat.png

Or something else entirely?

@Servant of the Lord

I am looking for something like the first example .

Then you'll probably need to code most of it yourself to fine-tune it to your desires, using OpenGL-based text-renderers.

If your game is 2D, I'd suggest SFML 2, but SDL and SDL_ttf (like richardurich mentioned) are excellent as well. You could even use SDL_ttf or SFML to generate OpenGL textures for you that contain text, but the logical interactions and the correct layout will need to be written by your code.

Alternatively, you could try a OpenGL-based GUI library (which one, I wouldn't know).

@

Servant of the Lord

pls , can u give a source code for the first example or anything useful or tutorial or website .

SotL already said what he is using for his example screenshot: Qt. If you decide to go down this route (which may not be wise for all types of games) and you aren't familiar with Qt yet then you will have to spend at least a few weeks learning a bit more about Qt. It's a quite massive framework and there is little room for cherry-picking a few pieces out quickly.

There are plenty of places to learn about Qt, including the site SotL (and now myself) linked.

This topic is closed to new replies.

Advertisement