Jump to content
  • Advertisement
Sign in to follow this  
Sir Sapo

OpenGL Console Window and OpenGL

This topic is 4877 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 anyway to have a console popup, let you input variables and stuff in it, and then when you are done with it have the program resume using OpenGL?

Share this post


Link to post
Share on other sites
Advertisement
Hmm, yes, as phantom said, you would have to do it yourself, OpenGL is kindof a rendering API :D

Anyways, assuming you meant a standard Windows(tm) console that was fairly easy, I added one to my own opengl window class, I just roughly chopped out the implementation of the console window here if it would give you any pointers to what to do: (Window:: is my own homebrewed opengl enabled window class)


void Window::RedirectIOToConsole(){

CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;

// allocate a console for this app
AllocConsole();

// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),
&coninfo);
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),
coninfo.dwSize);

// redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );

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

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

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




(I might have ripped this of someone else and modified it to my own needs in the first place btw)

usefull includes

#include <windows.h>

#include <stdio.h>
#include <fcntl.h>
#include <io.h>

#include <iostream>
#include <fstream>




Don't know if some definitions are missing, but I am short on time now. Provided as is .

Edit: one of meny spelling errors corrected.

Share this post


Link to post
Share on other sites
wow I had no idea it was so easy to get a console window to open up. Thanks for that code, for my last project I wound up trying to code my own console, but that would have made things sooooo much easier.

Share this post


Link to post
Share on other sites
Quote:
Original post by todderod
*** Source Snippet Removed ***

(I might have ripped this of someone else and modified it to my own needs in the first place btw)



Heh, yes, I thought that code looked familiar. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!