⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.cpp

📁 基于引擎基础上开发的三维游戏实例“恐怖之战”游戏者可以自爱三维地形上漫游
💻 CPP
字号:
// 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);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -