This commit is contained in:
Functioning Member of Society 2023-09-23 21:17:51 +00:00
parent 7342507fe8
commit 45d324a9ec
38 changed files with 0 additions and 11745 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
bin
obj

View File

@ -1,19 +0,0 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(XtreemNodes)
include_directories("include/")
file(GLOB_RECURSE Sources "src/**.cpp")
add_executable(${PROJECT_NAME} ${Sources})
if(UNIX AND NOT APPLE) # linux
target_link_libraries(${PROJECT_NAME} -lGL)
target_link_libraries(${PROJECT_NAME} -lGLEW)
target_link_libraries(${PROJECT_NAME} -lglfw)
#target_link_libraries(${PROJECT_NAME} -lsfml-opengl)
endif()
if (WIN32) # windows
endif(WIN32)

View File

@ -1,7 +0,0 @@
Copyright (c) 2022-2023 MCL Software
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,12 +0,0 @@
Begin Description:
XtreemNodes is a 3D Voxel Game engine by MCL Software & Cube Software,
meant to be a replacement for Minetest.
The project was started on 2022-10-15 by Migdyn
How to build on Windows with MSYS2
==================================
Download and install OpenGL, GLFW, Glew, GLM and mingw-w64 using Pacman and build the source files
Over.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 991 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

View File

@ -1,159 +0,0 @@
#version 330 core
in vec3 Normal;
in vec2 TexCoords;
in vec3 FragPosition;
out vec4 FragColor;
#define PI 3.14159265359
#define MAX_LIGHTS 128
struct Material {
float Ao;
vec3 Albedo;
float Metallic;
float Roughness;
};
struct PointLight {
vec3 Color;
vec3 Position;
float Intensity;
};
struct DirectLight {
vec3 Color;
vec3 Position;
vec3 Direction;
float Intensity;
};
struct SpotLight {
vec3 Color;
vec3 Position;
vec3 Direction;
float ICutOff;
float OCutOff;
float Intensity;
};
// uniforms
uniform sampler2D AoMap;
uniform sampler2D AlbedoMap;
uniform sampler2D NormalMap;
uniform sampler2D MetallicMap;
uniform sampler2D RoughnessMap;
uniform vec3 CameraPos;
uniform Material material;
uniform int spotLightCount;
uniform SpotLight spotLights[MAX_LIGHTS];
uniform int pointLightCount;
uniform PointLight pointLights[MAX_LIGHTS];
uniform int directLightCount;
uniform DirectLight directLights[MAX_LIGHTS];
float DistributionGGX(vec3 N, vec3 H, float roughness) {
float a = roughness * roughness;
float a2 = a * a;
float NdotH = max(dot(N, H), 0.0);
float NdotH2 = NdotH * NdotH;
float nom = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return nom / max(denom, 0.001); // prevent divide by zero for roughness=0.0 and NdotH=1.0
}
float GeometrySchlickGGX(float NdotV, float roughness) {
float r = (roughness + 1.0);
float k = (r * r) / 8.0;
float nom = NdotV;
float denom = NdotV * (1.0 - k) + k;
return nom / denom;
}
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
float NdotV = max(dot(N, V), 0.0);
float NdotL = max(dot(N, L), 0.0);
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
return ggx1 * ggx2;
}
vec3 fresnelSchlick(float cosTheta, vec3 F0) {
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
}
vec3 ProcessLight(vec3 N, vec3 V, vec3 Ld, vec3 color, vec3 F0, float I, float roughness, float metallic, vec3 albedo) {
vec3 L = normalize(Ld);
vec3 H = normalize(V + L);
float distance = length(Ld);
float attenuation = I / (distance * distance);
vec3 radiance = color * attenuation;
// Cook-Torrance BRDF
float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, roughness);
vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0);
vec3 nominator = NDF * G * F;
float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0);
vec3 specular = nominator / max(denominator, 0.001);
vec3 KS = F;
vec3 KD = vec3(1.0) - KS;
KD *= 1.0 - metallic;
float NdotL = max(dot(N, L), 0.0);
vec3 Lo = (KD * albedo / PI + specular) * radiance * NdotL;
return Lo;
}
void main() {
vec3 N = normalize(Normal);
vec3 V = normalize(CameraPos - FragPosition);
float ao = material.Ao + texture(AoMap, TexCoords).r;
vec3 albedo = pow(material.Albedo, vec3(2.2)) + pow(vec3(texture(AlbedoMap, TexCoords)), vec3(5.2));
float metallic = material.Metallic + texture(MetallicMap, TexCoords).r;
float roughness = material.Roughness + texture(RoughnessMap, TexCoords).r;
vec3 F0 = vec3(0.04);
F0 = mix(F0, albedo, metallic);
vec3 Luminance = vec3(0.0);
// Point lights
int count = (pointLightCount > MAX_LIGHTS) ? MAX_LIGHTS : pointLightCount;
for (int i = 0; i < count; i++) {
PointLight light = pointLights[i];
vec3 L = (light.Position - FragPosition);
Luminance += ProcessLight(N, V, L, light.Color, F0, light.Intensity, roughness, metallic, albedo);
}
// Directional lights
count = (directLightCount > MAX_LIGHTS) ? MAX_LIGHTS : directLightCount;
for (int i = 0; i < count; i++) {
DirectLight light = directLights[i];
Luminance += ProcessLight(N, V, light.Direction, light.Color, F0, light.Intensity, roughness, metallic, albedo);
}
// ambient
vec3 ambient = vec3(0.1f) * albedo * ao;
vec3 color = ambient + Luminance;
// HDR correction
color = color / (color + vec3(1.0));
// Gamma correction
color = pow(color, vec3(1.0 / 3.0));
FragColor = vec4(color, 1.0);
}

View File

@ -1,21 +0,0 @@
#version 330 core
#extension GL_ARB_explicit_attrib_location : enable
layout(location = 0) in vec3 aPos;
layout(location = 1) in vec3 aNormal;
layout(location = 2) in vec2 aTexCoords;
out vec3 Normal;
out vec2 TexCoords;
out vec3 FragPosition;
uniform mat4 View;
uniform mat4 Model;
uniform mat4 Projection;
void main() {
TexCoords = aTexCoords;
FragPosition = vec3(Model * vec4(aPos, 1.0));
Normal = transpose(inverse(mat3(Model))) * aNormal;
gl_Position = Projection * View * vec4(FragPosition, 1.0);
}

View File

@ -1,24 +0,0 @@
#pragma once
#ifndef BASE
#define BASE
#include <GL/glew.h>
#include <iostream>
//#include "NodeRenderer.h"
//#include "MapBlock.h"
class NodeManager;
class BlockManager;
extern NodeManager nodeManager;
extern BlockManager blockManager;
struct Position2D
{
int x;
int z;
};
#endif

View File

@ -1,113 +0,0 @@
#ifndef CAMERA_H
#define CAMERA_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
enum Camera_Movement {
FORWARD,
BACKWARD,
LEFT,
RIGHT
};
const float YAW = -90.0f;
const float PITCH = 0.0f;
const float SPEED = 2.5f;
const float SENSITIVITY = 0.1f;
const float ZOOM = 45.0f;
class Camera
{
public:
glm::vec3 Position;
glm::vec3 Front;
glm::vec3 Up;
glm::vec3 Right;
glm::vec3 WorldUp;
float Yaw;
float Pitch;
float MovementSpeed;
float MouseSensitivity;
float Zoom;
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
{
Position = position;
WorldUp = up;
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
{
Position = glm::vec3(posX, posY, posZ);
WorldUp = glm::vec3(upX, upY, upZ);
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
glm::mat4 GetViewMatrix()
{
return glm::lookAt(Position, Position + Front, Up);
}
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
{
float velocity = MovementSpeed * deltaTime;
if (direction == FORWARD)
Position += Front * velocity;
if (direction == BACKWARD)
Position -= Front * velocity;
if (direction == LEFT)
Position -= Right * velocity;
if (direction == RIGHT)
Position += Right * velocity;
}
void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true)
{
xoffset *= MouseSensitivity;
yoffset *= MouseSensitivity;
Yaw += xoffset;
Pitch += yoffset;
if (constrainPitch)
{
if (Pitch > 89.0f)
Pitch = 89.0f;
if (Pitch < -89.0f)
Pitch = -89.0f;
}
updateCameraVectors();
}
void ProcessMouseScroll(float yoffset)
{
Zoom -= (float)yoffset;
if (Zoom < 1.0f)
Zoom = 1.0f;
if (Zoom > 45.0f)
Zoom = 45.0f;
}
private:
void updateCameraVectors()
{
glm::vec3 front;
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Front = glm::normalize(front);
Up = glm::normalize(glm::cross(Right, Front));
}
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,42 +0,0 @@
#ifndef MATERIAL
#define MATERIAL
#include "GLShader.h"
struct Material {
Material() = default;
~Material() = default;
Material(glm::vec3 albedo, GLfloat metallic, GLfloat roughness, GLfloat ao):
Albedo(albedo), Metallic(metallic), Roughness(roughness), Ao(ao) { }
float Ao = 0.1f;
float Opacity = 1.0f;
float Metallic = 0.4f;
float Roughness = 0.2f;
float Shininess = 1.0f;
float Reflectivity = 0.0f;
glm::vec3 Albedo = glm::vec3(0.6f);
GLuint AoMap = 0;
GLuint NormalMap = 0;
GLuint AlbedoMap = 0;
GLuint MetallicMap = 0;
GLuint RoughnessMap = 0;
GLuint SpecularBRDFMap = 0;
void SetUniform(Shader& shader) {
shader.bind();
shader.setuniform("material.Ao", Ao);
shader.setuniform("material.Albedo", Albedo);
shader.setuniform("material.Metallic", Metallic);
shader.setuniform("material.Roughness", Roughness);
shader.setuniform("AoMap", AoMap, 0);
shader.setuniform("AlbedoMap", AlbedoMap, 1);
shader.setuniform("NormalMap", NormalMap, 2);
shader.setuniform("MetallicMap", MetallicMap, 3);
shader.setuniform("RoughnessMap", RoughnessMap, 4);
}
};
#endif

View File

@ -1,53 +0,0 @@
#ifndef GLMESH_H
#define GLMESH_H
#include "GLVertexArray.h"
#include "GLMaterial.h"
class GLMesh {
public:
GLMesh() = default;
~GLMesh() = default;
GLMesh(Vertex* vertices, GLsizei vSize) {
vao = VertexArray(vertices, vSize);
}
GLMesh(Vertex* vertices, GLsizei vSize, GLuint* indices, GLsizei iSize) {
vao = VertexArray(vertices, vSize, indices, iSize);
}
GLMesh(Vertex* vertices, GLsizei vSize, GLuint* indices, GLsizei iSize, const Material& matrial):
material(matrial) {
vao = VertexArray(vertices, vSize, indices, iSize);
}
GLMesh(const VertexArray& vao): vao(vao) {}
void SetMaterial(const Material& matrial) {
material = matrial;
}
Material& GetMaterial() {
return material;
}
void Render(Shader& shader, GLenum mode = GL_TRIANGLE_STRIP) {
material.SetUniform(shader);
shader.bind();
vao.DrawElements(mode);
}
void DrawArrays(Shader& shader, GLenum mode = GL_TRIANGLES) {
material.SetUniform(shader);
shader.bind();
vao.DrawArrays(mode);
}
private:
VertexArray vao;
Material material;
};
#endif

View File

@ -1,115 +0,0 @@
#include "GLShader.h"
#include "Base.h"
#include <iostream>
#include <fstream>
#include <sstream>
Shader::Shader(const char* vertexPath, const char* fragmentPath)
{
// 1. retrieve the vertex/fragment source code from filePath
std::string vertexCode;
std::string fragmentCode;
std::ifstream vShaderFile;
std::ifstream fShaderFile;
// ensure ifstream objects can throw exceptions:
vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
try
{
// open files
vShaderFile.open(vertexPath);
fShaderFile.open(fragmentPath);
std::stringstream vShaderStream, fShaderStream;
// read file's buffer contents into streams
vShaderStream << vShaderFile.rdbuf();
fShaderStream << fShaderFile.rdbuf();
// close file handlers
vShaderFile.close();
fShaderFile.close();
// convert stream into string
vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
}
catch (std::ifstream::failure& e)
{
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ: " << e.what() << std::endl;
}
const char* vShaderCode = vertexCode.c_str();
const char * fShaderCode = fragmentCode.c_str();
// 2. compile shaders
unsigned int vertex, fragment;
// vertex shader
vertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex, 1, &vShaderCode, NULL);
glCompileShader(vertex);
checkCompileErrors(vertex, "VERTEX");
// fragment Shader
fragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment, 1, &fShaderCode, NULL);
glCompileShader(fragment);
checkCompileErrors(fragment, "FRAGMENT");
// shader Program
program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
checkCompileErrors(program, "PROGRAM");
// delete the shaders as they're linked into our program now and no longer necessery
glDeleteShader(vertex);
glDeleteShader(fragment);
}
void Shader::bind(){
GLCALL(glUseProgram(program));
}
void Shader::unbind(){
GLCALL(glUseProgram(0));
}
void Shader::setuniform(const GLchar* uName, unsigned int value){
GLCALL(glUniform1i(glGetUniformLocation(program, uName), value));
}
void Shader::setuniform(const GLchar* uName, int value){
GLCALL(glUniform1i(glGetUniformLocation(program, uName), value));
}
void Shader::setuniform(const GLchar* uName, GLfloat value){
GLCALL(glUniform1i(glGetUniformLocation(program, uName), value));
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y){
GLCALL(glUniform2f(glGetUniformLocation(program, uName), x, y));
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z){
GLCALL(glUniform3f(glGetUniformLocation(program, uName), x, y, z));
}
void Shader::setuniform(const GLchar* uName, glm::vec3 vector){
GLCALL(glUniform3f(glGetUniformLocation(program, uName), vector.x, vector.y, vector.z));
}
void Shader::setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z, GLfloat w){
GLCALL(glUniform4f(glGetUniformLocation(program, uName), x, y, z, w));
}
void Shader::setuniform(const GLchar* name, const glm::mat4 &mat)
{
glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_FALSE, &mat[0][0]);
}
void Shader::setuniform(const GLchar* uName, glm::vec2 vector){
GLCALL(glUniform2f(glGetUniformLocation(program, uName), vector.x, vector.y));
}
void Shader::setuniform(const GLchar* uName, glm::vec4 vector){
GLCALL(glUniform4f(glGetUniformLocation(program, uName), vector.x, vector.y, vector.z, vector.w));
}
void Shader::setuniform(const GLchar* uName, GLuint tex2d, GLint unit){ // sample 2d
GLCALL(glActiveTexture(GL_TEXTURE0 + unit));
GLCALL(glBindTexture(GL_TEXTURE_2D, tex2d));
GLCALL(glUniform1i(glGetUniformLocation(program, uName), unit));
}

View File

@ -1,65 +0,0 @@
#ifndef SHADER_H
#define SHADER_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <iostream>
#define GLCALL(func) func
class Shader {
public:
Shader() : program(0) {}
Shader(const GLuint id) : program(id) {}
Shader(const char* vertexPath, const char* fragmentPath);
~Shader() { glDeleteProgram(program); }
void bind();
void unbind();
void setuniform(const GLchar* uName, unsigned int value);
void setuniform(const GLchar* uName, int value);
void setuniform(const GLchar* uName, GLfloat value);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y);
void setuniform(const GLchar* uName, glm::vec2 vector);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z);
void setuniform(const GLchar* uName, glm::vec3 vector);
void setuniform(const GLchar* uName, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void setuniform(const GLchar* uName, glm::vec4 vector);
void setuniform(const GLchar* uName, const glm::mat4& mtx);
void setuniform(const GLchar* uName, GLuint tex2d, GLint unit); // sample 2d
GLuint getuniform(const char* name);
GLuint GetProgram() { return program; }
private:
void checkCompileErrors(GLuint shader, std::string type)
{
GLint success;
GLchar infoLog[1024];
if(type != "PROGRAM")
{
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
else
{
glGetProgramiv(shader, GL_LINK_STATUS, &success);
if(!success)
{
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
}
GLuint program;
};
#endif

View File

@ -1,19 +0,0 @@
#ifndef GLVERTEX_H
#define GLVERTEX_H
struct Vertex {
Vertex() = default;
Vertex(float x, float y, float z): Position(glm::vec3(x, y, z)){}
Vertex(glm::vec3 position): Position(position), Normal(0), TexCoords(0) { }
Vertex(glm::vec3 position, glm::vec3 normal): Position(position), Normal(normal), TexCoords(0) { }
Vertex(glm::vec3 position, glm::vec3 normal, glm::vec2 texcoord): Position(position), Normal(normal), TexCoords(texcoord) { }
// position
glm::vec3 Position = glm::vec3(0.0f);
// normal
glm::vec3 Normal = glm::vec3(0.0f);
// coords
glm::vec2 TexCoords = glm::vec2(0.0f);
};
#endif

View File

@ -1,70 +0,0 @@
#ifndef GLVERTEXARRAY_H
#define GLVERTEXARRAY_H
#include "GLVertex.h"
class VertexArray {
public:
~VertexArray() = default;
VertexArray(): VAO(0), EBO(0), VBO(0), numOfIndices(0),
numOfVertices(0) {}
VertexArray(Vertex* vertices, GLsizei vSize, GLuint* indices=nullptr, GLsizei iSize=0):
numOfIndices(iSize), numOfVertices(vSize){
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, numOfVertices * sizeof(Vertex), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, numOfIndices * sizeof(GLuint), indices, GL_STATIC_DRAW);
// Positions
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0);
// Normals
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Normal));
// Texcoords
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, TexCoords));
glBindVertexArray(0);
numOfVertices /= sizeof(Vertex);
}
void PushAttrib(GLuint index, GLint size, GLsizei stride, GLvoid* ptr) {
glEnableVertexAttribArray(index);
glVertexAttribPointer(index, size, GL_FLOAT, GL_FALSE, size, ptr);
}
void Bind() {
GLCALL(glBindVertexArray(VAO));
}
void UnBind() {
GLCALL(glBindVertexArray(0));
}
void DrawElements(GLenum mode = GL_TRIANGLE_STRIP) {
GLCALL(glBindVertexArray(VAO));
GLCALL(glDrawElements(mode, numOfIndices, GL_UNSIGNED_INT, 0));
GLCALL(glBindVertexArray(0));
}
void DrawArrays(GLenum mode = GL_TRIANGLES) {
GLCALL(glBindVertexArray(VAO));
GLCALL(glDrawArrays(mode, 0, numOfVertices));
GLCALL(glBindVertexArray(0));
}
private:
GLuint VAO, VBO, EBO;
GLsizei numOfIndices, numOfVertices;
};
#endif

View File

@ -1,45 +0,0 @@
/*#include "MapBlock.h"
#include "FastNoiseLite.h"
#include "LevelGenerator.h"
//FastNoiseLite perlin, os, cellular;
int seed = 138;
LevelGenerator::LevelGenerator()
{
perlin.SetSeed(seed);
perlin.SetNoiseType(FastNoiseLite::NoiseType_Perlin);
perlin.SetFrequency(.01F);
os.SetSeed(seed);
os.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
os.SetFrequency(.01F);
cellular.SetSeed(seed);
cellular.SetNoiseType(FastNoiseLite::NoiseType_Cellular);
cellular.SetFrequency(.1F);
}
void LevelGenerator::generateBlock()
{
for(int bx = 0; bx < 8; bx++)
{
for(int bz = 0; bz < 8; bz++)
{
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
float cX = (float)x + (16 * bx);
float cZ = (float)z + (16 * bz);
for(int y = 0; y < 48 * abs(perlin.GetNoise(cX, cZ)) / 2 + abs(cellular.GetNoise(cX, cZ)) * 2 + abs(os.GetNoise(cX, cZ)) * 4 + 10; y++)
{
blockManager.mapBlocks[bx][bz].addNode(y > 20 ? 1 : 2, 0, x, y, z);
}
}
}
}
}
}
*/

View File

@ -1,19 +0,0 @@
/*#ifndef LEVELGENERATOR
#define LEVELGENERATOR
#include "FastNoiseLite.h"
class LevelGenerator
{
public:
LevelGenerator();
void generateBlock();
protected:
private:
FastNoiseLite perlin, os, cellular;
int seed = 138;
};
#endif
*/

View File

@ -1,11 +0,0 @@
#include <cstdio>
class Logger
{
public:
void log(char* comp, char* message);
{
printf("Message: %c", message);
}
};

View File

@ -1,68 +0,0 @@
/*#include "MapBlock.h"
int mapBlock[65536];
MapBlock::MapBlock()
{
}
// TODO; Make this function work with global coordinates and move it to BlockManager
void MapBlock::addNode(int id, int meta, int x, int y, int z)
{
mapBlock[256 * y + z * 16 + x] = id;
}
MapBlock mapBlocks[16][16];
BlockManager::BlockManager()
{
}
int BlockManager::getNodeAt(int x, int y, int z)
{
// Math explanation for future reference:
// The x and z coordinates need to be have block.[AXIS] * 16 subtracted from them
// so that the coordinates passed to the function are local block coordinates instead
// of global node coordinates (e.g. 1, and not 17)
if(x < 0 || y < 0 || z < 0)
{
return 0;
}
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
int localX = x - block.x * 16;
int localZ = z - block.z * 16;
return mapBlocks[block.x][block.z].mapBlock[256 * y + localZ * 16 + localX];
}
bool BlockManager::isAir(int x, int y, int z)
{
return getNodeAt(x, y, z) == 0;
}
BlockUtilities::BlockUtilities()
{
}
Position2D BlockUtilities::getBlockFromNodeCoordinates(int x, int z)
{
Position2D pos2d;
pos2d.x = floor(x / 16);
pos2d.z = floor(z / 16);
return pos2d;
}
*/

View File

@ -1,34 +0,0 @@
/*#ifndef MAPBLOCK
#define MAPBLOCK
#include "Base.h"
#include <math.h>
#include <cstdio>
class MapBlock
{
public:
int mapBlock[65536];
MapBlock();
// TODO; Make this function work with global coordinates and move it to BlockManager
void addNode(int id, int meta, int x, int y, int z);
};
class BlockManager
{
public:
MapBlock mapBlocks[16][16];
BlockManager();
int getNodeAt(int x, int y, int z);
bool isAir(int x, int y, int z);
};
class BlockUtilities
{
public:
BlockUtilities();
static Position2D getBlockFromNodeCoordinates(int x, int z);
};
#endif
*/

View File

@ -1,34 +0,0 @@
#ifndef NODERENDERER_H
#define NODERENDERER_H
#include "Base.h"
#include "MapBlock.h"
class NodeRenderer
{
public:
NodeRenderer()
{
}
virtual ~NodeRenderer()
{
}
int renderNode(int x, int y, int z)
{
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
// render block
return 1;
}
protected:
private:
};
#endif

View File

@ -1,17 +0,0 @@
class Node
{
public:
Node(int i, int j)
{
id = i;
textureIndex = j;
}
int getTextureIndexFromSide(int side)
{
return textureIndex;
}
private:
int id;
int textureIndex;
};

