0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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\$ – Tyyppi_77 Feb 12 '17 at 14:57
  • \$\begingroup\$ Or, would it be sufficient to output data to your Visual Studio console? \$\endgroup\$ – Tyyppi_77 Feb 12 '17 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 Feb 12 '17 at 15:55
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\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 Feb 12 '17 at 16:05
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ LukeG i will try this as soon as i can, thanks a lot, this seems great! \$\endgroup\$ – Emanuele Feb 19 '17 at 17:40
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Oliver Yasuna thanks, i will check out the quake source for more infos \$\endgroup\$ – Emanuele Feb 12 '17 at 14:56
  • \$\begingroup\$ Glad to help. Hope you figure it out! \$\endgroup\$ – Oliver Yasuna Feb 12 '17 at 14:56
  • \$\begingroup\$ You said in a comment above that printf() doesn't work? \$\endgroup\$ – Oliver Yasuna Feb 14 '17 at 7:51
  • \$\begingroup\$ Check out my edit for more information \$\endgroup\$ – Oliver Yasuna Feb 15 '17 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.