Code:
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
#include "glfont2.h"
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
glfont::GLFont gl_font;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
//Initialize the viewport
glViewport(0, 0, width, height);
//Initialize OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
//Initialize OpenGL
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Try and load our font
if (!gl_font.Create("courier.glf", 1))
return FALSE;
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
float top_color[3] = {1.0F, 1.0F, 1.0F};
float bottom_color[3] = {0.0F, 0.0F, 1.0F};
//Clear back buffer
glClear(GL_COLOR_BUFFER_BIT);
//Initialize modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Draw some strings
glColor3f(0.0F, 0.0F, 1.0F);
gl_font.Begin();
gl_font.DrawString("Hello World!", 2.0F, 0.0F, 480.0F);
gl_font.DrawString(L"Hello World!", 2.0F, 0.0F,
400.0F, top_color, bottom_color);
gl_font.DrawString(std::string("Hello World!"), 0.0F, 320.0F);
gl_font.DrawString(std::wstring(L"Hello World!"), 0.0F, 280.F,
top_color, bottom_color);
glTranslatef(0.0F, 200.F, 0.0F);
glRotatef(15.0F, 0.0F, 0.0F, 1.0F);
gl_font.DrawString("Hello World!", 2.0F, 0.0F, 0.F,
top_color, bottom_color);
return TRUE; // Everything Went OK
}
I uploaded a .zip containing the entire compilable project, if you want to poke around at it. It can be found here: