SFML community forums
Help => General => Topic started by: mickes27 on June 10, 2017, 11:39:16 pm
-
Hello,
I just started to learn SFML and have to do a project for my university. The task is to work with console and SFML window at the same time, using object orientated C++. For example I want to have menu in my console:
1. Draw circle
2. Draw rectangle
...
And when I type 1 in console, the SFML window updates and show circle. I don't know how to achieve that, because in every course of SFML I saw while loop for displaying window. It prevents from using console, unless I close the window. I need them both opened. I have two classes:
Scheduler -> while loop for taking numbers from console
SFMLWind -> for displaying the primitive in window
But I totaly don't know how to connect them to work simultanously. Can you show me the way? What I need to learn?
EDIT:
I've heard about threds - do I need them here?
-
The problem I can see here is that if you use the console's "cin"-type input, you block the thread from being able to process the window's events. Yes, using a separate thread could fix this but multiple threads are quite convoluted.
I would suggest, instead, to use the window's events to capture the keypresses and process them yourself. You can still output to the console.
You could capture real-time key presses to output to the console instead of using the SFML window's events.
Another option would be to create two windows. One for the graphics and one for the "console". The console window could be another SFML window but look and act similarly to a console window whilst also allowing access to its events.
If you want to be able to show a console in an SFML window, you could consider Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki)'s Console Screen.
Otherwise, you may have to use multiple threads. If you haven't used threads before, this will take a lot of work and time.
http://www.cplusplus.com/reference/thread/thread/
-
The problem is that it has to be "system console" as itself, not other windows which looks like that. I have to have the general program in console and the window has to be only for graphic display, so I think I can't use SFML window as main loop of my program. I think I will use threads then. Thanks for replay
PS. I am usind PDCurse for console, not cout/cin
-
Use kbhit() and getch() functions from PDCurses, you won't have to wait for input from console, this way you can simply check if there's any.
-
As long as PDCurse doesn't block the main thread, you can still process the SFML window and therefore not need multiple threads.
p.s. Looks like korczurekk beat me to that...
-
So using getch and kbhit I would be able to write in console, then work on this data and send them to window display? Can you give me small example?