summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/graphics/AssetManager.cpp (renamed from code/graphics/AssetManager.cpp)2
-rw-r--r--src/graphics/AssetManager.hpp (renamed from graphics/AssetManager.hpp)2
-rw-r--r--src/graphics/Camera3D.cpp (renamed from code/graphics/Camera3D.cpp)0
-rw-r--r--src/graphics/Camera3D.hpp (renamed from code/graphics/Camera3D.hpp)0
-rw-r--r--src/graphics/Display.cpp (renamed from graphics/Display.cpp)261
-rw-r--r--src/graphics/Display.hpp (renamed from code/graphics/Display.hpp)4
-rw-r--r--src/graphics/Shader.cpp (renamed from code/graphics/Shader.cpp)0
-rw-r--r--src/graphics/Shader.hpp (renamed from code/graphics/Shader.hpp)0
-rw-r--r--src/graphics/Texture.cpp (renamed from code/graphics/Texture.cpp)0
-rw-r--r--src/graphics/Texture.hpp (renamed from code/graphics/Texture.hpp)0
10 files changed, 174 insertions, 95 deletions
diff --git a/code/graphics/AssetManager.cpp b/src/graphics/AssetManager.cpp
index 1840c63..f2f756d 100644
--- a/code/graphics/AssetManager.cpp
+++ b/src/graphics/AssetManager.cpp
@@ -4,7 +4,6 @@ const std::string pathToAssets = "./assets/";
const std::string pathToObjects = pathToAssets + "objects/";
const std::string pathToIndexFile = pathToAssets + "indexes/1.11.json";
const std::string pathToAssetsMc = "./assetsMc/";
-
const std::map<Asset::AssetType, std::string> assetTypeFileExtensions{
std::make_pair(Asset::AssetType::Texture, ".png"),
std::make_pair(Asset::AssetType::Lang, ".lang"),
@@ -12,6 +11,7 @@ const std::map<Asset::AssetType, std::string> assetTypeFileExtensions{
};
AssetManager::AssetManager() {
+ return;
std::ifstream indexFile(pathToIndexFile);
if (!indexFile) {
std::cerr << "Can't open file " << pathToIndexFile << std::endl;
diff --git a/graphics/AssetManager.hpp b/src/graphics/AssetManager.hpp
index c7ef81a..e723398 100644
--- a/graphics/AssetManager.hpp
+++ b/src/graphics/AssetManager.hpp
@@ -3,7 +3,7 @@
#include <fstream>
#include <string>
#include <map>
-#include "../json.hpp"
+#include <nlohmann/json.hpp>
#include "Texture.hpp"
struct Asset {
diff --git a/code/graphics/Camera3D.cpp b/src/graphics/Camera3D.cpp
index eb740e4..eb740e4 100644
--- a/code/graphics/Camera3D.cpp
+++ b/src/graphics/Camera3D.cpp
diff --git a/code/graphics/Camera3D.hpp b/src/graphics/Camera3D.hpp
index eac1f47..eac1f47 100644
--- a/code/graphics/Camera3D.hpp
+++ b/src/graphics/Camera3D.hpp
diff --git a/graphics/Display.cpp b/src/graphics/Display.cpp
index ff2d6a6..80bf524 100644
--- a/graphics/Display.cpp
+++ b/src/graphics/Display.cpp
@@ -2,6 +2,127 @@
#include "Display.hpp"
#include "AssetManager.hpp"
+/*GLfloat vertices[] = {
+ -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
+ 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
+ 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
+ -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
+
+ -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
+ -0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
+
+ -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
+ -0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
+ -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
+ -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
+
+ 0.5f, 0.5f, 0.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 1.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 0.0f,
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+
+ 0.0f, 1.0f,
+ 1.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 0.0f,
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+};
+GLfloat vertices[] = {
+ -1.0f, -1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, 1.0f,
+ -1.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+};
+GLuint indices[] = {
+ 5, 4, 6, //Z+ edge
+ 5, 6, 7,
+
+ 0, 1, 2, //Z- edge
+ 2, 1, 3,
+
+ 0, 4, 1, //X+ edge
+ 1, 4, 5,
+
+ 6, 2, 3, //X- edge
+ 6, 3, 7,
+
+ 3, 1, 5, //Y+ edge
+ 3, 5, 7,
+
+ 0, 2, 4, //Y- edge
+ 4, 2, 6,
+};
+
Display::Display(unsigned int winWidth, unsigned int winHeight, const char *winTitle, World *worldPtr) : world(
worldPtr) {
sf::ContextSettings contextSetting;
@@ -22,6 +143,9 @@ Display::Display(unsigned int winWidth, unsigned int winHeight, const char *winT
}
glViewport(0, 0, width(), height());
glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ glFrontFace(GL_CCW);
}
bool Display::IsClosed() {
@@ -29,21 +153,21 @@ bool Display::IsClosed() {
}
void Display::SetPlayerPos(double playerX, double playerY, double playerZ) {
- camera.Position = glm::vec3(playerX, playerY, playerZ);
+ //camera.Position = glm::vec3(playerX, playerY, playerZ);
+ toRender.clear();
const float ChunkDistance = 1;
- PositionI playerChunk = PositionI((int) playerX / 16, (int) playerZ / 16, (int) playerY / 16);
- /*std::cout << "Player chunk position: " << playerChunk.GetX() << " "
- << playerChunk.GetZ() << " " << playerChunk.GetY() << std::endl;*/
+ Vector playerChunk = Vector(floor(playerX / 16.0f), floor(playerY / 16.0f), floor(playerZ / 16.0f));
for (auto &it:world->m_sections) {
- PositionI chunkPosition = it.first;
- PositionI delta = chunkPosition - playerChunk;
+ Vector chunkPosition = it.first;
+ Vector delta = chunkPosition - playerChunk;
+ //std::cout << delta.GetDistance() << std::endl;
if (delta.GetDistance() > ChunkDistance)
continue;
/*std::cout << "Rendering " << delta.GetDistance() << " Detailed: " << delta.GetX() << " " << delta.GetZ() << " "
<< delta.GetY() << std::endl <<
"\t" << chunkPosition.GetX() << " " << chunkPosition.GetZ() << " "
<< chunkPosition.GetY() << std::endl;*/
- toRender.push_back(it.first);
+ toRender.push_back(chunkPosition);
}
std::cout << "Chunks to render: " << toRender.size() << std::endl;
}
@@ -51,69 +175,26 @@ void Display::SetPlayerPos(double playerX, double playerY, double playerZ) {
void Display::MainLoop() {
Shader shader("./shaders/simple.vs", "./shaders/simple.fs");
- GLfloat vertices[] = {
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
- 0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
- -0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-
- -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- 0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
- -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
- -0.5f, 0.5f, -0.5f, 0.0f, 1.0f
- };
- GLuint indices[] = {
- 0, 1, 2,
- 0, 2, 3
- };
- GLuint VBO, VAO, EBO;
+ GLuint VBO, VAO, EBO, VBO2;
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
+ glGenBuffers(1, &VBO2);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
{
+ glBindBuffer(GL_ARRAY_BUFFER, VBO2);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(uv_coords), uv_coords, GL_STATIC_DRAW);
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), 0);
+ glEnableVertexAttribArray(2);
+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
+ glEnableVertexAttribArray(0);
+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
-
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid *) (3 * sizeof(GLfloat)));
- glEnableVertexAttribArray(2);
}
glBindVertexArray(0);
@@ -121,6 +202,8 @@ void Display::MainLoop() {
bool captureMouse = true;
+ //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
bool isRunning = true;
while (isRunning) {
static sf::Clock clock, clock1;
@@ -128,6 +211,11 @@ void Display::MainLoop() {
float absTime = clock1.getElapsedTime().asSeconds();
clock.restart();
sf::Event event;
+ /*static sf::Clock clock2;
+ if (clock2.getElapsedTime().asSeconds() > 5.0f) {
+ clock2.restart();
+ SetPlayerPos(camera.Position.x, camera.Position.y, camera.Position.z);
+ }*/
while (window->pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
@@ -201,36 +289,27 @@ void Display::MainLoop() {
glUniform1f(timeLoc, absTime);
glBindVertexArray(VAO);
- /*for (GLuint i = 0; i < 10; i++) {
- glm::mat4 model;
- glm::vec3 cubePositions[] = {
- glm::vec3(0, 0, 0),
- glm::vec3(0, 0, 1),
- glm::vec3(0, 0, 2),
- glm::vec3(1, 0, 0),
- glm::vec3(1, 0, 1),
- glm::vec3(1, 0, 2),
- glm::vec3(2, 0, 0),
- glm::vec3(2, 0, 1),
- glm::vec3(2, 0, 2),
- glm::vec3(3, 0, 3),
- };
- if (toRender.size()<1)
- continue;
- model = glm::translate(model,
- glm::vec3(toRender[0].GetX() * 16, toRender[0].GetZ() * 16,
- toRender[0].GetY() * 16));
- model = glm::translate(model, cubePositions[i]);
-
- GLfloat angle = 20.0f * (i);
- //model = glm::rotate(model, glm::radians(angle * absTime), glm::vec3(1.0f, 0.3f, 0.5f));
- glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
-
- glDrawArrays(GL_TRIANGLES, 0, 36);
- }*/
+ camera.MovementSpeed = 5.0f;
+ if (camera.Position.y > 50)
+ camera.Position = glm::vec3(0, 0, 3.0f);
+
+ glm::mat4 model;
+ glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
+ glUniform1i(blockLoc, 1);
+
+ std::string textureName = AssetManager::GetAssetNameByBlockId(1);
+ Texture &texture1 = *(AssetManager::GetAsset(textureName).data.texture);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, texture1.texture);
+ glUniform1i(glGetUniformLocation(shader.Program, "blockTexture"), 0);
- for (auto &sectionPos:toRender) {
- Section &section = world->m_sections[sectionPos];
+ glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
+ //glDrawArrays(GL_TRIANGLES, 0, 36);
+
+
+ /*for (auto &sectionPos:toRender) {
+ Section &section = world->m_sections.find(sectionPos)->second;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
@@ -240,7 +319,7 @@ void Display::MainLoop() {
sectionPos.GetZ() * 16));
model = glm::translate(model, glm::vec3(x, y, z));
- Block block = section.GetBlock(PositionI(x, z, y));
+ Block block = section.GetBlock(Vector(x, y, z));
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glUniform1i(blockLoc, block.id);
@@ -257,7 +336,7 @@ void Display::MainLoop() {
}
}
}
- }
+ }*/
glBindVertexArray(0);
//End of render code
diff --git a/code/graphics/Display.hpp b/src/graphics/Display.hpp
index 314ef5d..7458bcd 100644
--- a/code/graphics/Display.hpp
+++ b/src/graphics/Display.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <SFML/Window.hpp>
-#include "../World.hpp"
+#include "../world/World.hpp"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
@@ -12,7 +12,7 @@
class Display {
sf::Window *window;
World* world;
- std::vector<PositionI> toRender;
+ std::vector<Vector> toRender;
Camera3D camera;
public:
Display(unsigned int winWidth, unsigned int winHeight, const char winTitle[9], World *worldPtr);
diff --git a/code/graphics/Shader.cpp b/src/graphics/Shader.cpp
index c84e169..c84e169 100644
--- a/code/graphics/Shader.cpp
+++ b/src/graphics/Shader.cpp
diff --git a/code/graphics/Shader.hpp b/src/graphics/Shader.hpp
index 8178d2a..8178d2a 100644
--- a/code/graphics/Shader.hpp
+++ b/src/graphics/Shader.hpp
diff --git a/code/graphics/Texture.cpp b/src/graphics/Texture.cpp
index 0104530..0104530 100644
--- a/code/graphics/Texture.cpp
+++ b/src/graphics/Texture.cpp
diff --git a/code/graphics/Texture.hpp b/src/graphics/Texture.hpp
index 8e3f1af..8e3f1af 100644
--- a/code/graphics/Texture.hpp
+++ b/src/graphics/Texture.hpp