Skip to content

Commit 5c5a6e5

Browse files
authored
Merge pull request #2 from Sommos/revert-1-master
Revert "Directory Fix / Visual Studio Conversion"
2 parents 7052cef + e23b72b commit 5c5a6e5

192 files changed

Lines changed: 382 additions & 63574 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 28 additions & 394 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,46 @@
1-
#include "Application.h"
2-
3-
Application::Application()
4-
{
5-
// push an instance of the "Playing" state onto the stack of game states
6-
pushState(std::make_unique<State::Playing>(*this));
7-
}
8-
9-
void Application::runMainGameLoop()
10-
{
11-
while (Display::isOpen())
12-
{
13-
Display::clear();
14-
m_states.top()->input();
15-
m_states.top()->update();
16-
m_states.top()->draw();
17-
Display::update();
18-
Display::checkForClose();
19-
}
20-
}
21-
22-
void Application::pushState(std::unique_ptr<State::Game_State> state)
23-
{
24-
// move the ownership of the state object into the stack of game states
25-
m_states.push(std::move(state));
26-
}
27-
28-
void Application::popState()
29-
{
30-
// remove the top game state from the stack
31-
m_states.pop();
32-
}
1+
#include "Application.h"
2+
#include "Display.h"
3+
#include "States/Playing.h"
4+
5+
Application::Application()
6+
{
7+
// push an instance of the "Playing" state onto the stack of game states
8+
pushState(std::make_unique<State::Playing>(*this));
9+
}
10+
11+
// the main game loop
12+
void Application::runMainGameLoop()
13+
{
14+
// loop until the display is closed
15+
while (Display::isOpen())
16+
{
17+
// clear the display
18+
Display::clear();
19+
20+
// handle input for the current state
21+
m_states.top()->input();
22+
// update the current state
23+
m_states.top()->update();
24+
// draw the current state
25+
m_states.top()->draw();
26+
27+
// update the display
28+
Display::update();
29+
// check if the display should be closed
30+
Display::checkForClose();
31+
}
32+
}
33+
34+
// push a new game state onto the stack
35+
void Application::pushState(std::unique_ptr<State::Game_State> state)
36+
{
37+
// move the ownership of the state object into the stack of game states
38+
m_states.push(std::move(state));
39+
}
40+
41+
// pop the top game state from the stack
42+
void Application::popState()
43+
{
44+
// remove the top game state from the stack
45+
m_states.pop();
46+
}
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
#ifndef APPLICATION_H_INCLUDED
2-
#define APPLICATION_H_INCLUDED
3-
4-
#include <stack>
5-
#include <memory>
6-
#include "Display.h"
7-
#include "States/Playing.h"
8-
#include "States/Game_State.h"
9-
10-
class Application
11-
{
12-
public:
13-
Application();
14-
void runMainGameLoop();
15-
void pushState(std::unique_ptr<State::Game_State> state);
16-
void popState();
17-
private:
18-
std::stack<std::unique_ptr<State::Game_State>> m_states;
19-
};
20-
#endif
1+
#ifndef APPLICATION_H_INCLUDED
2+
#define APPLICATION_H_INCLUDED
3+
4+
#include <stack>
5+
#include <memory>
6+
7+
#include "States/Game_State.h"
8+
9+
class Application
10+
{
11+
public:
12+
Application();
13+
14+
void runMainGameLoop();
15+
16+
void pushState(std::unique_ptr<State::Game_State> state);
17+
void popState();
18+
19+
private:
20+
std::stack<std::unique_ptr<State::Game_State>> m_states;
21+
};
22+
23+
#endif // APPLICATION_H_INCLUDED

Display.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "Display.h"
2+
#include <memory>
3+
#include <SFML/Graphics.hpp>
4+
#include <GL/glew.h>
5+
6+
namespace Display
7+
{
8+
// width and height variables for the current window
9+
constexpr static int WIDTH = 1280;
10+
constexpr static int HEIGHT = 720;
11+
12+
// pointer for RenderWindow object
13+
std::unique_ptr<sf::RenderWindow> window;
14+
15+
// initialize the display
16+
void init()
17+
{
18+
// configure the context settings for OpenGL
19+
sf::ContextSettings settings;
20+
settings.depthBits = 24;
21+
settings.majorVersion = 3;
22+
settings.minorVersion = 3; // OpenGL 3.3
23+
24+
// create the SFML window with the specified width, height, title, style, and settings
25+
window = std::make_unique<sf::RenderWindow>(sf::VideoMode(WIDTH, HEIGHT), "Window", sf::Style::Close, settings);
26+
27+
// initialize GLEW
28+
glewInit();
29+
30+
// set the viewport to cover the entire window
31+
glViewport(0, 0, WIDTH, HEIGHT);
32+
}
33+
34+
// close the display window
35+
void close()
36+
{
37+
window->close();
38+
}
39+
40+
// clear the display window with a specified color
41+
void clear()
42+
{
43+
// set the clear color to black
44+
glClearColor(0.0, 0.0, 0.0, 1.0);
45+
// clear the depth and color buffers
46+
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
47+
}
48+
49+
// update the display window
50+
void update()
51+
{
52+
window->display();
53+
}
54+
55+
// check if the display window should be closed
56+
void checkForClose()
57+
{
58+
sf::Event e;
59+
while (window->pollEvent(e))
60+
{
61+
if (e.type == sf::Event::Closed)
62+
{
63+
close();
64+
}
65+
}
66+
}
67+
68+
// check if the display window is open
69+
bool isOpen()
70+
{
71+
return window->isOpen();
72+
}
73+
}

Display.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef DISPLAY_H_INCLUDED
2+
#define DISPLAY_H_INCLUDED
3+
4+
namespace Display
5+
{
6+
void init();
7+
void close();
8+
9+
void clear();
10+
void update();
11+
12+
void checkForClose();
13+
14+
bool isOpen();
15+
}
16+
#endif // DISPLAY_H_INCLUDED
Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,57 @@
1-
#include "Model.h"
2-
3-
Model::Model(const std::vector<GLfloat>& vertexPositions)
4-
{
5-
glGenVertexArrays(1, &m_vao);
6-
glBindVertexArray(m_vao);
7-
addVBO(2, vertexPositions);
8-
9-
glBindVertexArray(0);
10-
glBindBuffer(GL_ARRAY_BUFFER, 0);
11-
}
12-
13-
Model::~Model()
14-
{
15-
glDeleteVertexArrays(1, &m_vao);
16-
glDeleteBuffers(m_buffers.size(), m_buffers.data());
17-
}
18-
19-
void Model::bind()
20-
{
21-
glBindVertexArray(m_vao);
22-
}
23-
24-
void Model::unbind()
25-
{
26-
glBindVertexArray(0);
27-
}
28-
29-
void Model::addVBO(int dim, const std::vector<GLfloat>& data)
30-
{
31-
GLuint vbo;
32-
glGenBuffers(1, &vbo);
33-
glBindBuffer(GL_ARRAY_BUFFER, vbo);
34-
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(data[0]), data.data(), GL_STATIC_DRAW);
35-
glVertexAttribPointer(m_vboCount, dim, GL_FLOAT, GL_FALSE, 0, (GLvoid*) 0);
36-
glEnableVertexAttribArray(m_vboCount++);
37-
m_buffers.push_back(vbo);
38-
}
1+
#include "Model.h"
2+
3+
Model::Model(const std::vector<GLfloat>& vertexPositions)
4+
{
5+
// generate a vertex array object (VAO)
6+
glGenVertexArrays(1, &m_vao);
7+
// bind the VAO
8+
glBindVertexArray(m_vao);
9+
10+
// add a vertex buffer object (VBO) for the vertex positions
11+
addVBO(2, vertexPositions);
12+
13+
// unbind the VAO
14+
glBindVertexArray(0);
15+
// unbind the buffer
16+
glBindBuffer(GL_ARRAY_BUFFER, 0);
17+
}
18+
19+
Model::~Model()
20+
{
21+
// delete the VAO
22+
glDeleteVertexArrays(1, &m_vao);
23+
24+
// delete the VBOs
25+
glDeleteBuffers(m_buffers.size(), m_buffers.data());
26+
}
27+
28+
void Model::bind()
29+
{
30+
// bind the VAO for rendering
31+
glBindVertexArray(m_vao);
32+
}
33+
34+
void Model::unbind()
35+
{
36+
// unbind the VAO
37+
glBindVertexArray(0);
38+
}
39+
40+
void Model::addVBO(int dim, const std::vector<GLfloat>& data)
41+
{
42+
GLuint vbo;
43+
// generate a VBO
44+
glGenBuffers(1, &vbo);
45+
// bind the VBO
46+
glBindBuffer(GL_ARRAY_BUFFER, vbo);
47+
// copy the data to the VBO
48+
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(data[0]), data.data(), GL_STATIC_DRAW);
49+
50+
// specify the layout of the vertex attribute
51+
glVertexAttribPointer(m_vboCount, dim, GL_FLOAT, GL_FALSE, 0, (GLvoid*) 0);
52+
// enable the vertex attribute
53+
glEnableVertexAttribArray(m_vboCount++);
54+
55+
// store the VBO in the list of buffers
56+
m_buffers.push_back(vbo);
57+
}
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
#ifndef MODEL_H_INCLUDED
2-
#define MODEL_H_INCLUDED
3-
4-
#include <GL/glew.h>
5-
#include <vector>
6-
7-
class Model
8-
{
9-
public:
10-
Model(const std::vector<GLfloat>& vertexPositions);
11-
~Model();
12-
13-
void bind();
14-
void unbind();
15-
16-
private:
17-
void addVBO(int dim, const std::vector<GLfloat>& data);
18-
std::vector<GLuint> m_buffers;
19-
GLuint m_vao = 0;
20-
GLuint m_vboCount = 0;
21-
};
22-
#endif
1+
#ifndef MODEL_H_INCLUDED
2+
#define MODEL_H_INCLUDED
3+
4+
#include <GL/glew.h>
5+
6+
#include <vector>
7+
8+
class Model
9+
{
10+
public:
11+
Model(const std::vector<GLfloat>& vertexPositions);
12+
~Model();
13+
14+
void bind();
15+
void unbind();
16+
private:
17+
void addVBO(int dim, const std::vector<GLfloat>& data);
18+
19+
std::vector<GLuint> m_buffers;
20+
GLuint m_vao = 0;
21+
22+
GLuint m_vboCount = 0;
23+
};
24+
25+
#endif // MODEL_H_INCLUDED

0 commit comments

Comments
 (0)