Sign in to follow this  

WIn32 OpenGL get commands from console

This topic is 1801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys.

 

So here is the thing. I have a win32 / opengl application. I've created a class* that opens a console with AllocConsole and ties the stdin, stderr and stdout of the application to it.

 

So this is awesome, 'cos I can go (from anywhere in the program)

 

#include <iostream>
...
std::cout << "\nSomething broke!"

 

Anyways, the point is I now have a console window that I can potentially get custom commands out of, such as "quit" for example.

 

I'm dubious about hacking something together before I've thought aboutt his so that's why I'm here.

 

If, on every frame (opengl) I go..

bool Frame() {
  std::string _command;
  std::cin >> command;
  if( command == "quit")
      return false;
  else
      return gfx->frame(); // do rendering
}

 

Then I'm never going to get to type "quit" because the program will always be recreating the string every seconds-per-frame.

 

So how do I solve that? I need some way of like holding a buffer of input characters and send/emptying it on  a newline / null character? then have a vector of these ? How do I test it?

How I turn AllocConsole() and freopen("CONIN$", "r", stdin) into an interactive console?

 

Share this post


Link to post
Share on other sites

Okay this just changed a whole bunch.. I need to get this on a thread? cin just waits for me to type and as such it frames only when I hit enter.. All my graphics and program loop are held up by cin lmao!

 

 

void WinConsole::Frame()
{
    std::string key_buf;
    
    std::cin >> key_buf;

    if( key_buf == "\n" )
        currentCommand = buffer;
    else {
        if( key_buf != "" )
            buffer.append( key_buf );
    }
}
 

 

 

Also.. when I type in quit and press enter, it does nothing..

I added two lines to this function concerning the m_Console

 

 

bool WinApp::Frame()
{
    /*
        Bail or fail?
    */

    if( ! m_Input->IsKeyDown( VK_ESCAPE )  )
    {
        m_Console->Frame();

        if( m_Console->GetCommand().c_str() == "quit" ) return false;
        if( ! m_GFX->Frame( m_Input ) )                    return false;
    }
    return true;
}
 

 

  So umm yeah.. do I need to like spark a thread and do std::cin on it? Surely that's too funny to be true ?

 


 

Share this post


Link to post
Share on other sites

This topic is 1801 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this