📄 gui.cpp
字号:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "../global.h"
#include "gui.h"
////////////////////////////////////////////////////////////////////////////
GcGui::GcGui()
{
// Build the font for text output
}
////////////////////////////////////////////////////////////////////////////
GcGui::~GcGui()
{
// Destruct the GUI
}
////////////////////////////////////////////////////////////////////////////
void GcGui::Begin()
{
/* Make the scene ready for 2D rendering */
// Disable depth testing
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
// Select the projection matrix
glMatrixMode(GL_PROJECTION);
// Save the current matrix
glPushMatrix();
// Load a default matrix
glLoadIdentity();
// Change mode to 2D drawing
glOrtho(0, GcSettings::ScreenWidth(), 0, GcSettings::ScreenHeight(), -1, 1);
// Load the modelview matrix
glMatrixMode(GL_MODELVIEW);
// Save the old modelview matrix
glPushMatrix();
// Load the default modelview matrix
glLoadIdentity();
// The Pop matrix commands will come in End() and will restore the old matrixs
}
////////////////////////////////////////////////////////////////////////////
void GcGui::End()
{
/* Restore the scene for 3D rendering */
// Restor the old modelview matrix
glPopMatrix();
// Select the projection matrix
glMatrixMode(GL_PROJECTION);
// Restore the old projection matrix
glPopMatrix();
// Cange back to the modelview matrix
glMatrixMode(GL_MODELVIEW);
// Enable depth testing
glEnable(GL_DEPTH_TEST);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
////////////////////////////////////////////////////////////////////////////
bool GcGui::Load(GcTexture *land, uint mapWidth)
{
// Build the font for printing
if(!font.Build("data/font.tga", 16, 16, 32, 32, 32))
{
MessageBox(NULL, "Unable to build the font.", "ERROR", MB_OK);
return false;
}
// Load the sprite for the crosshair
if(!aim.Load("data/aim.tga", 128, 128))
{
MessageBox(NULL, "Unable to load the crosshair.", "ERROR", MB_OK);
return false;
}
// Load the sprite for the HUD
if(!hud.Load("data/hud.tga", 256, 256))
{
MessageBox(NULL, "Unable to load the HUD.", "ERROR", MB_OK);
return false;
}
map.Load(land, mapWidth, GcSettings::Scale());
return true;
}
////////////////////////////////////////////////////////////////////////////
void GcGui::Draw(float x, float y)
{
map.Draw(x, y);
/*
// Draw the crosshair
aim.Draw(GcSettings::ScreenWidth() / 2.0f, GcSettings::ScreenHeight() / 2.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_COLOR);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f, 1.0f, 1.0f, 0.6f);
// Draw the HUD
hud.Draw(140, 140);
glDisable(GL_BLEND);
font.Print("Destroy", 95, 200);
font.Print("the Rockza base", 55, 174);
font.Print("Rescue POVs", 75, 140);
*/
}
////////////////////////////////////////////////////////////////////////////
void GcGui::Print(char *string, int x, int y)
{
font.Print(string, x, y);
}
////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -