Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
UTILITY.CPP
Package: openglsystem.rar [view]
Upload User: nthssl
Upload Date: 2022-04-05
Package Size: 25357k
Code Size: 2k
Category:
OpenCV
Development Platform:
Visual C++
- // Utility.cpp: implementation of the CUtility class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MyGame.h"
- #include "Utility.h"
- #include "string.h"
- #include <stdio.h>
- #include <stdarg.h>
- #include <assert.h>
- #include <math.h>
- #include "utility.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CUtility::CUtility()
- {
- }
- CUtility::~CUtility()
- {
- }
- void CUtility::PrintString(void *font, char *string)
- {
- int len,i;
- len=(int)strlen(string);
- for(i=0;i<len;i++)
- glutBitmapCharacter(font,string[i]);
- }
- void CUtility::glPrintf(int ScreenW,int ScreenH,GLuint x, GLuint y, int align, GLfloat scale, char* format, ...)
- {
- va_list args;
- char buffer[255], *p;
- int len;
- float dx=0;
- GLfloat font_scale = 119.05f;
- va_start(args, format);
- vsprintf(buffer, format, args);
- va_end(args);
- if(align)
- {
- len=strlen(buffer);
- dx=((scale*len)/2)*104.76/119.05;
- }
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D(0,ScreenW,0,ScreenH);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_LIGHTING);
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glTranslatef(x-dx, y, 0.0);
- glScalef(scale/font_scale, scale/font_scale, scale/font_scale);
- for(p = buffer; *p; p++)
- glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, *p);
- glPopAttrib();
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- }
- float CUtility::FPS(int LastFrameTime)
- {
- static int LastTimes[10]={0,0,0,0,0,0,0,0,0,0};
- static int c=0;
- int i;
- float average=0;
- c=(c+1)%10;
- LastTimes[c]=LastFrameTime;
- for(i=0;i<10;i++)
- average+=LastTimes[i];
- return 1000.0/(average/10.0);
- }