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

📄 font.cpp

📁 有个小游戏
💻 CPP
字号:
#define WIN32_MEAN_AND_LEAN
#define WIN32_EXTRA_LEAN

#include "stdafx.h"

#include "font.h"

#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <gl/gl.h>

CFont::CFont()
{
	screenX = 0;
	screenY = 0;
	xpos = 0.0;
	ypos = 0.0;
	zpos = 0.0;
}

CFont::CFont(char *name, int size)
{
	screenX = 0;
	screenY = 0;
	xpos = 0.0;
	ypos = 0.0;
	zpos = 0.0;
	Build(name, size);
}

CFont::~CFont()
{
	glDeleteLists(callList, 96);
}

void CFont::Build(char *name, int size)
{
	HFONT hFont;	// font ID
	HDC hDC;		// device context

	hDC = wglGetCurrentDC();
	callList = glGenLists(96);

	if (stricmp(name, "symbol") == 0)
	{
		hFont = CreateFont(-size, 0,0,0,FW_BOLD, FALSE, FALSE, FALSE, SYMBOL_CHARSET,
						OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
						FF_DONTCARE | DEFAULT_PITCH, name);
	}
	else
	{
		hFont = CreateFont(-size, 0,0,0,FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
					OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, 
					FF_DONTCARE | DEFAULT_PITCH, name);
	}

	SelectObject(hDC, hFont);
	wglUseFontBitmaps(hDC, 32, 96, callList);
}

void CFont::Print(const char *str, ...)
{
	char text[256];
	va_list args;

	if (str == NULL)
		return;

	va_start(args, str);
		vsprintf(text, str, args);
	va_end(args);

	glPushMatrix();
	glColor4f(r, g, b, a);
	glLoadIdentity();
	glTranslatef(0.0f, 0.0f, -1.0f);	// translate one unit into the screen
	if (xpos == 0.0 && ypos == 0.0 && zpos == 0.0)
		glRasterPos2i(screenX, screenY);
	else
		glRasterPos3f(xpos, ypos, zpos);

	glPushAttrib(GL_LIST_BIT);
		glListBase(callList - 32);
		glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
	glPopAttrib();
	glPopMatrix();
}

void CFont::ClearFont()
{
	glDeleteLists(callList, 96);
}

⌨️ 快捷键说明

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