CMake build added. Basic OpenGL 3.3 Mesh Rendering

This commit is contained in:
{{QWERTYKBGUI}} 2023-03-01 07:22:50 +01:00
parent 1215e7d8a5
commit 76c7e1808c
46 changed files with 960 additions and 912 deletions

19
CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
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)

51
GUI.cpp
View File

@ -1,51 +0,0 @@
#include "GUI.h"
// Code contributed by Kacperks
// COMMENTED OUT BECAUSE IT DOESN'T WORK!
/*
Button::Button(sf::Image* normal, sf::Image* clicked, std::string words, Position2D location) {
this->normal.SetImage(*normal);
this->clicked.SetImage(*clicked);
this->currentSpr=&this->normal;
current =false;
this->normal.SetPosition(location);
this->clicked.SetPosition(location);
String.SetText(words);
String.SetPosition(location.x+3,location.y+3);
String.SetSize(14);
}
void Button::checkClick (sf::Vector2f mousePos)
{
if (mousePos.x>currentSpr->GetPosition().x && mousePos.x<(currentSpr->GetPosition().x + currentSpr->GetSize().x)) {
if(mousePos.y>currentSpr->GetPosition().y && mousePos.y<(currentSpr->GetPosition().y + currentSpr->GetSize().y)) {
setState(!current);
}
}
}
void Button::setState(bool which)
{
current = which;
if (current) {
currentSpr=&clicked;
return;
}
currentSpr=&normal;
}
void Button::setText(std::string words)
{
String.SetText(words);
}
bool Button::getVar()
{
return current;
}
sf::Sprite* Button::getSprite()
{
return currentSpr;
}
sf::String * Button::getText()
{
return &String;
}*/

View File

@ -1,134 +0,0 @@
# depslib dependency file v1.0
<<<<<<< HEAD
1672107417 source:c:\development\xtreemminer\main.cpp
=======
1672097148 source:c:\development\xtreemminer\main.cpp
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
<stdlib.h>
<GL/glut.h>
"Utilities.h"
"MapBlock.h"
"Base.h"
"NodeRenderer.h"
"TextureHandler.h"
<math.h>
<cstdio>
<random>
<SFML/Window.hpp>
<<<<<<< HEAD
1672201712 c:\development\xtreemminer\include\noderenderer.h
=======
1667160597 c:\development\xtreemminer\include\noderenderer.h
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
"Base.h"
"MapBlock.h"
<GL/glut.h>
1667164077 c:\development\xtreemminer\include\mapblock.h
"Base.h"
<math.h>
<cstdio>
1667065840 c:\development\xtreemminer\include\base.h
1666531672 source:c:\development\xtreemminer\base.cpp
"MapBlock.h"
"Base.h"
<<<<<<< HEAD
1672341127 c:\development\xtreemminer\include\texturehandler.h
=======
1672105046 c:\development\xtreemminer\include\texturehandler.h
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
"stb_image.h"
"Base.h"
1666445333 c:\development\xtreemminer\include\stb_image.h
"stb_image.h"
<stdio.h>
<stdlib.h>
<stdarg.h>
<stddef.h>
<stdlib.h>
<string.h>
<limits.h>
<math.h>
<stdio.h>
<assert.h>
<stdint.h>
<emmintrin.h>
<intrin.h>
<arm_neon.h>
1667065840 c:\development\xtreemminer\include\utilities.h
1667075984 c:\development\xtreemminer\include\fastnoiselite.h
<cmath>
1667350805 source:c:\development\xtreemminer\mapblock.cpp
"MapBlock.h"
1667294728 source:/home/kacperks/projects/XtreemNodes/MapBlock.cpp
"MapBlock.h"
1667294728 /home/kacperks/projects/XtreemNodes/include/MapBlock.h
"Base.h"
<math.h>
<cstdio>
1667294728 /home/kacperks/projects/XtreemNodes/include/Base.h
1667294728 source:/home/kacperks/projects/XtreemNodes/main.cpp
<stdlib.h>
<GL/glut.h>
"Utilities.h"
"MapBlock.h"
"Base.h"
"NodeRenderer.h"
"TextureHandler.h"
<math.h>
<cstdio>
"FastNoiseLite.h"
<random>
<SFML/Window.hpp>
1667294728 /home/kacperks/projects/XtreemNodes/include/Utilities.h
1667294728 /home/kacperks/projects/XtreemNodes/include/NodeRenderer.h
"Base.h"
"MapBlock.h"
<GL/glut.h>
1667294728 /home/kacperks/projects/XtreemNodes/include/TextureHandler.h
"stb_image.h"
"Base.h"
1667088826 /home/kacperks/projects/XtreemNodes/include/stb_image.h
"stb_image.h"
<stdio.h>
<stdlib.h>
<stdarg.h>
<stddef.h>
<stdlib.h>
<string.h>
<limits.h>
<math.h>
<stdio.h>
<assert.h>
<stdint.h>
<emmintrin.h>
<intrin.h>
<arm_neon.h>
1667294728 /home/kacperks/projects/XtreemNodes/include/FastNoiseLite.h
<cmath>
1667347897 source:c:\development\xtreemminer\gui.cpp
"GUI.h"
1667333037 c:\development\xtreemminer\include\gui.h
"Base.h"
<SFML/Main.hpp>
<SFML/Graphics.hpp>

View File

@ -1,114 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<<<<<<< HEAD
<File name="include\FastNoiseLite.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="100664" topLine="2262" />
=======
<File name="include\NodeRenderer.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="2409" topLine="24" />
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
</Cursor>
</File>
<File name="MapBlock.cpp" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="29" topLine="0" />
</Cursor>
</File>
<<<<<<< HEAD
<File name="include\MapBlock.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="438" topLine="0" />
</Cursor>
</File>
<File name="include\stb_image.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="8925" topLine="160" />
</Cursor>
</File>
<File name="MapBlock.cpp" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1001" topLine="30" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2573" topLine="88" />
</Cursor>
</File>
<File name="include\Nodes.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
=======
<File name="include\Nodes.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
<Cursor>
<Cursor1 position="264" topLine="0" />
</Cursor>
</File>
<<<<<<< HEAD
<File name="include\Logger.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
=======
<File name="include\LevelGenerator.h" open="0" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="174" topLine="0" />
</Cursor>
</File>
<File name="GUI.cpp" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1286" topLine="3" />
</Cursor>
</File>
<File name="include\stb_image.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="8925" topLine="160" />
</Cursor>
</File>
<File name="LevelGenerator.cpp" open="0" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="87" topLine="0" />
</Cursor>
</File>
<File name="include\FastNoiseLite.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
>>>>>>> dcac2713f6b72f4d2252632a179b30a33fd827a8
<Cursor>
<Cursor1 position="97" topLine="0" />
</Cursor>
</File>
<File name="include\Base.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="28" topLine="0" />
</Cursor>
</File>
<File name="include\MapBlock.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="438" topLine="3" />
</Cursor>
</File>
<File name="include\Logger.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="97" topLine="0" />
</Cursor>
</File>
<File name="include\GUI.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="331" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="201" topLine="0" />
</Cursor>
</File>
<File name="include\TextureHandler.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="16" />
</Cursor>
</File>
<File name="include\NodeRenderer.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="2409" topLine="75" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="XtreemNodes" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/XtreemNodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="include" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/XtreemNodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Linker>
<Add option="-lGLEW" />
<Add option="-lGL" />
<Add option="-lsfml" />
</Linker>
<Unit filename="GUI.cpp" />
<Unit filename="MapBlock.cpp" />
<Unit filename="include/Base.h" />
<Unit filename="include/FastNoiseLite.h" />
<Unit filename="include/GUI.h" />
<Unit filename="include/Logger.h" />
<Unit filename="include/MapBlock.h" />
<Unit filename="include/NodeRenderer.h" />
<Unit filename="include/Nodes.h" />
<Unit filename="include/TextureHandler.h" />
<Unit filename="include/Utilities.h" />
<Unit filename="include/stb_image.h" />
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="XtreemNodes" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/XtreemNodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="include" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/XtreemNodes" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Linker>
<Add option="-lfreeglut" />
<Add option="-lglew32" />
<Add option="-lglu32" />
<Add option="-lopengl32" />
<Add option="-lsfml-window" />
<Add option="-lsfml-graphics" />
</Linker>
<Unit filename="GUI.cpp" />
<Unit filename="LevelGenerator.cpp" />
<Unit filename="MapBlock.cpp" />
<Unit filename="include/Base.h" />
<Unit filename="include/FastNoiseLite.h" />
<Unit filename="include/GUI.h" />
<Unit filename="include/LevelGenerator.h" />
<Unit filename="include/Logger.h" />
<Unit filename="include/MapBlock.h" />
<Unit filename="include/NodeRenderer.h" />
<Unit filename="include/Nodes.h" />
<Unit filename="include/TextureHandler.h" />
<Unit filename="include/Utilities.h" />
<Unit filename="include/stb_image.h" />
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,71 +0,0 @@
# depslib dependency file v1.0
1667347897 source:c:\development\xtreemminer\gui.cpp
"GUI.h"
1667333037 c:\development\xtreemminer\include\gui.h
"Base.h"
<SFML/Main.hpp>
<SFML/Graphics.hpp>
1667065840 c:\development\xtreemminer\include\base.h
1672106999 source:c:\development\xtreemminer\main.cpp
<stdlib.h>
<GL/glut.h>
"Utilities.h"
"MapBlock.h"
"Base.h"
"NodeRenderer.h"
"TextureHandler.h"
"LevelGenerator.h"
<math.h>
<cstdio>
<random>
<SFML/Window.hpp>
1667065840 c:\development\xtreemminer\include\utilities.h
1667164077 c:\development\xtreemminer\include\mapblock.h
"Base.h"
<math.h>
<cstdio>
1667160597 c:\development\xtreemminer\include\noderenderer.h
"Base.h"
"MapBlock.h"
<GL/glut.h>
1672105046 c:\development\xtreemminer\include\texturehandler.h
"stb_image.h"
"Base.h"
1666445333 c:\development\xtreemminer\include\stb_image.h
"stb_image.h"
<stdio.h>
<stdlib.h>
<stdarg.h>
<stddef.h>
<stdlib.h>
<string.h>
<limits.h>
<math.h>
<stdio.h>
<assert.h>
<stdint.h>
<emmintrin.h>
<intrin.h>
<arm_neon.h>
1667350805 source:c:\development\xtreemminer\mapblock.cpp
"MapBlock.h"
1672106616 source:c:\development\xtreemminer\levelgenerator.cpp
"LevelGenerator.h"
1672106654 c:\development\xtreemminer\include\levelgenerator.h
"FastNoiseLite.h"
"MapBlock.h"
1667075984 c:\development\xtreemminer\include\fastnoiselite.h
<cmath>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3631" topLine="60" />
</Cursor>
</File>
<File name="MapBlock.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="LevelGenerator.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1029" topLine="0" />
</Cursor>
</File>
<File name="include\MapBlock.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="include\LevelGenerator.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="97" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

BIN
data/img/apple.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

BIN
data/img/awesomeface.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
data/img/cobble.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
data/img/gold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

After

Width:  |  Height:  |  Size: 423 B

BIN
data/img/grass_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

BIN
data/img/iron.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

BIN
data/img/maple.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 B

BIN
data/img/oak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

BIN
data/img/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

159
data/shader/MeshF.shader Normal file
View File

@ -0,0 +1,159 @@
#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);
}

21
data/shader/MeshV.shader Normal file
View File

@ -0,0 +1,21 @@
#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,26 +0,0 @@
#ifndef GUI
#define GUI
#include "Base.h"
#include <SFML/Main.hpp>
#include <SFML/Graphics.hpp>
class Button
{
public:
Button(sf::Image* normal, sf::Image* clicked, std::string text, Position2D location);
void checkClick(Position2D);
void setState(bool state);
void setText(std::string);
bool getVar();
sf::Sprite* getSprite();
sf::String* getText();
private:
sf::Sprite normal;
sf::Sprite clicked;
sf::Sprite* currentSpr;
sf::String String;
bool current;
};
#endif

View File

@ -1,144 +0,0 @@
#ifndef NODERENDERER_H
#define NODERENDERER_H
#include "Base.h"
#include "MapBlock.h"
#include <GL/glut.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
glColor3f(1.0F, 1.0F, 1.0F);
glBegin(GL_QUADS);
// Front
if(blockManager.isAir(x, y, z - 1))
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F); // Bottom vertices
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glColor3f(1.0F, 1.0F, 1.0F);
}
// Back
if(blockManager.isAir(x, y, z + 1))
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glColor3f(.6F, .6F, .6F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
}
// Right
if(blockManager.isAir(x + 1, y, z))
{
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
// Left
if(blockManager.isAir(x - 1, y, z))
{
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
}
// Bottom
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
if(blockManager.isAir(x, y - 1, z))
{
//printf("\nWUT? x: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Top
if(blockManager.isAir(x, y + 1, z))
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
glEnd();
return 1;
}
protected:
private:
};
#endif

196
main.cpp
View File

@ -1,196 +0,0 @@
#include <stdlib.h>
#include <GL/glut.h>
#include "Utilities.h"
#include "MapBlock.h"
#include "Base.h"
#include "NodeRenderer.h"
#include "TextureHandler.h"
#include <math.h>
#include <cstdio>
#include <random>
#include <SFML/Window.hpp>
NodeRenderer renderer;
BlockManager blockManager;
TextureHandler textureHandler;
GLfloat playerX = 0;
GLfloat playerY = -30;
GLfloat playerZ = -100;
GLfloat playerRotX = 0;
GLfloat playerRotY = 0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(playerRotX, 1.0F, .0F, .0F);
glRotatef(playerRotY, .0F, 1.0F, .0F);
glTranslatef(playerX, playerY, playerZ);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_QUADS);
for(int x = 0; x < 100; x++)
{
for(int y = 0; y < 64; y++)
{
for(int z = 0; z < 100; z++)
{
if(blockManager.getNodeAt(x, y, z) > 0)
{
textureHandler.getTextureForNode(x, y, z);
renderer.renderNode(x, y, z);
}
}
}
}
glEnd();
glFlush();
glutSwapBuffers();
/*
sf::Vector2i lastMousePos = sf::Vector2i(0, 0);
const sf::Window& window = nullptr;
sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos;
lastMousePos = sf::Mouse::getPosition(window);*/
//glutPostRedisplay();
}
void reshape(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30, width / (float) height, 5, 512.0F);
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
void updateTimer(int time)
{
// Movement
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{
playerZ += .8;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{
playerZ -= .8;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
{
playerX += .8;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
playerX -= .8;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
{
playerY += .8;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
playerY -= .8;
}
// Rotation
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
playerRotY -= 1.8;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
playerRotY += 1.8;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
playerRotX -= 1.8;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
playerRotX += 1.8;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
exit(0);
}
glutPostRedisplay();
glutTimerFunc(30, &updateTimer, 0);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software");
glClearColor(.4, .7, .8 , 255);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_FRONT);
//glFrontFace(GL_CCW);
// Load textures
textureHandler.loadAllTextures();
/*
for(int y = 0; y < 16; y++)
{
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
printf("\n|x: %i |y: %i | z: %i | id: %i", x, y, z, blockManager.getNodeAt(x, y, z));
}
}
}
*/
updateTimer(0);
glutDisplayFunc(&display);
glutReshapeFunc(&reshape);
glutMainLoop();
return 0;
}

View File

@ -1,6 +1,11 @@
#pragma once
#ifndef BASE
#define BASE
#include <GL/glew.h>
#include <iostream>
//#include "NodeRenderer.h"
//#include "MapBlock.h"

113
src/Camera.h Normal file
View File

@ -0,0 +1,113 @@
#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

42
src/GLMaterial.h Normal file
View File

@ -0,0 +1,42 @@
#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

53
src/GLMesh.h Normal file
View File

@ -0,0 +1,53 @@
#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

115
src/GLShader.cpp Normal file
View File

@ -0,0 +1,115 @@
#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));
}

65
src/GLShader.h Normal file
View File

@ -0,0 +1,65 @@
#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

19
src/GLVertex.h Normal file
View File

@ -0,0 +1,19 @@
#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

70
src/GLVertexArray.h Normal file
View File

@ -0,0 +1,70 @@
#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,23 +1,24 @@
/*#include "MapBlock.h"
#include "FastNoiseLite.h"
#include "LevelGenerator.h"
FastNoiseLite perlin, os, cellular;
//FastNoiseLite perlin, os, cellular;
int seed = 138;
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);
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()
@ -41,3 +42,4 @@ void LevelGenerator::generateBlock()
}
}
}
*/

View File

@ -1,4 +1,4 @@
#ifndef LEVELGENERATOR
/*#ifndef LEVELGENERATOR
#define LEVELGENERATOR
#include "FastNoiseLite.h"
@ -16,3 +16,4 @@ class LevelGenerator
};
#endif
*/

View File

@ -1,4 +1,4 @@
#include "MapBlock.h"
/*#include "MapBlock.h"
@ -65,3 +65,4 @@ Position2D BlockUtilities::getBlockFromNodeCoordinates(int x, int z)
pos2d.z = floor(z / 16);
return pos2d;
}
*/

View File

@ -1,4 +1,4 @@
#ifndef MAPBLOCK
/*#ifndef MAPBLOCK
#define MAPBLOCK
#include "Base.h"
#include <math.h>
@ -31,3 +31,4 @@ class BlockUtilities
};
#endif
*/

34
src/NodeRenderer.h Normal file
View File

@ -0,0 +1,34 @@
#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

@ -4,8 +4,8 @@
#include "Base.h"
#ifndef TEXTURE_HANDLER
#define TEXTURE_HANDLER
//#ifndef TEXTURE_HANDLER
//#define TEXTURE_HANDLER
class TextureHandler
{
private:
@ -24,7 +24,7 @@ class TextureHandler
}
void loadAllTextures()
{
{/*
int textureIndex = 0;
imageData = loadTexture("data/img/texturemap.png");
@ -39,7 +39,6 @@ class TextureHandler
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);
@ -48,7 +47,7 @@ class TextureHandler
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData1);*/
}
void getTextureForNode(int x, int y, int z)
@ -56,16 +55,16 @@ class TextureHandler
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
if(blockManager.getNodeAt(x, y, z) == 1)
{
glBindTexture(GL_TEXTURE_2D, textures);
//glBindTexture(GL_TEXTURE_2D, textures);
}
else if(blockManager.getNodeAt(x, y, z) == 2)
{
glBindTexture(GL_TEXTURE_2D, textures1);
//glBindTexture(GL_TEXTURE_2D, textures1);
}
}
};
#endif
//#endif

0
src/XtreemNodes.h Normal file
View File

216
src/main.cpp Normal file
View File

@ -0,0 +1,216 @@
#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));
}

2
src/stb_image.cpp Normal file
View File

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