add crosshair

blockgen with sin
This commit is contained in:
2022-02-10 18:24:56 +01:00
parent 68f28a3294
commit 360a1cc79d
12 changed files with 93 additions and 26 deletions

18
blocks/AirBlock.h Normal file
View File

@ -0,0 +1,18 @@
//
// Created by lukas on 08.02.22.
//
#ifndef OPENGLTEST_AIRBLOCK_H
#define OPENGLTEST_AIRBLOCK_H
#include "BaseBlock.h"
class AirBlock : public BaseBlock{
public:
AirBlock(uint xpos, uint ypos, uint zpos) : BaseBlock(xpos, ypos, zpos, nullptr) {}
void render() override {
}
};
#endif //OPENGLTEST_AIRBLOCK_H

View File

@ -2,9 +2,6 @@
// Created by lukas on 04.02.22.
//
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <cstdlib>
#include <glm/ext/matrix_float4x4.hpp>
#include <glm/ext/matrix_transform.hpp>
@ -12,6 +9,8 @@
#include "BlockRenderer.h"
void BaseBlock::render() {
BlockRenderer::getInstance()->s.Bind();
glm::mat4 position = glm::translate(glm::mat4(1.0f), glm::vec3((float) xpos * 2, (float) ypos * 2, (float) zpos * 2));
glUniformMatrix4fv(BlockRenderer::getInstance()->getUniformhandle("translation"), 1, GL_FALSE, &position[0][0]);

View File

@ -8,6 +8,8 @@
#include "BlockRenderer.h"
#include "../gl/Texture.h"
#include <glm/ext/matrix_float4x4.hpp>
#include <glm/ext/matrix_transform.hpp>
class BaseBlock {
private:
@ -17,7 +19,7 @@ private:
public:
BaseBlock(uint xpos, uint ypos, uint zpos, Texture *texture);
void render();
virtual void render();
};

View File

@ -14,6 +14,12 @@ template<class T>
class RenderBase {
private:
static RenderBase *instance;
protected:
RenderBase() {
if (instance) throw std::logic_error("Instance already exists");
instance = this;
}
public:
virtual VertexArray *setVertexArray() = 0;
@ -23,11 +29,10 @@ public:
static RenderBase *getInstance() {
if (instance == nullptr) {
instance = new T();
new T();
instance->init();
}
return instance;
}
public:
@ -37,9 +42,9 @@ public:
Shader s;
public:
RenderBase() {};
void render() {
virtual void render() {
r.render(*va, *ib, s);
}
@ -49,7 +54,9 @@ public:
ib = setIndexBuffer();
}
void deinit() {}
void deinit() {
glDeleteProgram(s.getHandle());
}
unsigned getMVPhandle() {
return s.getUniformHandle("MVP");