I really need a console for the game i'm making. I am programming a first person camera right now and i want to see what is going on with the variables (to be more specific i need to know if i'm getting the mouse input as i want or no) and i don't know how to see it. I searched online A LOT and i found tons of scripts with no explanation so i don't know what to do. What i need is the "noob" line of command you get when you don't use WINAPI. The one you have from just writing your code into the dev c++. I know it sounds like i have no idea of what i'm saying but i don't know how to ekplain it better.
-
\$\begingroup\$ So do you need to have the console in-game or would just the default Windows CMD do the job? Do you need input or is output enough? \$\endgroup\$user35344– user353442017-02-12 14:57:41 +00:00Commented Feb 12, 2017 at 14:57
-
\$\begingroup\$ Or, would it be sufficient to output data to your Visual Studio console? \$\endgroup\$user35344– user353442017-02-12 15:02:50 +00:00Commented Feb 12, 2017 at 15:02
-
\$\begingroup\$ Tyyppi_77 no i don't need it in-game, i just need the default windows CMD, can you help me? \$\endgroup\$Emanuele– Emanuele2017-02-12 15:55:05 +00:00Commented Feb 12, 2017 at 15:55
3 Answers
One option would be to just use OutputDebugString which outputs to Visual Studio's Output-window.
If you want a Windows-style CMD instead, this SO-answer seems to create one for you.
-
\$\begingroup\$ I already found that code and it doesn't work! I don't know why but i just can't printf() nothing on the cmd \$\endgroup\$Emanuele– Emanuele2017-02-12 16:05:06 +00:00Commented Feb 12, 2017 at 16:05
I want to provide an alternative way to achieve both a console and a Window to draw your graphics to. Configure your project to be a default console project and create the window manually through the WinAPI. This way you have both a console and a window to draw your graphics to. If you later decide you do not need the console anymore you can do
ShowWindow(GetConsoleWindow(), SW_HIDE);
at the beginning of your program and the console wont show up anymore.
There are many Window libraries for C++ on Windows, but it is also easy to roll your own Window class, which supports all the features you need.
-
\$\begingroup\$ LukeG i will try this as soon as i can, thanks a lot, this seems great! \$\endgroup\$Emanuele– Emanuele2017-02-19 17:40:30 +00:00Commented Feb 19, 2017 at 17:40
There's no easy way to do this. You could have a class like...
class Console
{
private:
/*
* Stores each line inputted to render later.
*/
std::list<std::string> lines;
public:
/*
* Check the syntax of the inputted line, execute if valid, and add it to the list of lines.
* Return true if the syntax was valid.
*/
bool processCmd(const std::string& line);
}
But that example is very elementary. Check out the Quake source, that may be a good learning point.
On the rendering end, you need to temporarily render in 2d, so you can draw the console, then switch back to 3d.
EDIT 1:
For parsing you could use boost::program_options. There are some other libraries too, for example (quick Googpe search):
http://optionparser.sourceforge.net/
https://github.com/FlorianRappl/CmdParser
https://github.com/jarro2783/cxxopts
These are designed to parse the CLI, but can be used for your task.
-
\$\begingroup\$ Oliver Yasuna thanks, i will check out the quake source for more infos \$\endgroup\$Emanuele– Emanuele2017-02-12 14:56:07 +00:00Commented Feb 12, 2017 at 14:56
-
\$\begingroup\$ Glad to help. Hope you figure it out! \$\endgroup\$Oliver Yasuna– Oliver Yasuna2017-02-12 14:56:47 +00:00Commented Feb 12, 2017 at 14:56
-
\$\begingroup\$ You said in a comment above that
printf()doesn't work? \$\endgroup\$Oliver Yasuna– Oliver Yasuna2017-02-14 07:51:15 +00:00Commented Feb 14, 2017 at 7:51 -
\$\begingroup\$ Check out my edit for more information \$\endgroup\$Oliver Yasuna– Oliver Yasuna2017-02-15 22:48:04 +00:00Commented Feb 15, 2017 at 22:48