CMake build added. Basic OpenGL 3.3 Mesh Rendering
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
#ifndef BASE
|
||||
#define BASE
|
||||
|
||||
//#include "NodeRenderer.h"
|
||||
//#include "MapBlock.h"
|
||||
|
||||
class NodeManager;
|
||||
class BlockManager;
|
||||
|
||||
extern NodeManager nodeManager;
|
||||
extern BlockManager blockManager;
|
||||
|
||||
|
||||
struct Position2D
|
||||
{
|
||||
int x;
|
||||
int z;
|
||||
};
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
@@ -1,18 +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
|
||||
@@ -1,11 +0,0 @@
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
void log(char* comp, char* message);
|
||||
{
|
||||
printf("Message: %c", message);
|
||||
}
|
||||
};
|
||||
@@ -1,33 +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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
@@ -1,71 +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
|
||||
@@ -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
|
||||
7898
include/stb_image.h
7898
include/stb_image.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user