bool LoadFont(char in_name[], font_t* font, BYTE height, LONG weight) { static int count; char buf[100]; string name; count++; font->font = CreateFont(-height, 0, 0, 0 , weight, 0, 0, 0, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE || DEFAULT_PITCH, in_name); font->height = height; font->weight = weight; //font->name = strcat("FONT", itoa(count, buf, 10)); name = "Font" + string(itoa(count, buf, 10)); font->name = (char*)name.c_str(); if(!font) { LogToFile("debug.log", "Failed to load font: " + name); MessageBox(NULL, "Failed to load font", "CreateFont() Error", MB_OK | MB_ICONEXCLAMATION); return false; } SelectObject(hDC, font->font); font->base = glGenLists(256); wglUseFontBitmaps(hDC, 0, 255, font->base); //wglUseFontOutlines(hDC, 0, 255, font->base, 0.0f, 0.5f, WGL_FONT_POLYGONS, font->lpgmf); #ifdef _DEBUG_ LogToFile("debug.log", "Font loaded: " + name); #endif font_count++; return true; }
////////////////////////////////////////////////////////////////////////////// // font ////////////////////////////////////////////////////////////////////////////// unsigned int RGL::setFont(unsigned int fSize, const char * fName) { #ifdef _WIN32 LOGFONT lf; ZeroMemory(&lf, sizeof(lf)); lstrcpy(lf.lfFaceName, fName ); lf.lfHeight = fSize; //lf.lfWeight = FW_HEAVY; //lf.lfItalic = TRUE; //lf.lfUnderline = TRUE; HFONT font = CreateFontIndirect(&lf); if ( font ) { HDC dc = wglGetCurrentDC(); SelectObject( dc, font ); SendMessage( GetActiveWindow(), WM_SETFONT, (WPARAM)font, 1 ); gl_font_base = glGenLists(256); wglUseFontBitmaps(dc, 0, 255, gl_font_base); return true; } #endif return gl_font_base; }
/* ============ CameraWndProc ============ */ LONG WINAPI WCam_WndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int fwKeys, xPos, yPos; RECT rect; GetClientRect(hWnd, &rect); switch (uMsg) { case WM_CREATE: { HFONT hfont; g_qeglobals.d_hdcBase = GetDC(hWnd); QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true); if ( ( g_qeglobals.d_hglrcBase = wglCreateContext( g_qeglobals.d_hdcBase ) ) == 0 ) Error ("wglCreateContext failed"); if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase )) Error ("wglMakeCurrent failed"); Texture_SetMode(g_qeglobals.d_savedinfo.iTexMenu); // // create GL font // hfont = CreateFont( 10, // logical height of font 7, // logical average character width 0, // angle of escapement 0, // base-line orientation angle 0, // font weight 0, // italic attribute flag 0, // underline attribute flag 0, // strikeout attribute flag 0, // character set identifier 0, // output precision 0, // clipping precision 0, // output quality 0, // pitch and family 0 // pointer to typeface name string ); if ( !hfont ) Error( "couldn't create font" ); SelectObject (g_qeglobals.d_hdcBase, hfont); if ( ( g_qeglobals.d_font_list = glGenLists (256) ) == 0 ) Error( "couldn't create font dlists" ); // create the bitmap display lists // we're making images of glyphs 0 thru 255 if ( !wglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) ) Error( "wglUseFontBitmaps faileD" ); // indicate start of glyph display lists glListBase (g_qeglobals.d_font_list); // report OpenGL information Sys_Printf ("GL_VENDOR: %s\n", glGetString (GL_VENDOR)); Sys_Printf ("GL_RENDERER: %s\n", glGetString (GL_RENDERER)); Sys_Printf ("GL_VERSION: %s\n", glGetString (GL_VERSION)); Sys_Printf ("GL_EXTENSIONS: %s\n", glGetString (GL_EXTENSIONS)); } return 0; case WM_PAINT: { PAINTSTRUCT ps; if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase )) Error ("wglMakeCurrent failed"); if ( BeginPaint(hWnd, &ps) ) { QE_CheckOpenGLForErrors(); Cam_Draw (); QE_CheckOpenGLForErrors(); EndPaint(hWnd, &ps); SwapBuffers(g_qeglobals.d_hdcBase); } } return 0; case WM_USER+267: // benchmark { PAINTSTRUCT ps; WINDOWPLACEMENT wp; double start, end; int i; memset( &wp, 0, sizeof( wp ) ); wp.length = sizeof( wp ); GetWindowPlacement( g_qeglobals.d_hwndCamera, &wp ); MoveWindow( g_qeglobals.d_hwndCamera, 30, 30, 400, 400, TRUE ); BeginPaint(hWnd, &ps); if (!wglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase)) Error ("wglMakeCurrent failed"); glDrawBuffer (GL_FRONT); start = Sys_DoubleTime (); for (i=0 ; i<100 ; i++) { camera.angles[YAW] = i*4; Cam_Draw (); } SwapBuffers(g_qeglobals.d_hdcBase); glDrawBuffer (GL_BACK); end = Sys_DoubleTime (); EndPaint(hWnd, &ps); Sys_Printf ("%5.2f seconds\n", end-start); SetWindowPlacement( g_qeglobals.d_hwndCamera, &wp ); } break; case WM_KEYDOWN: if ( QE_KeyDown (wParam) ) return 0; else return DefWindowProc( hWnd, uMsg, wParam, lParam ); case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: case WM_LBUTTONDOWN: if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd) BringWindowToTop(hWnd); SetFocus (g_qeglobals.d_hwndCamera); SetCapture (g_qeglobals.d_hwndCamera); fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseDown (xPos, yPos, fwKeys); return 0; case WM_MBUTTONUP: case WM_RBUTTONUP: case WM_LBUTTONUP: fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseUp (xPos, yPos, fwKeys); if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON))) ReleaseCapture (); return 0; case WM_MOUSEMOVE: fwKeys = wParam; // key flags xPos = (short)LOWORD(lParam); // horizontal position of cursor yPos = (short)HIWORD(lParam); // vertical position of cursor yPos = (int)rect.bottom - 1 - yPos; Cam_MouseMoved (xPos, yPos, fwKeys); return 0; case WM_SIZE: camera.width = rect.right; camera.height = rect.bottom; InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false); return 0; case WM_KILLFOCUS: case WM_SETFOCUS: SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 ); return 0; case WM_NCCALCSIZE:// don't let windows copy pixels DefWindowProc (hWnd, uMsg, wParam, lParam); return WVR_REDRAW; case WM_CLOSE: DestroyWindow (hWnd); return 0; case WM_DESTROY: QEW_StopGL( hWnd, g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase ); return 0; } return DefWindowProc( hWnd, uMsg, wParam, lParam ); }
/////////////////////////////////////////////////////////////////////////////// // Setup. Create font/bitmaps, load textures, create display lists void SetupRC(HDC hDC) { M3DVector3f vPoints[3] = {{ 0.0f, -0.4f, 0.0f }, { 10.0f, -0.4f, 0.0f }, { 5.0f, -0.4f, -5.0f } }; int iSphere; int i; // Setup the Font characteristics HFONT hFont; LOGFONT logfont; logfont.lfHeight = -20; logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = FW_BOLD; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = ANSI_CHARSET; logfont.lfOutPrecision = OUT_DEFAULT_PRECIS; logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; logfont.lfQuality = DEFAULT_QUALITY; logfont.lfPitchAndFamily = DEFAULT_PITCH; strcpy(logfont.lfFaceName,"Arial"); // Create the font and display list hFont = CreateFontIndirect(&logfont); SelectObject (hDC, hFont); //Create display lists for glyphs 0 through 128 nFontList = glGenLists(128); wglUseFontBitmaps(hDC, 0, 128, nFontList); DeleteObject(hFont); // Don't need original font anymore // Grayish background glClearColor(fLowLight[0], fLowLight[1], fLowLight[2], fLowLight[3]); // Clear stencil buffer with zero, increment by one whenever anybody // draws into it. When stencil function is enabled, only write where // stencil value is zero. This prevents the transparent shadow from drawing // over itself glStencilOp(GL_INCR, GL_INCR, GL_INCR); glClearStencil(0); glStencilFunc(GL_EQUAL, 0x0, 0x01); // Cull backs of polygons glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); // Setup light parameters glLightModelfv(GL_LIGHT_MODEL_AMBIENT, fNoLight); glLightfv(GL_LIGHT0, GL_AMBIENT, fLowLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight); glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Calculate shadow matrix M3DVector4f pPlane; m3dGetPlaneEquation(pPlane, vPoints[0], vPoints[1], vPoints[2]); m3dMakePlanarShadowMatrix(mShadowMatrix, pPlane, fLightPos); // Mostly use material tracking glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMateriali(GL_FRONT, GL_SHININESS, 128); // Randomly place the sphere inhabitants for(iSphere = 0; iSphere < NUM_SPHERES; iSphere++) { // Pick a random location between -20 and 20 at .1 increments spheres[iSphere].SetOrigin((float)((rand() % 400) - 200) * 0.1f, 0.0f, (float)((rand() % 400) - 200) * 0.1f); } // Set up texture maps glEnable(GL_TEXTURE_2D); glGenTextures(NUM_TEXTURES, textureObjects); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Load teach texture for(i = 0; i < NUM_TEXTURES; i++) { GLbyte *pBytes; GLint iWidth, iHeight, iComponents; GLenum eFormat; glBindTexture(GL_TEXTURE_2D, textureObjects[i]); // Load this texture map pBytes = gltLoadTGA(szTextureFiles[i], &iWidth, &iHeight, &iComponents, &eFormat); gluBuild2DMipmaps(GL_TEXTURE_2D, iComponents, iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Trilinear mipmapping glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } // Get window position function pointer if it exists glWindowPos2i = (PFNGLWINDOWPOS2IPROC)wglGetProcAddress("glWindowPos2i"); // Get swap interval function pointer if it exists wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); if(wglSwapIntervalEXT != NULL && startupOptions.bVerticalSync == TRUE) wglSwapIntervalEXT(1); // If multisampling was available and was selected, enable if(startupOptions.bFSAA == TRUE && startupOptions.nPixelFormatMS != 0) glEnable(GL_MULTISAMPLE_ARB); // If sepearate specular color is available, make torus shiney if(gltIsExtSupported("GL_EXT_separate_specular_color")) glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); // Initialize the timers QueryPerformanceFrequency(&CounterFrequency); QueryPerformanceCounter(&FPSCount); CameraTimer = FPSCount; // Build display lists for the torus and spheres // (You could do one for the ground as well) lTorusList = glGenLists(2); lSphereList = lTorusList + 1; glNewList(lTorusList, GL_COMPILE); gltDrawTorus(0.35f, 0.15f, 61, 37); glEndList(); glNewList(lSphereList, GL_COMPILE); gltDrawSphere(0.3f, 31, 16); glEndList(); }
void CMFCTessView::OnDraw(CDC* pDC) { CMFCTessDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here //some per-drawing init stuff glLoadIdentity(); //setup drawing dimensions, etc CPoint vptorg = m_pDC->GetViewportOrg() ; //note m_pDC, NOT pDC CRect rect ; GetWindowRect( &rect ) ; int dx = rect.Width() ; int dy = rect.Height() ; glViewport( 0, 0, dx, dy ); glMatrixMode( GL_MODELVIEW ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // create bitmaps for the device context font's first 256 glyphs HDC hdc = m_pDC->GetSafeHdc() ; wglUseFontBitmaps(hdc, 0, 256, 1000); glListBase(1000); float R ; if( pDoc->m_ContourList.GetCount() > 0 ) { CalculateExtents() ; // Collect overall figure extents (in meters) R = Radius ; //11/29/03 experiment to eliminate probs w/non-square windows float glleft = -R ; float gltop = +R ; float nearplane = -R ; //rev 07/25/03 float farplane = R ; //rev 07/25/03 float glleft2 = glleft ; float gltop2 = gltop ; float glright2 = ( glleft + 2*R ) ; float glbottom2 = ( gltop - 2*R ) ; //adjust for non-square viewing window float dxdy = (float)dx/(float)dy ; //=1.00 for square window if( dxdy > 1 ) { glOrtho( glleft2*dxdy , glright2*dxdy, glbottom2, gltop2, nearplane, farplane ) ; } else { glOrtho( glleft2 , glright2, glbottom2/dxdy, gltop2/dxdy, nearplane, farplane ) ; } glTranslatef( -m_Center.x, -m_Center.y, -m_Center.z ) ; } else { CString txtstr ; glOrtho( -1.f , 1.f, -1.f, 1.f, -1.f, 1.f ) ; glTranslatef( 0.f, 0.f, 0.f ) ; txtstr = "Nothing to draw" ; glColor3f( 0.f, 0.f, 0.f ) ; glRasterPos3f(0.0F, 0.0F, 0.0F ); glCallLists(txtstr.GetLength(), GL_UNSIGNED_BYTE, txtstr); //clean up & exit glFlush(); glDeleteLists(1000, 256) ; SwapBuffers( m_pDC->GetSafeHdc() ); return ; } glPushMatrix() ; //01/09/05 implement tessellation GLUtesselator *tobj; tobj = gluNewTess(); //added 02/09/05 as part of mem leak fix while( gm_VertexPtrList.GetCount() > 0 ) { GLdouble* pV = (GLdouble*)gm_VertexPtrList.RemoveHead() ; delete[] pV ; pV = NULL ; } gluTessCallback(tobj, GLU_TESS_BEGIN, (void (CALLBACK *) ())beginCallback); gluTessCallback(tobj, GLU_TESS_VERTEX, (void (CALLBACK *) ()) vertexCallback); gluTessCallback(tobj, GLU_TESS_END, (void (CALLBACK *) ())endCallback); gluTessCallback(tobj, GLU_TESS_ERROR,(void (CALLBACK *) ())errorCallback); gluTessCallback(tobj, GLU_TESS_COMBINE, (void (CALLBACK *) ())combineCallback); glShadeModel(GL_SMOOTH); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, m_WindingRule ); //only one polygon, but multiple contours gluTessBeginPolygon(tobj, NULL); POSITION pos = pDoc->m_ContourList.GetHeadPosition() ; while ( pos ) { CContour* pCtr = (CContour*)pDoc->m_ContourList.GetNext( pos ) ; ASSERT( pCtr != NULL && pCtr->m_NumVertex > 0 && pCtr->m_ppVertexArray != NULL ) ; int numcorners = pCtr->m_NumVertex ; gluTessBeginContour(tobj); for( int cnridx = 0; cnridx < numcorners; cnridx++ ) { GLdouble* glvert = pCtr->m_ppVertexArray[cnridx]; gluTessVertex( tobj, glvert, glvert ) ; TRACE( "Draw: Sent vertex(%f,%f,%f,%f,%f,%f)\n", glvert[0],glvert[1],glvert[2],glvert[3],glvert[4],glvert[5] ) ; } gluTessEndContour(tobj); } //end of all contour definitions gluTessEndPolygon(tobj); //clean up & exit glFlush(); glDeleteLists(1000, 256) ; // delete our 256 glyph display lists SwapBuffers( m_pDC->GetSafeHdc() ); gluDeleteTess( tobj ) ; //added 02/09/05 as part of mem leak fix while( gm_VertexPtrList.GetCount() > 0 ) { GLdouble* pV = (GLdouble*)gm_VertexPtrList.RemoveHead() ; delete[] pV ; pV = NULL ; } }
// // Constructor // CBitmapFont::CBitmapFont( const TDesc& Desc, UINT FirstGlyph, UINT GlyphsCount ): CFont( GlyphsCount ) { // // Non-portable codepath. // #ifdef _WIN32 HDC DC = wglGetCurrentDC(); if (!DC) throw Sys::CException( this, "::CBitmapFont() : Failed to get current DC." ); LOGFONT lf; ZeroMemory( &lf, sizeof( LOGFONT ) ); lf.lfHeight = Desc.Height; lf.lfWidth = Desc.Width; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = Desc.Weight; lf.lfItalic = Desc.Italic ? TRUE : FALSE; lf.lfUnderline = Desc.Underline ? TRUE : FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = Desc.CharSet; lf.lfOutPrecision = Desc.OutputPrecision; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = Desc.Quality; lf.lfPitchAndFamily = Desc.PitchAndFamily; // FF_DONTCARE | DEFAULT_PITCH wcscpy( lf.lfFaceName, Desc.FaceName ); HFONT Font, OldFont; Font = CreateFontIndirect( &lf ); if (!Font) throw Sys::CException( this, "::CBitmapFont() : Failed to create font." ); OldFont = (HFONT)SelectObject( DC, Font ); try { if (!wglUseFontBitmaps( DC, FirstGlyph, m_GlyphsCount - 1, m_ListBase )) throw Sys::CException( this, "::CBitmapFont() : Failed to create glyph bitmaps." ); } catch (const Sys::CException& Ex) { SelectObject( DC, OldFont ); DeleteObject( Font ); throw Ex; } SelectObject( DC, OldFont ); DeleteObject( Font ); #elif defined (__linux__) #endif // _WIN32 }
// Init2d method --------------------------------------------------------------+ bool CGLFont::Init2d(HDC hdcContext, FontMode fm, HFONT hFont, GLuint iWidth, GLuint iHeigth, GLuint iTexture) { if (m_FontMode!= fmNone) return false; HFONT hFontOld; BOOL bRet = TRUE; float fCx, fCy; // size of characters... in 2d mode should be fixed size m_fSize[0][0] = (float)iWidth; m_fSize[0][1] = (float)iHeigth; // build appropriate font: m_FontMode = fm; switch ( m_FontMode ) { case fmBitmap: { m_iList = glGenLists(256); hFontOld = (HFONT)SelectObject(hdcContext, hFont); bRet = wglUseFontBitmaps(hdcContext, 0, 255, m_iList); SelectObject(hdcContext, hFontOld); DeleteObject(hFont); break; } case fmTexture: { m_iList = glGenLists(256); m_iTexture = iTexture; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_iTexture); // create 256 textured flat quads: for (GLuint i = 0; i < 256; ++i) { fCx = (float)(i%16)/16.0f; // X Position Of Current Character fCy = (float)(i/16)/16.0f; // Y Position Of Current Character glNewList(m_iList + i, GL_COMPILE); glBegin(GL_QUADS); glTexCoord2f(fCx, 1-fCy-0.0625f); glVertex2i(0, iWidth); glTexCoord2f(fCx + 0.0625f, 1 - fCy - 0.0625f); glVertex2i(iWidth, iWidth); glTexCoord2f(fCx + 0.0625f, 1 - fCy); glVertex2i(iWidth, 0); glTexCoord2f(fCx, 1 - fCy); glVertex2i(0, 0); glEnd(); glTranslated(10, 0, 0); glEndList(); } break; } case fm3d: break; // one must call Init3d! default: m_FontMode = fmNone; } // any errors? if (bRet == FALSE) { glDeleteLists(m_iList, 256); return false; } return true; // success! }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) { WNDCLASS wc; HWND hWnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; wc.style = CS_OWNDC; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "GLpong"; RegisterClass (&wc); hWnd = CreateWindow ( "GLpong", "ponggl", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 70, 70, 800, 600, NULL, NULL, hInstance, NULL); EnableOpenGL (hWnd, &hDC, &hRC); BuildFont(); wglUseFontBitmaps(hDC, 32, 96, base); while (!bQuit) { if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage (&msg); DispatchMessage (&msg); } } else { glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT); //glColor3f(1,1,1); //glPushMatrix(); glBegin(GL_TRIANGLE_FAN); //ball //glColor3f(1,0,0); glColor3f(0,1,0); glVertex3f(posx+(GLfloat).01,posy+(GLfloat).01,0); glVertex3f(posx-(GLfloat).01,posy+(GLfloat).01,0); glVertex3f(posx-(GLfloat).01,posy-(GLfloat).01,0); glVertex3f(posx+(GLfloat).01,posy-(GLfloat).01,0); glEnd(); glBegin(GL_TRIANGLES); //paddle //glColor3f(1,0,0); glColor3f(0,1,0); glVertex3f((GLfloat)(mousex-400)/400,(GLfloat)-1*(mousey-300)/300,0); glVertex3f(0,0,0); glVertex3f((GLfloat)(mousex-400)/400-(GLfloat).1,(GLfloat)-1*(mousey-300)/300,0); glEnd(); glRasterPos2f(0.05f,0.05f); glPrint("testx%f",(float)mousex); if (posx==0){richtungsvektor.x=(GLfloat).01;richtungsvektor.y=(GLfloat).03;} if (posx>1){glPrint("gr%f",(float)posx);richtungsvektor.x=(GLfloat)-.01; } if (posx<-1){glPrint("kl%f",(float)posx);richtungsvektor.x=(GLfloat)+.01; } if (posy>1){glPrint("gr%f",(float)posy);richtungsvektor.y=(GLfloat)-.03; } if (posy<-1){glPrint("kl%f",(float)posy);richtungsvektor.y=(GLfloat)+.03; } //if (-0.5>posx){glPrint("kl%f",(float)posx);richtungsvektor.x=-.001; } /*if (posx<-0.5f){richtungsvektor.x=-.001;} if (posy>0.5f){richtungsvektor.y=.002;} if (posy<-0.5f){richtungsvektor.y=-.002;} */ posx+=richtungsvektor.x; posy+=richtungsvektor.y; //glPopMatrix(); SwapBuffers (hDC); } } DisableOpenGL (hWnd, hDC, hRC); DestroyWindow (hWnd); return msg.wParam; }
TextWriter::TextWriter(int in_x, int in_y, Renderer &in_renderer, bool in_centered, int in_size, std::wstring fontname) : x(in_x), y(in_y), size(in_size), original_x(0), last_line_height(0), centered(in_centered), renderer(in_renderer) { x += renderer.m_xoffset; original_x = x; y += renderer.m_yoffset; #ifdef WIN32 Context c = renderer.m_context; point_size = MulDiv(size, GetDeviceCaps(c, LOGPIXELSY), 72); HFONT font = 0; if (font_size_lookup[in_size] == 0) { // Set up the LOGFONT structure LOGFONT logical_font; logical_font.lfHeight = get_point_size(); logical_font.lfWidth = 0; logical_font.lfEscapement = 0; logical_font.lfOrientation = 0; logical_font.lfWeight = FW_NORMAL; logical_font.lfItalic = false; logical_font.lfUnderline = false; logical_font.lfStrikeOut = false; logical_font.lfCharSet = ANSI_CHARSET; logical_font.lfOutPrecision = OUT_DEFAULT_PRECIS; logical_font.lfClipPrecision = CLIP_DEFAULT_PRECIS; logical_font.lfQuality = PROOF_QUALITY; logical_font.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; lstrcpy(logical_font.lfFaceName, fontname.c_str()); font = CreateFontIndirect(&logical_font); HFONT previous_font = (HFONT)SelectObject(c, font); wglUseFontBitmaps(c, 0, 128, next_call_list_start); font_size_lookup[in_size] = next_call_list_start; font_handle_lookup[in_size] = font; next_call_list_start += 130; SelectObject(c, previous_font); } #else // TODO: is this sufficient? point_size = size; if (font_size_lookup[size] == 0) { int list_start = glGenLists(128); // MACNOTE: Force Trebuchet MS. It's what we mostly use anyway, but // I want to be sure they have it. const CFStringRef font_name = CFSTR("Trebuchet MS"); ATSFontFamilyRef font = ATSFontFamilyFindFromName(font_name, kATSOptionFlagsDefault); if (!font) throw PianoGameError(WSTRING(L"Couldn't get ATSFontFamilyRef for font '" << WideFromMacString(font_name) << L"'.")); AGLContext context = aglGetCurrentContext(); if (!context) throw PianoGameError(L"Couldn't retrieve OpenGL context while creating font."); GLboolean ret = aglUseFont(context, font, normal, size, 0, 128, list_start); if (ret == GL_FALSE) throw PianoGameError(WSTRING(L"aglUseFont() call failed with error code: " << aglGetError())); font_size_lookup[size] = list_start; // Create the ATSU style object that we'll use for calculating text extents and store it for later. ATSUStyle style; OSStatus status = ATSUCreateStyle(&style); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create ATSU style. Error code: " << static_cast<int>(status))); Fixed fixed_size = Long2Fix(size); ATSUAttributeTag tags[] = { kATSUSizeTag }; ByteCount sizes[] = { sizeof(Fixed) }; ATSUAttributeValuePtr values[] = { &fixed_size }; status = ATSUSetAttributes(style, sizeof(sizes) / sizeof(ByteCount), tags, sizes, values); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't set ATSU style attributes. Error code: " << static_cast<int>(status))); atsu_style_lookup[size] = style; } #endif }
bool CChildView::GLLoadFont() { CFont ThisFont; CFont* pOldFont; int l; CPaintDC dc(this); // device context for painting HDC hDC = dc.m_hDC; wglMakeCurrent(dc.m_hDC,m_hRC); CFont TempFont; LOGFONT lf; if(!TempFont.CreatePointFont(85, "Courier New")) { // AfxMessageBox("Font Courrier New is not present\n switching to Courier Font"); if(!TempFont.CreatePointFont(85, "Courier")) { // AfxMessageBox("Couldn't find Courier font either. Exiting..."); TempFont.CreateFont( 12, // nHeight 8, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality FIXED_PITCH | FF_MODERN, // nPitchAndFamily "DefaultFont"); // lpszFacename } } TempFont.GetLogFont(&lf); lf.lfHeight = m_WndLogFont.lfHeight; if(!ThisFont.CreateFontIndirect(&lf)) { AfxMessageBox("Couldn't create indirect Font. Exiting..."); return false; } pOldFont = dc.SelectObject(&ThisFont); if(!wglUseFontBitmaps(hDC, 0,255, GLF_START_LIST)) { AfxMessageBox("Couldn't create GL Font Bitmaps. Exiting..."); return false; } MAT2 m2 = {{0, 1}, {0, 0}, {0, 0}, {0, 1}}; GLYPHMETRICS gm; m_LetterWidth = 0; DWORD res; for (l=42; l<122; l++) { res = dc.GetGlyphOutline(l, 0, &gm, 0, NULL, &m2); if(res==-1) { AfxMessageBox("Couldn't create GL Glyph Outline. Exiting..."); return false; } m_LetterWidth = max (m_LetterWidth,(int)(gm.gmBlackBoxX)); } dc.SelectObject(pOldFont); wglMakeCurrent(dc.m_hDC,NULL); return true; }
//--------------------------------------------------------------------------- void CFabAtHomeView::InitGL() //--------------------------------------------------------------------------- { PIXELFORMATDESCRIPTOR pfd; int n; GLfloat fMaxObjSize, fAspect; GLfloat fNearPlane, fFarPlane; m_pDC = new CClientDC(this); ASSERT(m_pDC != NULL); if (!bSetupPixelFormat()) return; n = ::GetPixelFormat(m_pDC->GetSafeHdc()); ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd); hrc = wglCreateContext(m_pDC->GetSafeHdc()); wglMakeCurrent(m_pDC->GetSafeHdc(), hrc); GetClientRect(&m_oldRect); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); if (m_oldRect.bottom) fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom; else // don't divide by zero, not that we should ever run into that... fAspect = 1.0f; fNearPlane = 0.0f; fFarPlane = 100.0f; fMaxObjSize = 3.0f; m_fRadius = fNearPlane + fMaxObjSize / 2.0f; //initialize the panning/zooming cursor start point. startPoint = m_oldRect.CenterPoint(); // initialize rolling matrix with unity glPushMatrix(); glLoadIdentity(); glRotated(-90,0,0,1); glRotated(-60,0,1,0); glScaled(scale, scale, scale); glGetDoublev(GL_MODELVIEW_MATRIX, rotmat); glPopMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); SetViewTransformation(); glMatrixMode(GL_MODELVIEW); // Load character Set // BOOL CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, // int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, // BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, // BYTE nPitchAndFamily, LPCTSTR lpszFacename ); CFont times; times.CreateFont(0,0,0,0, FW_NORMAL,FALSE,FALSE,0,DEFAULT_CHARSET, OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH,"Times New Roman"); // m_pDC->SelectObject(GetStockObject(SYSTEM_FONT)); m_pDC->SelectObject(×); // create the bitmap display lists // we're making images of glyphs 0 thru 255 // the display list numbering starts at 1000, an arbitrary choice wglUseFontBitmaps(m_pDC->GetSafeHdc(), 0, 255, 1000); // display a string: // indicate start of glyph display lists glListBase(1000); // to draw the characters in a string, do, for example: // glCallLists(24, GL_UNSIGNED_BYTE, "Hello Win32 OpenGL World"); }
// Initialize our rendering device int GLDriver::initialize(IWindow* pWindow) { HWND hwnd; Trace("Initializing OpenGL graphics driver"); hwnd = static_cast< HWND > (pWindow->getWindowHandle()); // Create an OpenGL pixel format descriptor PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Format Must Support OpenGL and double buffering PFD_TYPE_RGBA, // Request An RGBA Format pWindow->getBpp(), // 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 }; // Initialise stuff, and check for errors Trace("Acquiring device context"); if (!(hdc = GetDC(hwnd))) CEngine::CriticalError("Unable to create GL device context!"); Trace("Finding pixel format"); if (!(pixelFormat = ChoosePixelFormat(hdc, &pfd))) CEngine::CriticalError("Unable to find a pixel format!"); Trace("Setting pixel format"); if(!SetPixelFormat(hdc, pixelFormat, &pfd)) CEngine::CriticalError("Unable to set the pixel format!"); Trace("Acquiring rendering context"); if(!(hrc = wglCreateContext(hdc))) CEngine::CriticalError("Unable to create GL rendering context!"); Trace("Setting current GL window"); if(!wglMakeCurrent(hdc, hrc)) CEngine::CriticalError("Unable to activate GL rendering context!"); resize(pWindow->getWidth(), pWindow->getHeight()); // Set up initial gl parameters glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glClearColor(0.0,0.0,0.0,0.0); glDepthFunc(GL_LEQUAL); glEnable(GL_TEXTURE_2D); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); // Grab GL vendor information Trace("Getting OpenGL driver info ..."); char* str; str = (char*)glGetString(GL_VENDOR); vendor.assign(str); Trace("OpenGL Vendor: %s", vendor.c_str()); str = (char*)glGetString(GL_RENDERER); renderer.assign(str); Trace("OpenGL Renderer: %s", renderer.c_str()); str = (char*)glGetString(GL_VERSION); version.assign(str); Trace("OpenGL Version: %s", version.c_str()); str = (char*)glGetString(GL_EXTENSIONS); extensions.assign(str); // Replace all spaces with newlines for(int i = 0; i < extensions.length(); ++i) { if(extensions[i] == ' ') extensions[i] = '\n'; } // Acquire pointer to extension functions // Multitexturing glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)wglGetProcAddress("glActiveTextureARB"); glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)wglGetProcAddress("glClientActiveTextureARB"); glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC)wglGetProcAddress("glMultiTexCoord2fARB"); // CVAs glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)wglGetProcAddress("glLockArraysEXT"); glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC)wglGetProcAddress("glUnlockArraysEXT"); glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) wglGetProcAddress("glFogCoordfEXT"); #if 0 glFlushVertexArrayRangeNV = (PFNGLFLUSHVERTEXARRAYRANGENVPROC)wglGetProcAddress("glFlushVertexArrayRangeNV"); glVertexArrayRangeNV = (PFNGLVERTEXARRAYRANGENVPROC)wglGetProcAddress("glVertexArrayRangeNV"); wglAllocateMemoryNV = (PFNWGLALLOCATEMEMORYNVPROC)wglGetProcAddress("wglAllocateMemoryNV"); wglFreeMemoryNV = (PFNWGLFREEMEMORYNVPROC)wglGetProcAddress("wglFreeMemoryNV"); mem = NULL; mem = (unsigned char*)wglAllocateMemoryNV(1024 * 1024 * 5, 0.2f, 0.0f, 0.7f); if(!mem) CEngine::CriticalError("Can't allocate memory"); glVertexArrayRangeNV(1024 * 1024 * 5, mem); glEnableClientState(GL_VERTEX_ARRAY_RANGE_NV); #endif // Set up hardware gamma, if we are using it if(Config::getBoolValue("UseHardwareGamma")) { GetDeviceGammaRamp(hdc, &oldGamma); float gamma = 2.0f; for(int i = 0; i < 3; i++) { for(int j = 0;j < 256; j++) { DWORD d = oldGamma[j][i] * gamma; if(d > 65535) d = 65535; newGamma[j][i] = d; } } SetDeviceGammaRamp(hdc, &newGamma); } // Set up the font HFONT oldfont; fontDispListBase = glGenLists(FONT_DISPLAY_LIST_SIZE); font = CreateFont(-12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Courier New"); oldfont = (HFONT)SelectObject(hdc, font); wglUseFontBitmaps(hdc, 32, FONT_DISPLAY_LIST_SIZE, fontDispListBase); SelectObject(hdc, oldfont); DeleteObject(font); return 0; }
bool WINDOW::Init(char * windowTitle, int newWidth, int newHeight, int newColorBits, int newDepthBits, int newStencilBits, int fullscreenflag) //CREATE WINDOW { WNDCLASS wc; //windows class structure DWORD dwExStyle; //extended style info. DWORD dwStyle; //style info //set class's member variables title=windowTitle; width=newWidth; height=newHeight; colorBits=newColorBits; depthBits=newDepthBits; stencilBits=newStencilBits; //set class's fullscreen flag if(fullscreenflag == FULL_SCREEN) { fullscreen=true; } if(fullscreenflag == WINDOWED_SCREEN) { fullscreen=false; } if(fullscreenflag == CHOOSE_SCREEN) //Ask user if fullscreen { if(MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?","Start FullScreen",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=false; //If answered no } else { fullscreen=true; //if answered yes } } RECT WindowRect; //grab rect. upper left/lower right values WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; hInstance= GetModuleHandle(NULL); //Grab an instance for window wc.style= CS_HREDRAW | CS_VREDRAW | CS_OWNDC; //window style: redraw on move, own DC wc.lpfnWndProc= (WNDPROC) WndProc; //Wndproc handles messages wc.cbClsExtra= 0; wc.cbWndExtra= 0; //no extra window data wc.hInstance= hInstance; //Set the instance wc.hIcon= LoadIcon(NULL, IDI_WINLOGO); //load default icon wc.hCursor= LoadCursor(NULL, IDC_ARROW); //Load arrow cursor wc.hbrBackground=NULL; //No background rqd for GL wc.lpszMenuName=NULL; //No menu wc.lpszClassName="OpenGL"; //set class name if(!RegisterClass(&wc)) //try to register class { errorLog.OutputError("Failed to register the window class"); return FALSE; } else errorLog.OutputSuccess("Window Class Registered"); if(fullscreen) //try to set up fullscreen? { DEVMODE dmScreenSettings; //Device mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); //clear memory dmScreenSettings.dmSize=sizeof(dmScreenSettings); //size of devmode structure dmScreenSettings.dmPelsWidth=width; //selected width dmScreenSettings.dmPelsHeight=height; //selected height dmScreenSettings.dmBitsPerPel=colorBits; //selected bpp dmScreenSettings.dmFields=DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) //try to set mode.CDS_FULLSCREEN removes start bar { //If mode fails, give 2 options, quit or run in window if(MessageBox(NULL, "The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?",title, MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { fullscreen=FALSE; //if "yes", try windowed } else { //tell user program is closing errorLog.OutputError("Program Closed, As Fullscreen Mode Not Supported."); return FALSE; //exit and return FALSE } } } if (fullscreen) //still fullscreen? { dwExStyle=WS_EX_APPWINDOW; //window extended style dwStyle=WS_POPUP | WS_VISIBLE; //window style (no border), visible ShowCursor(FALSE); //hide mouse pointer } else { dwExStyle=WS_EX_CLIENTEDGE; //window extended style(3d look) dwStyle=WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_VISIBLE; //window style (close button, title bar, border, visible) } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); //adjust window to actual requested size, rather than including borders in size. in fullscreen, no effect if(!(hWnd=CreateWindowEx( dwExStyle, //extended style for window "OpenGL", //class name title, //window title WS_CLIPSIBLINGS | //required style WS_CLIPCHILDREN | //required style dwStyle, //Selected style 0, 0, //window position WindowRect.right-WindowRect.left, //calculate adjusted width WindowRect.bottom-WindowRect.top, //calculate adjusted height NULL, // no parent window NULL, //No Menu hInstance, //Instance NULL))) //Dont pass anything to WM_CREATE { Shutdown(); //if not set up, reset display errorLog.OutputError("Window Creation Error."); //pop up error message return FALSE; //return false, to quit program } else errorLog.OutputSuccess("Window Created."); //set up pixel format(openGL supporting, RGBA, correct bits GLuint pixelFormat; //holds result after searching for mode match //calculate alpha bits int alphaBits=0; if(colorBits==32) alphaBits=8; static PIXELFORMATDESCRIPTOR pfd= //pfd tells windows how we want things to be { sizeof(PIXELFORMATDESCRIPTOR), //size of Pixel format descriptor 1, //Version Number PFD_DRAW_TO_WINDOW | //must support window PFD_SUPPORT_OPENGL | //must support opengl PFD_DOUBLEBUFFER, //must support double buffer PFD_TYPE_RGBA, //request RGBA format colorBits, //select colour depth 0, 0, 0, 0, 0, 0, //colour bits ignored alphaBits, //alpha buffer bits 0, //shift bit ignored 0, //no accumulation buffer 0, 0, 0, 0, //accumulation bits ignored depthBits, //z buffer bits stencilBits, //stencil buffer bits 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? { //if not Shutdown(); //Reset display errorLog.OutputError("Can't Create a GL Device context."); return FALSE; //return false, to exit } else errorLog.OutputSuccess("DC Created"); if(!(pixelFormat=ChoosePixelFormat(hDC,&pfd))) //found a matching pixel format? { //if not Shutdown(); errorLog.OutputError("Can't Find a Suitable PixelFormat."); return FALSE; } else errorLog.OutputSuccess("Pixel Format Found."); if(!SetPixelFormat(hDC, pixelFormat,&pfd)) //are we able to set pixel format? { //if not Shutdown(); errorLog.OutputError("Can't set the pixelformat."); return FALSE; } else errorLog.OutputSuccess("Pixel Format set."); if(!(hRC=wglCreateContext(hDC))) //are we able to get rendering context? { //if not Shutdown(); errorLog.OutputError("Can't create a GL rendering context."); return FALSE; } else errorLog.OutputSuccess("GL Rendering Context Created."); if(!MakeCurrent()) //are we able to activate rendering context? { //if not Shutdown(); return FALSE; } else errorLog.OutputSuccess("GL Rendering Context Activated."); //get pixel format parameters static PIXELFORMATDESCRIPTOR finalPfd; DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &finalPfd); //output window parameters errorLog.OutputNewline(); errorLog.OutputSuccess("Window Size: (%d, %d)", width, height); errorLog.OutputSuccess("Color Buffer Bits (R, G, B, A): (%d, %d, %d, %d)", finalPfd.cRedBits, finalPfd.cGreenBits, finalPfd.cBlueBits, finalPfd.cAlphaBits); errorLog.OutputSuccess("Depth Buffer Bits: %d", finalPfd.cDepthBits); errorLog.OutputSuccess("Stencil Buffer Bits: %d", finalPfd.cStencilBits); errorLog.OutputNewline(); ShowWindow(hWnd,SW_SHOW); //show window SetForegroundWindow(hWnd); //slightly higher priority SetFocus(hWnd); //Set keyboard focus to the window errorLog.OutputSuccess("Window Created!"); errorLog.OutputNewline(); //Init the font HFONT font; //windows font ID //create 96 display lists base = glGenLists(96); font = CreateFont( -18, //font height 0, //default width 0, 0, //angles - escapement, orientation FW_BOLD, //font weight, 0-1000, NORMAL, BOLD false, //italic false, //underline false, //strikeout ANSI_CHARSET, //character set OUT_TT_PRECIS, //precision CLIP_DEFAULT_PRECIS, //clip precision ANTIALIASED_QUALITY, //output quality FF_DONTCARE | DEFAULT_PITCH,//family and pitch "Courier New"); //font name //select the font SelectObject(hDC, font); //create 96 display lists, starting at 32 wglUseFontBitmaps(hDC, 32, 96, base); errorLog.OutputSuccess("Font created successfully."); return TRUE; //success! }
int InitENstring() { lists = glGenLists(MAX_CHAR); wglUseFontBitmaps(wglGetCurrentDC(), 0, MAX_CHAR, lists); return TRUE; }
LRESULT CMainFrame::OnPostInit(WPARAM w,LPARAM l) { Ptz = (CZ_ed2View *)m_wndSplitter.GetPane(0,1); Ptx = (CZ_ed2View *)m_wndSplitter.GetPane(1,0); Pty = (CZ_ed2View *)m_wndSplitter.GetPane(1,1); PT3 = (z_ed3View *)m_wndSplitter.GetPane(0,0); if(0 == Ptz) { PostMessage(WM_POSTINIT,0,0); } b_viewsup = 1; wglShareLists(PT3->m_hRC, Ptz->m_hRC); wglShareLists(PT3->m_hRC, Ptx->m_hRC ); wglShareLists(PT3->m_hRC, Pty->m_hRC ); m_Gl.CreateWnd(this, 0); // this shares the list inside TexRef::Clear(1); BYTE wLmap[4] = {255,255,255,255}; MakeCurrent('3'); BYTE dBits[] = { 255,192,192, 128,255,235, 209,209,255, 255,235,235, 255,192,192, 235,255,235, 209,209,255, 235,128,235, 255,128,192, 235,128,235, 209,209,255, 235,235,255, 255,192,192, 235,255,235, 209,209,128, 255,235,235}; _dumptex = TexRef::GlGenTex( 4, 4, 3 , dBits,0); /* BYTE dBitsSel[4*4*3]; memset(dBitsSel,192, 4*4*3); dBitsSel[0]=255; dBitsSel[1]=255; dBitsSel[2]=255; dBitsSel[9]=255; dBitsSel[10]=255; dBitsSel[11]=255; dBitsSel[36]=255; dBitsSel[37]=255; dBitsSel[38]=255; dBitsSel[47]=255; dBitsSel[46]=255; dBitsSel[45]=255; */ BYTE dBitsSel[32*32*3]; int line = 0; int g = 0; for(int x=0;x<32;x++) { for(int y=0;y<32;y++) { if( (((x%4)+(y%4))%2)==0 ) { dBitsSel[g++]=128; dBitsSel[g++]=128; dBitsSel[g++]=128; } else { dBitsSel[g++]=0; dBitsSel[g++]=0; dBitsSel[g++]=0; } } } _selTex = TexRef::GlGenTex( 32, 32, 3 , dBitsSel,GEN_TEX_MM_LINEAR); _sndtex = TexRef::LoadRCTexture("-IDR_SCE_SOUND", 128,128); _lbulbtex = TexRef::LoadRCTexture("-IDR_SCE_LBULB", 128,128); _itmqtex = TexRef::LoadRCTexture("-ITM_CUSTOM", 128,128); _tbtex = TexRef::LoadRCTexture("-IDR_GLTBAR",256,32); _startPosTex = TexRef::LoadRCTexture("-ITM_STARTPOS",32,32); _wLmap = TexRef::GlGenTex( 1, 1, 3 , wLmap, 0); _ambLmap = DOC()->RecreateAmbLmap(); TexRef::_defTex = _dumptex; m_Gl.InitialUpdate(); // char* pext = (char*)glGetString(GL_VERSION); _font1 = glGenLists(96); _hf = CreateFont(-11, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Arial" ); SelectObject(Ptz->_hdc, _hf); SelectObject(Ptx->_hdc, _hf); SelectObject(Pty->_hdc, _hf); wglUseFontBitmaps(Ptz->_hdc, 32, 96, _font1); wglUseFontBitmaps(Ptx->_hdc, 32, 96, _font1); wglUseFontBitmaps(Pty->_hdc, 32, 96, _font1); DOC()->Invalidate(1); BARDLG()->SendMessage(WM_POSTINIT,0,0); if(!IsValidUL(0)) PostMessage(WM_GOTOZALSOFT); return TRUE; }