OpenGL에서 3 개의 큰 상자와 1 개의 작은 상자가있는 게임을 작성하고 있습니다. 작은 상자는 큰 상자 중 하나에 숨겨져 있으며 사용자는 A, B 또는 C를 눌러 작은 상자의 위치를 표시해야합니다. 사용자가 얼마나 많은 추측을했는지, 진행 한 라운드 수를 추적하고 싶지만 OpenGL에서 증가 된 숫자를 출력하는 방법에 대해서는 잘 모릅니다. 숫자에 관련된 것이 생길 때마다 숫자를 증가시키고 싶지만, 알아낼 수는 없습니다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까? 정말 고맙습니다!OpenGL에서 변수 번호를 출력하는 방법은 무엇입니까?
MAIN.CPP :
#include "Box.h"
#include "Font.h"
#include "Camera.h"
#include "Time.h"
#include <vector>
using namespace std;
#include "vgl.h"
using namespace glm;
#define SPACEBAR_KEY 32
#define ESCAPE_KEY 033
vector<Box * > boxes;
Camera* camera;
Font* font;
int numGenerator, guesses, totalGuesses, rounds, averageGuesses;
bool win;
void closeApp()
{
delete camera;
delete font;
for (auto it = boxes.begin(); it != boxes.end(); ++it)
delete (*it);
}
void startNewGame()
{
rounds++;
win = false;
guesses = 0;
numGenerator = rand() % 3;
boxes[1]->Visible = true;
boxes[2]->Visible = true;
boxes[3]->Visible = true;
if (numGenerator == 0)
{
boxes[0]->Position = vec3(0.0f, -3.0f, 0.0f);
}
else if (numGenerator == 1)
{
boxes[0]->Position = vec3(0.0f, 0.0f, 0.0f);
}
else
{
boxes[0]->Position = vec3(0.0f, 3.0f, 0.0f);
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case ESCAPE_KEY: // ASCII Escape Key Code
closeApp();
exit(EXIT_SUCCESS);
break;
case 'a':
boxes[1]->Visible = false;
if (boxes[0]->Position != vec3(0.0f, -3.0f, 0.0f))
{
guesses++;
totalGuesses++;
}
else
{
win = true;
}
glutPostRedisplay();
break;
case 'b':
boxes[2]->Visible = false;
if (boxes[0]->Position != vec3(0.0f, 0.0f, 0.0f))
{
guesses++;
totalGuesses++;
}
else
{
win = true;
}
glutPostRedisplay();
break;
case 'c':
boxes[3]->Visible = false;
if (boxes[0]->Position != vec3(0.0f, 3.0f, 0.0f))
{
guesses++;
totalGuesses++;
}
else
{
win = true;
}
glutPostRedisplay();
break;
case 'r':
startNewGame();
glutPostRedisplay();
break;
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
font->printText("Guessing Game!", 260, 500, 20);
font->printText("Press 1, 2, or 3 to make one of the boxes disappear!", 10, 480, 15);
font->printText("Try to find the small cube! Press 'r' to restart!", 30, 460, 15);
if (win)
{
font->printText("You win!", 20, 200, 30);
}
font->printText("Guesses: ", 20, 350, 15);
font->printText("Rounds played: ", 20, 330, 15);
font->printText("Total guesses: ", 20, 310, 15);
font->printText("Average guesses: ", 20, 290, 15);
boxes[0]->Draw(camera->ProjectionMatrix, camera->ViewMatrix);
boxes[1]->Draw(camera->ProjectionMatrix, camera->ViewMatrix);
boxes[2]->Draw(camera->ProjectionMatrix, camera->ViewMatrix);
boxes[3]->Draw(camera->ProjectionMatrix, camera->ViewMatrix);
glutSwapBuffers();
}
void init()
{
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
srand(time(NULL));
font = new Font();
camera = new Camera();
camera->ViewMatrix = glm::lookAt(glm::vec3(0, 0, 20), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
VertexBufferData vertexBufferData = VertexBufferData("Data\\Models\\Objects.xml");
boxes.push_back(new Box(vertexBufferData, glm::vec3(0.0f, 0.0f, 0.0f), "data/images/wood.bmp", "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader", vec3(0.4f, 0.4f, 0.4f), true));
boxes.push_back(new Box(vertexBufferData, glm::vec3(0.0f, -3.0f, 0.0f), "data/images/ground.tga", "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader", vec3(1.0f, 1.0f, 1.0f), true));
boxes.push_back(new Box(vertexBufferData,glm::vec3(0.0f, 0.0f, 0.0f), "data/images/metal.bmp", "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader", vec3(1.0f, 1.0f, 1.0f), true));
boxes.push_back(new Box(vertexBufferData, glm::vec3(0.0f, 3.0f, 0.0f), "data/images/brick.bmp", "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader", vec3(1.0f, 1.0f, 1.0f), true));
startNewGame();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(1024, 768);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutCreateWindow("Satterwhite_Project_5");
if (glewInit())
{
cerr << "Unable to init glew" << endl;
exit(EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}