OpenGL Output Class

About the Class

The class makes it possible to create a font simply and to display text all kinds 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 and choose for the files of the class not to use precompiled headers). The functions of the class are based on the ones that appear on the site http://nehe.gamedev.net, and it should get the credit it deserves.

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; that works exactly the way printf (of the standard IO of C Language) does. You can use SetFont more than once to change the font's properties.

The Functions of the Class

SetFont

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

Parameters:

  • hDC—Handle of GDI Device Contex.
  • fName—Font name as defined in Windows; for example, "Arial" or "Times New Roman."
  • fDepth—How "deep" the font goes, meaning how long it gets on the Z axis.
  • fWeight—Weight of the font. There is a list of values that will fit in MSDN (CreateFont function).
  • fItalic—For italic font, TRUE; otherwise, FALSE.
  • fUnderline—For underlined font, TRUE; otherwise, FALSE.
  • fStrilkeOut—For strikeout font, TRUE; otherwise, FALSE.
  • fCharSet—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 anyway, so if you don't use another language, just leave it or enter ANSI_CHARSET, which is the default.

Print

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

Parameters:

A string and afterwards the variables that you want to print, in the same template that 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.

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 or NULL was entered for the fName parameter of SetFont).

Example

#include "CGLOutput.h"
...
char myname[];
CGLOutput OC;    // Output Class variable
...
OC.SetFont(hDC, "Comic Sans MS");    // Set font definitions
OC.Print("Hello %s", myname);        // Print "hello" + a string""
...

Other Remarks

This article, and another one that I wrote about an input class and a class for both Input & Output in OpenGL, can all be found in NeHe's Productions Site at http://nehe.gamedev.net.

There is another example in the attached file.



Downloads

Comments

  • plot a point using 3d co-ordinate system

    Posted by lakme2india.com on 03/05/2005 06:15am

    i want to plot a point using the 3d co-ordinate system. can u please tell me how to do that

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds