Jump to content

  • Log In with Google      Sign In   
  • Create Account

WIn32 OpenGL get commands from console


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 10 February 2013 - 08:43 AM

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?

 



Sponsor:

#2 mynameisnafe   Members   -  Reputation: 252

Like
0Likes
Like

Posted 10 February 2013 - 09:10 AM

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 ?

 


 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS