PDA

View Full Version : how keep rendering whilst interacting with console



ooIsNotMyThing
01-03-2010, 11:23 AM
Hi, Im using C++ and glfw on windows and I need to know if it is possible to keep rendering whilst typing in the console.

Currently, animation stops until the console gives "focus" back to the rendering.

Any help is appreciated.

Brolingstanz
01-03-2010, 05:19 PM
Well, this shouldn’t be a problem for a typical animation loop setup, where you basically spin in a message loop, pumping (input) messages to the window system and driving your animation with the idle time in between messages. Examples for the various platforms abound here and abroad if that sounds like it’s up your alley (or try something platform neutral like GLUT).

ooIsNotMyThing
01-05-2010, 05:46 AM
ill have to look for some examples.
Does this apply to
cin >> size; aswell?

ZbuffeR
01-05-2010, 05:55 AM
Ah, you mean the command line console provided by OS, not your ingame console right ?
Then you will have to do cin/scanf/whatever in a separate thread from rendering.

Dark Photon
01-05-2010, 05:57 AM
ill have to look for some examples.
Does this apply to
cin >> size; aswell?
No, anytime you interact with the console reading input in a blocking fashion like this, you can hang your thread waiting on I/O.

You're probably going to find it simplest to just put your console interaction in a background thread. That is, talk to OpenGL with one thread and talk to the console in another.

Also, you can do select()-style non-blocking user interaction which would allow you to stuff all your GL/GUI drawing and user console interaction in a single thread (on Linux/UNIX at least). I can't speak to Windows though. And this is more than you probably want to bite off right now unless a Windows dev can point you to some code.

ZbuffeR
01-05-2010, 06:01 AM
And GLFW does provide simple portable threads too.

ooIsNotMyThing
01-05-2010, 07:07 AM
im not familiar with threads in C or C++, so would you advise placing I/O in a seperate thread or creating an ingame console that feeds commands?

If threads, could you point me in the right direction?

ZbuffeR
01-05-2010, 07:39 AM
The excellent GLFW doc details how to use threads and mutexes :
http://glfw.sourceforge.net/GLFWUsersGuide26.pdf

Create a thread that reads from console, and when new results are read it can update main program variables.

Doing a good ingame console is not that easy, it depends on your preferences. Someone had a nice library for quake-like ingame console, but I lost the link...