Jump to content
  • Advertisement


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


OpenGL console app and opengl app running at same time

This topic is 5519 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
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 {
DebugView(std::string title);
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);
this->exists = ::AllocConsole() != 0;
if(! this->exists) {
MessageBox(0, TEXT("Couldn''t create debug console!"), TEXT("Error"), MB_ICONERROR | MB_OK);

//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

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

if(this->exists) {
this->exists = false;


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!