PDA

View Full Version : bitmap font not drawing....hmmm



Al Grant
06-08-2006, 04:14 AM
Hi Folks,

The following code is a hash really of other peoples code, mainly Nehe's.

I am trying to get some font text to draw on the screen without success. I have manage to get text to draw on its own, but the problems start when I integrate it into my own project.

In the DrawGLScene you can even see that I commentted all the other drawing stuff out and my text still didnt draw - blank screen.

Anyone able to help please?

Ta

-Al



/*
* This Code Was Created By Jeff Molofee 2000
* A HUGE Thanks To Fredric Echols For Cleaning Up
* And Optimizing The Base Code, Making It More Flexible!
* If You've Found This Code Useful, Please Let Me Know.
* Visit My Site At nehe.gamedev.net
*/

#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <math.h> // Windows Math Library
#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 "objbase.h" // Needed for COM functionality
#include <stdarg.h> // Header File For Variable Argument Routines

///////////////////////////////////////////////////////////////
// XSENS DEFINES ETC //
///////////////////////////////////////////////////////////////

// import functions in MT object
#include "IMTObj.h"
// GUIDs of MT object
#include "IMTObj_i.c"

// return values for MT_GetOrientation function
#define MT_NEWDATA 1
#define MT_NODATA 2
#define MT_NOSENSORID 3
#define MT_INCOMPLETE 4
#define MT_CHECKSUMERROR 5
#define MT_NOPORT 6
#define MT_NOCALIBVALUES 7
#define MT_POWERLOSS 8

// output possiblities for MT object
#define MT_LOGQUATERNION 0
#define MT_LOGEULER 1
#define MT_LOGROTMATRIX 2

// Global pointer to the MTObj COM Interface
IMotionTracker* pMT;

// Output data format
short g_nMode = MT_LOGEULER;

// Global Varibale to Hold Orientation Data
float fOrientationData[9] = {0};

double pi = 3.1415926535;

///////////////////////////////////////////////////////////////
// OPEN GL VARIABLES ETC //
///////////////////////////////////////////////////////////////

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
GLuint base;
GLuint loop;
GLfloat lines;

GLuint texture[2]; // Storage For One Texture ( NEW )

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc

/////////////////// SETUP FILTER FOR XSENS ////////////////////

void SetupFilter()
{
// Set MTObj COM object options
short m_bLogCalibratedData = FALSE;

// Set MTObj COM object variables
float fGain = 1.0;
short nCorInterval = 1;
float fRho = 1.0;
short nPortNumber = 1;

//////////////////////////////////////////////////////////////////////////
// Sample frequency and .XMU file location not needed with MT9-B
// Sample frequency and .XMU file location needed with MT9-A
//short nSampleFreq = 100;
//wchar_t* wszIn = L"D:\\2025_07082002_000.xmu";
//
//// Allocate string and copy wszIn
//BSTR bstrIn;
//bstrIn = ::SysAllocString(wszIn);
//////////////////////////////////////////////////////////////////////////

// Create instance of MTObj COM object
printf("Create instance of MotionTracker object...");
HRESULT hRes = CoCreateInstance(CLSID_MotionTracker, NULL, CLSCTX_SERVER, IID_IMotionTracker, (void**) &amp;pMT);
if (FAILED(hRes))
{
printf("Error %x in CoCreateInstance for MT object!",hRes);
return;
}
else
printf("done\n\n");


printf("Setting filter parameters...");
// Optional settings
pMT->MT_SetCalibratedOutput(m_bLogCalibratedData);

// Set Gain, Correction interval and Rho
pMT->MT_SetFilterSettings(fGain,nCorInterval,fRho);

// Required settings
pMT->MT_SetOutputMode(g_nMode);

// Set COM port number (1-15) where MT9 is attached
pMT->MT_SetCOMPort(nPortNumber);

//////////////////////////////////////////////////////////////////////////
// Sample frequency and .XMU file location not needed with MT9-B
// Sample frequency and .XMU file location need with MT9-A
//pMT->MT_SetSampleFrequency(nSampleFreq);
//
//// Set .XMU file location
//pMT->MT_SetxmuLocationBSTR(bstrIn);
//
//// Free allocated string
//::SysFreeString(bstrIn);
//////////////////////////////////////////////////////////////////////////

printf("done\n\n");
}


/////////////////// GET DATA FOR XSENS ////////////////////
BOOL GetData()
{

VARIANT OrientationBuffer;
void* pDest;
short nNew = 0;

BOOL bNewData = FALSE;

pMT->MT_GetOrientationData(&amp;nNew, &amp;OrientationBuffer);
if (nNew == MT_NEWDATA)
{
// Check if array is not empty
if (OrientationBuffer.vt != VT_EMPTY)
{
// Retrieve pointer to array data
HRESULT hr = SafeArrayAccessData(OrientationBuffer.parray, &amp;pDest);
// One dimensional array. Get the bounds for the array.

if (SUCCEEDED(hr))
{
__try{
// Copy data from the VARIANT array to the local fData array
memcpy(fOrientationData,pDest,(OrientationBuffer.p array->rgsabound->cElements * sizeof(float)));
bNewData = TRUE;
}
__except(GetExceptionCode() == STATUS_ACCESS_VIOLATION){
bNewData = FALSE;
}

SafeArrayUnaccessData(OrientationBuffer.parray); // Invalidate pointer

// Variant must be cleared. This also destroys the SafeArray
VariantClear(&amp;OrientationBuffer);

// fOrientationData now contains orientation data is bNewData = true
// Can be logged to file or written to screen (see below)

if (g_nMode == MT_LOGEULER)
{
printf("%f %f %f\n",fOrientationData[0],fOrientationData[1],fOrientationData[2]);
}

bNewData = FALSE;

return TRUE;
}
else
return FALSE;
}
else
return FALSE;
}
else if (nNew != 0)
{
// Check if error was reported by MotionTracker object
switch(nNew) {
case MT_NODATA:
printf("No Data On COM Port\n\n");
break;
case MT_NOSENSORID:
printf("No Sensor ID Received From Sensor\n\n");
break;
case MT_INCOMPLETE:
printf("Incomplete Data Received (Connection Lost)\n\n");
break;
case MT_CHECKSUMERROR:
printf("Checksum Error\n\n");
break;
case MT_NOPORT:
printf("COM Port Could Not Be Opened\n\n");
break;
case MT_NOCALIBVALUES:
printf("XMU File With Calibration Data Could Not Be Read or \nMTS Data With Calibration Data Not Set\n\n");
break;
case MT_POWERLOSS:
printf("Power Supply To The Sensor Was Probably Interupted\n\n");
break;
}

return FALSE;
}
else
return TRUE;

}




AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture Data
memset(TextureImage,0,sizeof(void *)*2); // Set The Pointer To NULL

if ((TextureImage[0]=LoadBMP("Untitled-1.bmp")) &amp;&amp; // Logo Texture
(TextureImage[1]=LoadBMP("mask.bmp"))) // Second Image
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(2, &amp;texture[0]); // Create Five Textures

for (loop=0; loop<2; loop++) // Loop Through All 5 Textures
{
glBindTexture(GL_TEXTURE_2D, texture[loop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);
}
}
for (loop=0; loop<2; loop++) // Loop Through All 5 Textures
{
if (TextureImage[loop]) // If Texture Exists
{
if (TextureImage[loop]->data) // If Texture Image Exists
{
free(TextureImage[loop]->data); // Free The Texture Image Memory
}
free(TextureImage[loop]); // Free The Image Structure
}
}
return Status; // Return The Status
}



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
}

glViewport(0,0,width,height); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping

base = glGenLists(96); // Storage For 96 Characters

font = CreateFont( -24, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name

oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}

GLvoid KillFont(GLvoid) // Delete The Font List
{
glDeleteLists(base, 96); // Delete All 96 Characters
}
GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments

if (fmt == NULL) // If There's No Text
return; // Do Nothing

va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text

glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn't Load Return FALSE ( NEW )
}

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
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
return TRUE; // Initialization Went OK
}



int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{

GLfloat radius_1=1.8f;
GLfloat radius_2=2.0f;
GLfloat radius_3=2.2f;

//////////XSENS STUFF //////////////

GetData();

///////////////////////////////////


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-7.0f);



