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

📄 font.h

📁 小游戏 有碰撞检测和音乐 使用键盘openal
💻 H
字号:
#pragma once
#include "engine.h"

GLuint base;
TextureImage fontTextures [ 1 ];
void ShutdownFont()
{
	glDeleteLists(base,256);
}	

void BuildFont() // build font display list
{
	LoadTGA( &fontTextures[ 0 ], "images/font.tga" );
	base = glGenLists(256); // create 256 display lists
	glBindTexture(GL_TEXTURE_2D, fontTextures[0].id); // set font texture
	for (int loop1=0; loop1<256; loop1++) // loop through 256 lists
	{
		float cx=float(loop1%16)/16.0f; // x position of current character
		float cy=float(loop1/16)/16.0f; // y position of current character
		glNewList(base+loop1,GL_COMPILE); // start building a list
		glBegin(GL_QUADS); // quad for each character
		glTexCoord2f(cx,1.0f-cy-0.0625f);// texture coord (bottom left)
		glVertex2d(0,16);// vertex coord (bottom left)
		glTexCoord2f(cx+0.0625f,1.0f-cy-0.0625f); // texture coord (bottom right)
		glVertex2i(16,16); // vertex coord (bottom right)
		glTexCoord2f(cx+0.0625f,1.0f-cy-0.001f); // texture coord (top right)
		glVertex2i(16,0); // vertex coord (top right)
		glTexCoord2f(cx,1.0f-cy-0.001f); // texture coord (top left)
		glVertex2i(0,0); // vertex coord (top left)
		glEnd(); // end building quad character
		glTranslated(13,0,0); // move to right of character
		glEndList(); // end building display list
	}
}
void PrintList(int x, GLint y, int set, const char *fmt, float scale = 0.85f)
// where printing happens
{
	char text[1024]; // Holds Our String
	va_list ap; // Pointer To List Of Arguments
	if (fmt == NULL) // If There's No Text
	return;
	// Do Nothing
	va_start(ap, fmt); // Parses The String For Variables
	vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
	va_end(ap); // Results Are Stored In Text
	if (set>1) // Did User Choose An Invalid Character Set?
	set=1; // If So, Select Set 1 (Italic)
	glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
	glLoadIdentity(); // Reset The Modelview Matrix
	glTranslated(x,y,0); // Position The Text (0,0 - Top Left)
	glListBase(base-32+(128*set)); // Choose The Font Set (0 or 1)
	glScalef(scale,scale,1.0f); // Make The Text 2X Taller
	glCallLists(strlen(text),GL_UNSIGNED_BYTE, text);// Write The Text To The Screen
	glDisable(GL_TEXTURE_2D); // Disable Texture Mapping
}

⌨️ 快捷键说明

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