View File

@ -1,70 +0,0 @@
#define STBI_FAILURE_USERMSG
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "Base.h"
//#ifndef TEXTURE_HANDLER
//#define TEXTURE_HANDLER
class TextureHandler
{
private:
int width = -1;
int height = -1;
int comp = -1;
unsigned char* imageData;
unsigned char* imageData1;
public:
GLuint textures;
GLuint textures1;
unsigned char* loadTexture(char* filename)
{
return stbi_load(filename, &width, &height, &comp, 0);
}
void loadAllTextures()
{/*
int textureIndex = 0;
imageData = loadTexture("data/img/texturemap.png");
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &textures);
glBindTexture(GL_TEXTURE_2D, textures);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
imageData1 = loadTexture("data/img/oak.png");
glGenTextures(1, &textures1);
glBindTexture(GL_TEXTURE_2D, textures1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData1);*/
}
void getTextureForNode(int x, int y, int z)
{
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
if(blockManager.getNodeAt(x, y, z) == 1)
{
//glBindTexture(GL_TEXTURE_2D, textures);
}
else if(blockManager.getNodeAt(x, y, z) == 2)
{
//glBindTexture(GL_TEXTURE_2D, textures1);
}
}
};
//#endif

View File

@ -1,24 +0,0 @@
#ifndef UTILITIES
#define UTILITIES
class Utilities
{
public:
Utilities()
{
}
static float degToRad(int degrees)
{
return 3.14 / 180 * degrees; // Only the first three digits of pi
}
protected:
private:
};
#endif

View File

View File

@ -1,216 +0,0 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "stb_image.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "GLShader.h"
#include "GLMesh.h"
#include "Camera.h"
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void processInput(GLFWwindow *window);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = SCR_WIDTH / 2.0f;
float lastY = SCR_HEIGHT / 2.0f;
bool firstMouse = true;
// timing
float deltaTime = 0.0f; // time between current frame and last frame
float lastFrame = 0.0f;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
// tell GLFW to capture our mouse
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// glad: load all OpenGL function pointers
// ---------------------------------------
// glew
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << std::endl;
return -1;
}
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
Shader sh = Shader("data/shader/MeshV.shader", "data/shader/MeshF.shader");
static Vertex cubeVertices[] = {
// positions // normals // texture coords
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(0.5f, -0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(0.5f, -0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, -0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(0.5f, -0.5f, -0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(0.5f, -0.5f, -0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(0.5f, -0.5f, 0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(0.5f, -0.5f, -0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(0.5f, -0.5f, 0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, -0.5f, 0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, 0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
Vertex(glm::vec3(0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 1.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(1.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, 0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(0.0f, 0.0f)),
Vertex(glm::vec3(-0.5f, 0.5f, -0.5f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec2(0.0f, 1.0f)),
};
GLMesh mesh = GLMesh(cubeVertices, sizeof(cubeVertices));
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// per-frame time logic
// --------------------
float currentFrame = static_cast<float>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mesh.DrawArrays(sh);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow *window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, deltaTime);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
{
float xpos = static_cast<float>(xposIn);
float ypos = static_cast<float>(yposIn);
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos; // reversed since y-coordinates go from bottom to top
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
// glfw: whenever the mouse scroll wheel scrolls, this callback is called
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(static_cast<float>(yoffset));
}

View File

@ -1,2 +0,0 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

File diff suppressed because it is too large Load Diff