Game Input Class

Version 1.01
Made For The Windows Operating System

1. About The Class

This class makes it possible to input strings, chars and integers in OpenGL while working with the Windows API. You can use it in MFC too.

2. How To Use This Class

In order to use this class, you have to have access to it's GetInput function from the Window Procedure (WndProc usually). Therefore, I suggest you define a global variable of the class, or make a GetInput function in the class that contains it that simply calls GetInput from this class. In the WndProc's WM_EVENT call the GetInput function with the WPARAM variable.

An example:

switch (uMsg)					// type of uMsg is UINT
		InputClass.GetInput(wParam);	// type of InputClass – CGLInput
						// type of wParam - WPARAM

The end of an input is when user presses the ENTER key (VK_RETURN constant). Because a lot of people use enter in their programs, I suggest you call the FixEnterCollide function every frame.

After you've done that, you can start using the class for input. The class ostensibly works in the background (because it's based on Windows Events), so you can draw or do other things while the user inputs.

The class works by "processes" – it has a process for each input type – integer, string or char. In order to get input, you begin a process (using the BeginProcess function. This function gets the kind of process you want to begin). Now any keys that are pressed will be handled by the input class up until the user presses the ENTER key.

You can use the IsOver function to determine whether the process is over or not. If it is, use the GetInt, GetStr or GetChar function to get the input. Once you use one of these functions, the process is automatically cancelled. In your rendering loop use the DrawInput function so the user can see the input.

Many people use the ENTER key for various things. If you do as well, make sure you call the FixEnterCollide function in the main loop of your program. It will fix the "collides" between the input class and use of Enter in the program itself.

3. The Function Table For This Class

Function Name How To Use It
BeginProcess(GLuint) Begins an input process. The only parameter is what kind of a process you want to begin. Enter one of the process variables (see the class Process Constants Table)
GetInput(WPARAM) Call this function with from the WndProc function as explained above.
GetStr(char*) Gets a pointer to char (or name of a char array) and makes it a pointer to the string. It must have enough room for the string. Use GetStrLen to verify it. If the process isn't over, it will return false, else true.
GetInt(int&) Parameter is an int variable (by reference). If the process is over, it will return true and will substitute the data user has entered. If the process isn't over, it returns false.
GetInt( ) Returns the integer that the user entered, if process is over.
GetChar(char&) Puts in the char variable the char that the user has entered and returns true if process is over. Otherwise it returns false.
GetChar( ) Returns the char that that the user entered if process is over.
GetProcess( ) Returns the value of the Process Constant of the current process. Returns PR_NO_PROCESS if there is no process.
IsOver( ) Returns true if a process is over, otherwise false.
DrawInput( GLYPHMETRICSFLOAT* ,GLuint) The function draws the input of the user. 1st Parameter is a pointer to an array that contains the information about the font. 2nd parameter is the base display list for the font. If current process is PR_NO_PROCESS, then nothing will be drawn (no output).

4. Process Constants Table

Constant's Name Value Meaning
PR_NO_PROCESS 0 No process. If this is the parameter of BeginProcess function, the current process is stopped.
PR_GETCHAR 1 Get char process
PR_GETINTEGER / PR_GETINT 2 Get integer process
PR_GETSTRING / PR_GETSTR 3 Get string process

There is obviously no need knowing the values of the constants.

5. Example

#include "CGLInput.h"

CGLInput IC1;					// Define A Global Input Class Variable
				UINT uMsg,
				WPARAM wParam,
				LPARAM lParam )
	switch (uMsg)
		case WM_KEYDOWN:
	IC1.BeginProcess(PR_GETINT);		// Begin a Get Int Process
void DrawEverything()				// Constantly Draws The Scene
	int input;
	IC1.DrawInput();			// Draw The Input. If Process Is
						// PR_NO_PROCESS, Nothing
						// Is Drawn.
	if(IC1.IsOver())			// Is The Process Over?
		IC1.GetInt(input);		// If So, Put The Input In A Variable
CGLOutput – OpenGL Output Class


By: Aviram Cohen


Version 1.00
Made For The Windows Operating System

1. About The Class

This class makes it possible to create a font and display all kinds of text in OpenGL. Unlike the class CGLInput, this class can work great under MFC (but if you use it, you have to go to the settings of the project in VC++ 6.0 and choose not to use precompiled headers for the files of this class). The functions of the class are based on the ones that appear on this site (

2. How To Use The Class

First of all, you have to define (of course…) a variable. Then use the SetFont function to set the font's definitions. Once you have called the SetFont function, you can use the Print function exactly the same way you would use printf (standard I/O in the C Language). You can use SetFont more than once in order to change the font's properties.

3. The Functions Of This Class


void SetFont(	HDC hDC,
		char* fName = NULL,
		GLfloat fDepth = 0.5f,
		int fWeight = FW_BOLD,
		DWORD fItalic = FALSE,
		DWORD fUnderline = FALSE,
		DWORD fStrikeOut = FALSE,


Handle of GDI Device Context

Font name as defined in Windows, for example "Arial" or "Times New Roman".

How "deep" the font goes, meaning how long it gets on the Z Axis.

Weight of the font. There is a list of values that will fit.

For italic font TRUE, otherwise FALSE.

For underlined font TRUE, otherwise FALSE.

For strikeout font TRUE, otherwise FALSE.

The character set. For a specific language, it is the name of language in capital letters, then CHARSET. For example, GREEK_CHARSET or HEBREW_CHARSET. It can write in english, so if you don't use another language, just leave it or enter ANSI_CHARSET, which is default.


bool Print(const char *fmt, ...)


A string and afterwards the variables that you want to print, in the same template as the printf function uses.

Return Values:

If the font isn't set or if the entered string is NULL, the function will return true. Otherwise it will return false.

4. Class Constants

The class has only one constant - GLO_DEFAULT_FONT[ ] of char. It contains the name of the default font (that is used in case no font name is given or NULL was entered for the fName parameter of SetFont.

5. Font Weights

This table of font weights appears in MSDN:

Value Weight

6. Example

#include "CGLOutput.h"
char myname[];
CGLOutput OC;					// Output Class Variable

OC.SetFont(hDC, "Comic Sans MS");		// Set The Font
OC.Print("Hello %s", myname);			// Print "hello" + a string.
CGLIO – OpenGL Input/Output Class


By: Aviram Cohen


1. About The Class

The class brings the Input and Output classes together.

2. How To Use This Class

All you need to know is how to use the overridden function DrawInput. Simply use the two class functions for everything within this class except the DrawInput function.

Use the SetFont function to set the font's definitions, and then call the DrawInput function with no parameters. The input will be drawn automatically.

Download the code for this article: OpenGL IO