/*
//**** Disable texturing
glDisable(GL_TEXTURE_2D);

glPushMatrix();
glRotatef(fOrientationData[0],0.0f,0.0f,1.0f);
glTranslatef(0.0f,(fOrientationData[1]/18.0)+0.0f,0.0f);

//**** Blue/Brown of Horizon
glBegin(GL_QUADS);
glColor3f(0.0f, 0.6f, 0.796f);
glVertex3f(-6.0f, 18.0f, 0.0f); // Top Left
glVertex3f( 6.0f, 18.0f, 0.0f); // Top Right
glVertex3f( 6.0, 0.0f, 0.0f); // Bottom Right
glVertex3f(-6.0f, 0.0f, 0.0f); // Bottom Left

glColor3f(0.694f, 0.4f, 0.0f);
glVertex3f(-6.0f, -18.0f, 0.0f); // Top Left
glVertex3f( 6.0f, -18.0f, 0.0f); // Top Right
glVertex3f( 6.0f, 0.0f, 0.0f); // Bottom Right
glVertex3f(-6.0f, 0.0f, 0.0f); // Bottom Left

glEnd();

//**** Horizon Lines

for (lines=-18; lines<19; lines++)
{
glBegin(GL_LINES);
glColor3f(1.0f, 1.0f, 1.0f); // Sets Color White

glVertex3f(-6.0f, 0.0f, 0.0f); //Level
glVertex3f(6.0f, 0.0f, 0.0f);

glVertex3f(-0.75f, lines+1.0f, 0.0f); //10 UP
glVertex3f(0.75f, lines+1.0f, 0.0f);

glVertex3f(-0.25f, lines+0.75f, 0.0f); // ---
glVertex3f(0.25f, lines+0.75f, 0.0f);

glVertex3f(-0.5f, lines+0.5f, 0.0f); //---===---
glVertex3f(0.5f, lines+0.5f, 0.0f);

glVertex3f(-0.25f, lines+0.25f, 0.0f); // ---
glVertex3f(0.25f, lines+0.25f, 0.0f);

glEnd();
}

glPopMatrix();

// WINGS
glBegin(GL_QUADS);
glColor3f(0.0f,0.0f,0.0f);
glVertex3f(-1.75f,0.075f,0.0f); //LEFT
glVertex3f(-0.75f,0.075f,0.0f);
glVertex3f(-0.75f,-0.075f,0.0f);
glVertex3f(-1.75f,-0.075f,0.0f);

glVertex3f(-0.75f,-0.075f,0.0f);
glVertex3f(-0.75f,-0.175f,0.0f);
glVertex3f(-0.875f,-0.175f,0.0f);
glVertex3f(-0.875f,-0.075f,0.0f);

glVertex3f(1.75f,0.075f,0.0f); //RIGHT
glVertex3f(0.75f,0.075f,0.0f);
glVertex3f(0.75f,-0.075f,0.0f);
glVertex3f(1.75f,-0.075f,0.0f);

glVertex3f(0.75f,-0.075f,0.0f);
glVertex3f(0.75f,-0.175f,0.0f);
glVertex3f(0.875f,-0.175f,0.0f);
glVertex3f(0.875f,-0.075f,0.0f);

glVertex3f(-0.075f,0.075f,0.0f); // MIDDLE DOT
glVertex3f(0.075f,0.075f,0.0f);
glVertex3f(0.075f,-0.075f,0.0f);
glVertex3f(-0.075f,-0.075f,0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glEnd();

// OUTLINES IN WHITE

glBegin(GL_LINE_LOOP);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(-1.75f,0.075f,0.0f); //LEFT
glVertex3f(-0.75f,0.075f,0.0f);
glVertex3f(-0.75f,-0.175f,0.0f);
glVertex3f(-0.875f,-0.175f,0.0f);
glVertex3f(-0.875f,-0.075f,0.0f);
glVertex3f(-1.75f,-0.075f,0.0f);
glEnd();

glBegin(GL_LINE_LOOP);
glColor3f(1.0f,1.0f,1.0f);
glVertex3f(1.75f,0.075f,0.0f); //LEFT
glVertex3f(0.75f,0.075f,0.0f);
glVertex3f(0.75f,-0.175f,0.0f);
glVertex3f(0.875f,-0.175f,0.0f);
glVertex3f(0.875f,-0.075f,0.0f);
glVertex3f(1.75f,-0.075f,0.0f);
glEnd();

glBegin(GL_LINE_LOOP);
glVertex3f(-0.075f,0.075f,0.0f); // MIDDLE DOT
glVertex3f(0.075f,0.075f,0.0f);
glVertex3f(0.075f,-0.075f,0.0f);
glVertex3f(-0.075f,-0.075f,0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glEnd();


glPushMatrix(); // MOVING NON FILLED BANK TRIANGLE
glRotatef(fOrientationData[0],0.0f,0.0f,1.0f);
glBegin(GL_LINE_LOOP);
glVertex3f(-0.15f,1.6f,0.0f);
glVertex3f(-0.15f,1.5f,0.0f);
glVertex3f(0.15f,1.5f,0.0f);
glVertex3f(0.15f,1.6f,0.0f);
glVertex3f(0.0f,1.8,0.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glEnd();
glPopMatrix();

glBegin(GL_TRIANGLES); // NON MOVING BANK TRIANGLE - R=1.8
glVertex3f(0.0f,1.8,0.0f);
glVertex3f(-0.15f,2.0f,0.0f);
glVertex3f(0.15f,2.0f,0.0f);
glEnd();


glRotatef(90,0.0f,0.0f,1.0f);
glBegin(GL_LINES);
glVertex3f(radius_1*cos(pi/18),radius_1*sin(pi/18),0.0f); //10 deg
glVertex3f(radius_2*cos(pi/18),radius_2*sin(pi/18),0.0f);
glVertex3f(radius_1*cos(pi/9),radius_1*sin(pi/9),0.0f); // 20 deg
glVertex3f(radius_2*cos(pi/9),radius_2*sin(pi/9),0.0f);
glVertex3f(radius_1*cos(pi/6),radius_1*sin(pi/6),0.0f); // 30 deg
glVertex3f(radius_3*cos(pi/6),radius_3*sin(pi/6),0.0f);
glVertex3f(radius_1*cos(pi/4),radius_1*sin(pi/4),0.0f); // 45 deg
glVertex3f(radius_2*cos(pi/4),radius_2*sin(pi/4),0.0f);
glVertex3f(radius_1*cos(pi/3),radius_1*sin(pi/3),0.0f); // 60 deg
glVertex3f(radius_3*cos(pi/3),radius_3*sin(pi/3),0.0f);
glEnd();


pi=pi*-1;
glBegin(GL_LINES);
glVertex3f(radius_1*cos(pi/18),radius_1*sin(pi/18),0.0f); //10 deg
glVertex3f(radius_2*cos(pi/18),radius_2*sin(pi/18),0.0f);
glVertex3f(radius_1*cos(pi/9),radius_1*sin(pi/9),0.0f); // 20 deg
glVertex3f(radius_2*cos(pi/9),radius_2*sin(pi/9),0.0f);
glVertex3f(radius_1*cos(pi/6),radius_1*sin(pi/6),0.0f); // 30 deg
glVertex3f(radius_3*cos(pi/6),radius_3*sin(pi/6),0.0f);
glVertex3f(radius_1*cos(pi/4),radius_1*sin(pi/4),0.0f); // 45 deg
glVertex3f(radius_2*cos(pi/4),radius_2*sin(pi/4),0.0f);
glVertex3f(radius_1*cos(pi/3),radius_1*sin(pi/3),0.0f); // 60 deg
glVertex3f(radius_3*cos(pi/3),radius_3*sin(pi/3),0.0f);
glEnd();

//**** Enable texturing
glEnable(GL_TEXTURE_2D);

glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_DST_COLOR,GL_ZERO);

glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS); // Start Drawing A Textured Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5.0f, 5.0f, 0.0f); // Bottom Left
glTexCoord2f(1.0f, 1.0f); glVertex3f(5.0f, 5.0f, 0.0f); // Bottom Right
glTexCoord2f(1.0f, 0.0f); glVertex3f(5.0f, -5.0f, 0.0f); // Top Right
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5.0f, -5.0f, 0.0f); // Top Left
glEnd();

glDisable(GL_BLEND);
*/

//***** Font Stuff ******
glColor3f(1.0f,1.0f,1.0f);
glRasterPos3f(0.0f,0.0f,0.0f);
glPrint("Active OpenGL Text With NeHe");

return TRUE; // Everything Went OK
}

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}

if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL
}

if (hDC &amp;&amp; !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}

if (hWnd &amp;&amp; !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}

if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
KillFont();
}

/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Fullscreen Mode *
* height - Height Of The GL Window Or Fullscreen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height

fullscreen=fullscreenflag; // Set The Global Fullscreen Flag

hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name

if (!RegisterClass(&amp;wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&amp;dmScreenSettings,0,sizeof(dmScreenSettings )); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWID TH|DM_PELSHEIGHT;

// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&amp;dmScreenSettings,CDS_FULLS CREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}

if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}

AdjustWindowRectEx(&amp;WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size

// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&amp;pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!SetPixelFormat(hDC,PixelFormat,&amp;pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen

if (!InitGL()) // Initialize Our Newly Created GL Window
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

return TRUE; // Success
}

LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
switch (uMsg) // Check For Windows Messages
{
case WM_ACTIVATE: // Watch For Window Activate Message
{
if (!HIWORD(wParam)) // Check Minimization State
{
active=TRUE; // Program Is Active
}
else
{
active=FALSE; // Program Is No Longer Active
}

return 0; // Return To The Message Loop
}

case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}

case WM_CLOSE: // Did We Receive A Close Message?
{
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}

case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = TRUE; // If So, Mark It As TRUE
return 0; // Jump Back
}

case WM_KEYUP: // Has A Key Been Released?
{
keys[wParam] = FALSE; // If So, Mark It As FALSE
return 0; // Jump Back
}

case WM_SIZE: // Resize The OpenGL Window
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back
}
}

// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop

////////////XSENS
CoInitialize(NULL);
SetupFilter();
pMT->MT_StartProcess();

// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // Windowed Mode
}

// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's First Polygon Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}

while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&amp;msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&amp;msg); // Translate The Message
DispatchMessage(&amp;msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active &amp;&amp; !DrawGLScene()) &amp;#0124;&amp;#0124; keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}

if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's First Polygon Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}

// Shutdown
KillGLWindow(); // Kill The Window


//////////////////XSENS////////////////
pMT->MT_StopProcess();

if (pMT != NULL)
{
pMT->Release();

pMT = NULL;
}

// Uninitialize COM library
CoUninitialize();


return (msg.wParam); // Exit The Program
}

Al Grant
06-08-2006, 04:15 AM
PS: Believe it or not I am learning.

RigidBody
06-08-2006, 04:45 AM
that's a lot of lines. most of them- like WinMain, GetData, SetupFilter- irrelevant to your problem. this doesn't make it easier to find the problem.

at first sight, glListBase could be causing the problem. remove it and try again.

Al Grant
06-08-2006, 04:50 AM
Remove which line? This one:

glListBase(base - 32);

I have ripped a lot of the code from NeHe's tutorial and it has that line in so...

-Al

Al Grant
06-08-2006, 04:51 AM
However you are right - I remarked that line out and things worked....I will dig deeper.

-Al

Al Grant
06-08-2006, 04:52 AM
Sorry - spoke too soon - remarking out that line didnt do anything.

Al Grant
06-08-2006, 05:07 AM
I dont think it can be anything in the DrawGLScene, because I remarked all my stuff out so that it was essentially the same as NeHe's example, but I still got a blank screen. So it must be something before that?

Al Grant
06-08-2006, 05:25 AM
I found the error. I didnt have IntGL call BuildFont().

The one thing that is still going wrong however is my text is black, yet I set glcolor at 1,1,1??

Cheers

-Al

RigidBody
06-08-2006, 05:46 AM
sorry, i was wrong. the glListBase line is ok.

anyway: don't just paste code together that you don't understand. build yourself a small program framework that just creates a window and a gl context with a display func that just clears and swaps the buffers.

then, each time you want to try something new, use the prog framework, knowing that any occuring problem cannot arise from the fact that you don't have a valid gl context or made some other basic error.

for drawing text, you could use the program framework and add only 3 or 4 lines. this makes it much easier to find errors.

Al Grant
06-08-2006, 05:56 AM
RigidBody,

I think I know what you mean by a framework.

I have been using NeHe's so far, but if you can show my how to put text on the screen and only add a few more lines to a framework i would be interested to see it.

Lastly, I have the lines:


glColor3f(1.0f,1.0f,1.0f);
glRasterPos3f(-1.1f,0.9f,0.0f);
glPrint("10 10");

I would like to apply a rotation to this and have tried putting :
glRotatef(angle,0.0f,0.0f,1.0f);
before it, but this doesnt work. What am I missing now!!???

Cheers

-Al

RigidBody
06-08-2006, 06:06 AM
actually, all that you need is wglUseFontBitMap once after you've made your context current.

then, each time you want to draw text: glColor3f to set the color, glRasterPos for the position, finally glCallLists to display the string.

glColor3f has to be called before glRasterpos. an alternative to glRasterPos is glWindowPos, which lets you specify the position in window coordinates. if you use it, you don't have to think about transformation matrices. glWindowPos used to be an extension, so if you have an old gl.h header file, it's probably not present.

charliejay
06-09-2006, 01:04 AM
AFAIK, you can't rotate bitmap and pixmap data, they're screen aligned...

The consequence of that being, if you want rotation, that you need to use textured quads, or models of the actual letters, etc...

RigidBody
06-09-2006, 01:08 AM
of course, glRotate etc. have no effect on the bitmap data itself, but on the raster position.

Al Grant
06-09-2006, 01:47 PM
So how would you put text on the screen and rotate it?

06-09-2006, 09:12 PM
Your text is the wrong color even though you called the glColor because you never disabled the GL_TEXTURE_2D. This will set the color to the last color of your bitmap. Run glDisable(GL_TEXTURE_2D); and then add and enable as soon as you are done rastering.

Carl

charliejay
06-12-2006, 01:05 AM
"So how would you put text on the screen and rotate it?"

Using textured quads, see NeHe, I believe he has a tutorial on this, likewise for full 3D modelled text if you're in Windows...