Original Post
Hi, I'm trying to write a font class similiar to the one in the opengl game programming book.
Well my problem is that both SelectObject and wglUseFontBitmap fail. GetLastError returns 6, which is invalid handle. Why is this if wglGetCurrentDC executes without error?
I dropped the class into the tutorial that covered fonts, and it works fine, so i assume the problem lies somewhere in the initilazation of my engine?
Sorry about the length, but im not sure what's causing it. I removed all the error checking to try to hack down the size, but everything was fine except those two functions i mentioned.
[edited by - absolutdew on December 6, 2002 1:40:04 PM]
void generate( std::string type, int height, int weight )
{
base_ = glGenLists( 96 );
HFONT font = CreateFont( -height,
0, 0, 0,
weight,
FALSE, FALSE, FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE | DEFAULT_PITCH,
type.c_str() );
HDC hdc = wglGetCurrentDC();
SelectObject( hdc, font )
wglUseFontBitmaps( hdc, 32, 96, base_ )
}
engine::engine( std::string title, RECT viewport )
{
HINSTANCE hInst = GetModuleHandle( NULL );
WNDCLASSEX WndClass =
{
sizeof( WNDCLASSEX ), // cbSize
CS_HREDRAW | CS_VREDRAW, // style
WndProc, // lpfnWndProc
0, 0, // cbClsExtra, cbWndExtra
hInst, // hInstance
LoadIcon( NULL, IDI_APPLICATION ), // hIcon
LoadCursor( NULL, IDC_ARROW ), // hCursor
(HBRUSH)GetStockObject( BLACK_BRUSH ), // hbrBackground
NULL, // lpszMenuName
"lpszClassName", // lpszClassName
LoadIcon( NULL, IDI_WINLOGO ) // hIconSm
};
RegisterClassEx( &WndClass );
viewport_ = viewport;
hwnd_ = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // dwExStyle
"lpszClassName", // lpClassName
title.c_str(), // lpWindowName
WS_OVERLAPPEDWINDOW, // dwStyle
viewport.left, viewport.top, // x, y
viewport.right, viewport.bottom, // nWidth, nHeight
NULL, // hWndParent
NULL, // hMenu
hInst, // hInstance
NULL ); // lpParam
hdc_ = GetDC( hwnd_ );
init_gl();
ShowWindow( hwnd_, SW_SHOW );
SetForegroundWindow( hwnd_ );
SetFocus( hwnd_ );
}
void engine::init_gl()
{
PIXELFORMATDESCRIPTOR descriptor;
ZeroMemory( &descriptor, sizeof( PIXELFORMATDESCRIPTOR ) );
descriptor.nSize = sizeof( PIXELFORMATDESCRIPTOR );
descriptor.nVersion = 1;
descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
descriptor.iPixelType = PFD_TYPE_RGBA;
descriptor.cColorBits = 32;
descriptor.cDepthBits = 16;
descriptor.iLayerType = PFD_MAIN_PLANE;
int format = ChoosePixelFormat( hdc_, &descriptor );
SetPixelFormat( hdc_, format, &descriptor );
hrc_ = wglCreateContext( hdc_ )
wglMakeCurrent( hdc_, hrc_ );
resize( viewport_ );
glShadeModel( GL_SMOOTH );
glEnable( GL_BLEND );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
font_system = new font();
}