Jump to content
  • Advertisement
Sign in to follow this  
Jovan

OpenGL creating a fully-functional console?

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

This has been puzzling me for a few days: I started to work on a console for a small game I am making, and it is almost finished, except for one last main ingredient: User input. I am using FreeType 2 Font library to output opengl text, and I am trying to figure out how get the entire "typing effect" going on, and of course to translate text upward by lets say.. 2-3 units. I am okay with translating it, but I am not sure how to get the user to input her-his text. Here's a few things I thought about, yet I am unsure if they will work ( I had some troubles converting char to const char.. gave me errors ) Every time the user opens up the console (tilde), a function is passed on that creates a 'new' string of text to be typed in, and declared under an array like 'newtext' and for every enter, i+1 (so that no post text is modified). Once the user presses Enter (return), that text is stored in another array called 'oldtext[t]' and every new enter creates +1, so theres space, and every time the user presses enter, oldtext (which i guess can be made by using one freetype function every time?) is translated by 2-3 units upward. Any thoughts, comments, or source-codes would be much helpful :)

Share this post


Link to post
Share on other sites
Advertisement
Ah, I recently wrote a console system for a Final Project I did to complete college, and over christmas I rewrote it. The way I did it before was completely quake style, as i allocated a huge char array of 32kb. and used some variables to calculate a row/character offset into the big array for the 'oldtext' as you have it. and the 'newtext' was an array[32][150] so i could have a command history to scroll through.

The new way I'm doing it is using std::sting and std::vector. The way I handle input is I have a function that accepts a interget as what key was pressed and I send that through a switch to see what do to with the key, like open, scroll, backspace, etc and the default state is to add it to the typing line. Here is what i do to add it to my current line


if (m_Open && isprint(c) && m_EditLinePos < (m_LineWidth - 1))
{
m_CLIHistory[m_EditLine].insert(m_EditLinePos, 1, c);
m_EditLinePos++;
m_CLIHistory[m_EditLine].insert(m_EditLinePos, 1, 0);
}




So that will only add the character if it is a printable character and it will fit on the current line. When the user hits 'enter' in my consle I take that index into the m_CLIHistory and use my AddLine() function which adds the passed in text to the 'oldtext'. for printing all my old text i just loop through my array of text each time decrementing my yoffset by a set amount, this being the height of the font I use. Here is a stripped down version of how i do it, and it works just fine. the iter, and end are just std::vector<std::string>::iterator's.

for (; iter != end; iter++, yOffset -=12)
{
// if the text has gone totally off screen stop
if (yOffset < -12)
break;
m_BitmapFont->Print(xPos, yOffset, (*iter).c_str());
}




Hope this helps ya out some.

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!