Results 1 to 2 of 2

Thread: Input/Output Console for OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    May 2004
    Posts
    13

    Input/Output Console for OpenGL

    I am looking for a sourcecode which can display the buffer of glutKeyboardFunc(keyboard) on the screen.

    Or just a code which displays a variable (text). Optimal would be some kind of console.

    Thanks for help.

  2. #2

    Re: Input/Output Console for OpenGL

    If you are looking for a simple way to debug your code while it is running by displaying text messages within the programs window then this is what I use (this only works with windows and only if you have a handle to the windows device context):

    ////Begin code
    #ifndef __TEXT_H
    #define __TEXT_H

    #include <String>

    class Text
    {
    public:

    void initialize(HDC hDC)
    {
    //Set up a font to use
    HFONT hFont;
    GLYPHMETRICSFLOAT agmf[128];
    LOGFONT logfont;

    logfont.lfHeight = -10;
    logfont.lfWidth = 0;
    logfont.lfEscapement = 0;
    logfont.lfOrientation = 0;
    logfont.lfWeight = FW_BOLD;
    logfont.lfItalic = FALSE;
    logfont.lfUnderline = FALSE;
    logfont.lfStrikeOut = FALSE;
    logfont.lfCharSet = ANSI_CHARSET;
    logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
    logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    logfont.lfQuality = DEFAULT_QUALITY;
    logfont.lfPitchAndFamily= DEFAULT_PITCH;
    strcpy(logfont.lfFaceName,"Arial");
    hFont = CreateFontIndirect(&logfont);

    SelectObject(hDC, hFont);

    nFontBase = glGenLists(12;

    wglUseFontOutlines(hDC, 0, 128, nFontBase ,0.0f, 0.0001f, WGL_FONT_POLYGONS, agmf);

    output = "";
    }

    void drawText()
    {
    glPushMatrix();
    glLoadIdentity();
    glTranslatef(-.77,.56,-1);
    glScaled(.025, .025, .025) ;

    glListBase(nFontBase);
    glCallLists(output.length(),GL_UNSIGNED_BYTE,outpu t.c_str());
    glPopMatrix();
    }

    void setText(string changeTo)
    {
    output = changeTo;
    }

    void addText(char stringToAdd)
    {
    output += stringToAdd;
    }

    void addText(string stringToAdd)
    {
    output += stringToAdd;
    }

    void addText(int stringToAdd)
    {
    char buffer [33];
    itoa (stringToAdd,buffer,10);
    output = output + buffer;
    }

    void addText(float stringToAdd)
    {
    char buffer[33];
    int temp = (int)stringToAdd;
    itoa(temp,buffer,10);
    output = output + buffer;
    }

    string output;
    GLuint nFontBase;

    };

    #endif

    I create a global Text object. I then call the initialize function (this must be done after opengl is set up so that is why I did not put it in the constructor). Then I use the helper functions (addText,setText) to change the message. Then I make sure to call drawText every frame. In the drawText function are some calls to glScale and glTranslate. These you might need to tweek depending on how big you want your text and where you want it positioned. This is a very crude method for displaying text but it serves its purpose. You can add other helper functions to display things like float point integers but I never bothered to. You could also use some operator like << to add successive strings or different data types but I got lazy when I wrote the class. Hope this helps.

    But wait, if you are writing a standard c++ console program then you should already have a console. Why can't you just use cout?

    The code is mine except for the init function and I forget where I got it. Sorry.

Similar Threads

  1. input and output having different dimensions
    By acolubri in forum OpenCL
    Replies: 2
    Last Post: 07-09-2009, 03:42 PM
  2. Displaying 3d images with console output
    By dpanther1017 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-26-2006, 11:15 AM
  3. user input/output
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-18-2005, 09:48 PM
  4. How to create a console window in Win 32 for direct user input?
    By cutting_crew in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-27-2004, 03:58 PM
  5. input / output in opengl application
    By matrixh725 in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 09-30-2003, 07:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean