Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gresc

OpenGL console app and opengl app running at same time

This topic is 5436 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

is there a way to have a console application (like the dos prompt u start out when ur learning c++) and a opengl running at the same time on one program and letting thme interact with each other... if any finds out how to do this could they plz tell me

Share this post


Link to post
Share on other sites
Advertisement
yes, you can either compile it as a console app, and (after including the windows headers) create a window to use with OGL... or you can compile it as a windows app, and get a console with (i think) AllocConsole.

Share this post


Link to post
Share on other sites
For MSVC++ 6.0.

It''s mostly not my code, but someone else posted it somewhere on these forums. I''ve just forgotten where.


In DebugView.h

#pragma once

#include <string>

/// Creates a debug console that lasts the duration of the DebugView object
/// lifetime, and syncs stdin/stdout/stderr and the C++ streams to print there.

class DebugView {
public:
DebugView(std::string title);
~DebugView();
private:
static bool exists;
};

In DebugView.cpp

// DebugConsole.cpp

#include "DebugView.h"
#include <iostream>
#include <fcntl.h>
#include <io.h>
#include <windows.h>

using namespace std;

typedef long intptr_t;

bool DebugView::exists = false;

DebugView::DebugView(string title)
{
if (this->exists) {
MessageBox(0, TEXT("There is already a debug console!"), TEXT("Error"), MB_ICONERROR | MB_OK);
return;
}
this->exists = ::AllocConsole() != 0;
if(! this->exists) {
MessageBox(0, TEXT("Couldn''t create debug console!"), TEXT("Error"), MB_ICONERROR | MB_OK);
return;
}

//sync stdin, stdout, stderr fds up with the new console
//original source: http://www.halcyon.com/ast/dload/guicon.htm
//changes: removed all warnings by changing types and casting
// set the screen buffer to be big enough to let us scroll text

CONSOLE_SCREEN_BUFFER_INFO coninfo;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = 500;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);

// redirect unbuffered STDOUT to the console
intptr_t pStdHandle = reinterpret_cast(GetStdHandle(STD_OUTPUT_HANDLE));
int hConHandle = _open_osfhandle(pStdHandle, _O_TEXT);
FILE* pFile = _fdopen( hConHandle, "w" );
*stdout = *pFile;
setvbuf( stdout, NULL, _IONBF, 0 );

// redirect unbuffered STDIN to the console
pStdHandle = reinterpret_cast(GetStdHandle(STD_INPUT_HANDLE));
hConHandle = _open_osfhandle(pStdHandle, _O_TEXT);
pFile = _fdopen( hConHandle, "r" );
*stdin = *pFile;
setvbuf( stdin, NULL, _IONBF, 0 );

// redirect unbuffered STDERR to the console
pStdHandle = reinterpret_cast(GetStdHandle(STD_ERROR_HANDLE));
hConHandle = _open_osfhandle(pStdHandle, _O_TEXT);
pFile = _fdopen( hConHandle, "w" );
*stderr = *pFile;
setvbuf( stderr, NULL, _IONBF, 0 );

// make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
// point to console as well
ios::sync_with_stdio();
SetConsoleTitle(title.c_str());
}

DebugView::~DebugView()
{
if(this->exists) {
FreeConsole();
this->exists = false;
}
}

//#endif



To use, just include DebugView.h and create an instance of it:

DebugView dbc("debug");

The window should be destroyed when the object goes out of scope. You can''t make more the one, so the code will give you a runtime error if you try.




Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!