Okay, with the font header that I have I can draw my text on a gluPerspective Veiwing area. However, when I move to a glOrtho moving area I cannot display fonts. I can not tell where I am messing up. Here is my code excluding the other headers. If you can help me it would be great
#define WIN32_LEAN_AND_MEAN // trim the excess fat from Windows
///// includes
#include <windows.h> // standard Windows app include
#include <gl/gl.h> // standard OpenGL include
#include <gl/glu.h> // OpenGL utilities
#include <gl/glaux.h> // OpenGL auxiliary functions
#include <stdio.h>
#include <stdlib.h>
#include “SetupPixelFormat.h”
#include “SetupLights.h”
#include “FontSetup.h”
////// Global Variables
bool keyPressed[256]; // holds true for keys that are pressed
/////// the camera variables
float cameraX, cameraY, cameraZ; // the camera’s location
float lookX, lookY, lookZ; // the camera’s target
float upX, upY, upZ;
// this is for the font base
unsigned int listBase;
//HDC g_hDC;
//********************************************
// displayText()
// This function Displays Text to the screen
//********************************************
void displayText(char *str)
{
glPushMatrix();
glLoadIdentity();
//glRasterPos2f(-0.35, 0.0);
glTranslated(10.0, 10.0, 0.0);
glColor3f(1.0 , 1.0, 1.0);
PrintString(listBase, str);
glPopMatrix();
}
//********************************************
// initCamera()
// This function sets the initial setting for the camera
//********************************************
void initCamera()
{
cameraX = 0.0; // cameraX,Y,Z -> variables for the location of the
cameraY = 0.0; // of the camera
cameraZ = 12.0;
lookX = 0.0; // lookX,Y,Z -> variables for where the camera
lookY = 0.0; // is looking at
lookZ = -5.0;
upX = 0.0; // upX,Y,Z -> variables to specify what direction
upY = 1.0; // is up
upZ = 0.0;
}
//**********************************************
// Initialize()
// Function that sets and calls all the initial
// functions and values to start the program
//**********************************************
void Initialize()
{
// clear color to black
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// use smooth shading
glShadeModel(GL_SMOOTH);
// setup the camera
initCamera();
listBase = CreateBitmapFont("Comic Sans MS", 10);
}
// tells the program in what order to draw stuff
void Draw(void)
{
// reset modelview matrix
//glLoadIdentity();
// move the camera to where it needs to be
//glTranslatef(0.0, 0.0, -1.0);
// Setup the camera and place it in the scene
//gluLookAt(cameraX, cameraY, cameraZ, lookX, lookY, lookZ, upX, upY, upZ);
displayText("Displaying Text!");
}
// Setup the ViewPorts
void SetupViewPorts(HWND hwnd)
{
RECT rect; // Holds Coordinates Of A Rectangle
GetClientRect(hwnd, &rect); // Get Window Dimensions
int width=rect.right-rect.left; // Calculate The Width (Right Side-Left Side)
int height=rect.bottom-rect.top; // Calculate The Height (Bottom-Top)
// take the first half of the screen
// but for now fill up the window
/*
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); // set projection matrix
glLoadIdentity(); // reset projection matrix
// calculate aspect ratio of window
gluPerspective(45.0f, (GLfloat)(width)/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW); // set modelview matrix
glLoadIdentity(); // reset modelview matrix
Draw();
/*
// Set The Viewport To The Top Right. It Will Take Up Half The Screen Width And Height
glViewport (width/2, height/2, width/2, height/2);
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity (); // Reset The Projection Matrix
// Set Up Perspective Mode To Fit 1/4 The Screen (Size Of A Viewport)
gluPerspective( 45.0, (GLfloat)(width)/(GLfloat)(height), 0.1f, 500.0 );
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity ();
Draw();
*/
// for right now though, just set the ortho to the entire window
// Set The Viewport To The Bottom Right. It Will Take Up Half The Screen Width And Height
//glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION); // Select The Projection Matrix
glPushMatrix();
glLoadIdentity (); // Reset The Projection Matrix
// Set Up Ortho Mode To Fit 1/4 The Screen (Size Of A Viewport)
glOrtho(0, width, 0, height, -1.0, 1.0);
glMatrixMode (GL_MODELVIEW); // Select The Modelview Matrix
//SetupLights();
// draw a 2d polygon
glDisable(GL_TEXTURE_2D);
/*
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(0, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(width, 0);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(width, height);
glColor3f(1.0, 0.0, 0.0);
glVertex2i(0, height);
glEnd();
*/
Draw();
glEnable(GL_TEXTURE_2D);
glPopMatrix();
}
// function to render the current scene
void Render(HWND hwnd)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SetupViewPorts(hwnd);
// do rendering here
// clear screen and depth buffer
SwapBuffers(g_HDC); // bring back buffer to foreground
glFlush();
}
// the windows Procedure event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC; // rendering context
static HDC hDC; // device context
switch(message)
{
case WM_CREATE: // window is being created
hDC = GetDC(hwnd); // get current window's device context
g_HDC = hDC;
SetupPixelFormat(hDC); // call your pixel format setup function
// create rendering context and make it current
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
return 0;
break;
case WM_DESTROY: // window is closing
// deselect rendering context and delete it
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
// send WM_DESTROY to message queue
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
SetupViewPorts(hwnd); // reset modelview matrix
return 0;
break;
case WM_KEYDOWN:
SetCapture(hwnd);
// is a key pressed?
keyPressed[wParam] = true;
return 0;
break;
case WM_KEYUP:
keyPressed[wParam] = false;
ReleaseCapture();
return 0;
break;
default:
break;
}
return (DefWindowProc(hwnd, message, wParam, lParam));
}
// the application entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd)
{
WNDCLASSEX windowClass; // window class
HWND hwnd; // window handler
MSG msg; // message
// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "MyClass";
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
// register the window class
if (!RegisterClassEx(&windowClass))
return 0;
// class registered, so now create your window
hwnd = CreateWindowEx(NULL, // extended style
"MyClass", // class name
"Text Testing", // app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE |
WS_SYSMENU | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
100, 100, // x,y coordinate
400, 400, // width and height
NULL, // handle to parent
NULL, // handle to menu
hInstance, // application instance
NULL); // no extra params
// check if window creation failed (hwnd would equal NULL)
if (!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW); // display the window
UpdateWindow(hwnd); // update the window
Initialize();
// main message loop
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if (keyPressed[VK_ESCAPE])
PostQuitMessage(0);
if (keyPressed['W']) // if the a key is pressed, turn to the left
{
cameraY += 0.01;
}
if (keyPressed['A']) // if the a key is pressed, turn to the left
{
}
if (keyPressed['S']) // if the a key is pressed, turn to the left
{
cameraY -= 0.01;
}
if (keyPressed['Z']) // if the a key is pressed, turn to the left
{
cameraZ += 0.01;
}
if (keyPressed['Q']) // if the a key is pressed, turn to the left
{
cameraZ -= 0.01;
}
if (keyPressed['D']) // if the a key is pressed, turn to the left
{
}
if (keyPressed['X']) // if the a key is pressed, turn to the left
{
// Reset Camera
initCamera();
}
// render scene
Render(hwnd);
}
}
return msg.wParam;
}