110 lines
2.0 KiB
C++
110 lines
2.0 KiB
C++
//
|
|
// Created by lukas on 05.02.22.
|
|
//
|
|
|
|
#include "BlockRenderer.h"
|
|
#include "../gl/Texture.h"
|
|
|
|
#define GL_GLEXT_PROTOTYPES
|
|
|
|
#include <GL/gl.h>
|
|
|
|
VertexArray *BlockRenderer::setVertexArray() {
|
|
float cubee[] = {
|
|
// face #1
|
|
1, 1, 1, 1, 0,
|
|
-1, 1, 1, 1, 1,
|
|
-1, -1, 1, 0, 1,
|
|
1, -1, 1, 0, 0,
|
|
|
|
// face #2
|
|
1, 1, 1, 1, 0,
|
|
1, -1, 1, 1, 1,
|
|
1, -1, -1, 0, 1,
|
|
1, 1, -1, 0, 0,
|
|
|
|
// face #3
|
|
1, 1, 1, 1, 0,
|
|
1, 1, -1, 1, 1,
|
|
-1, 1, -1, 0, 1,
|
|
-1, 1, 1, 0, 0,
|
|
|
|
// face #4
|
|
-1, -1, -1, 1, 0,
|
|
-1, 1, -1, 1, 1,
|
|
1, 1, -1, 0, 1,
|
|
1, -1, -1, 0, 0,
|
|
|
|
// face #5
|
|
-1, -1, -1, 1, 0,
|
|
-1, -1, 1, 1, 1,
|
|
-1, 1, 1, 0, 1,
|
|
-1, 1, -1, 0, 0,
|
|
|
|
// face #6
|
|
-1, -1, -1, 1, 0,
|
|
1, -1, -1, 1, 1,
|
|
1, -1, 1, 0, 1,
|
|
-1, -1, 1, 0, 0,};
|
|
|
|
// Generate a vertex buffer
|
|
auto *vb = new VertexBuffer(cubee, sizeof(cubee));
|
|
auto *va = new VertexArray(*vb);
|
|
va->add(0,3,5,0);
|
|
va->add(1,2,5,12);
|
|
|
|
return va;
|
|
}
|
|
|
|
IndexBuffer *BlockRenderer::setIndexBuffer() {
|
|
unsigned indexx[] = {
|
|
0, 1, 2,
|
|
2, 3, 0,
|
|
|
|
4, 5, 6,
|
|
6, 7, 4,
|
|
|
|
8, 9, 10,
|
|
10, 11, 8,
|
|
|
|
12, 13, 14,
|
|
14, 15, 12,
|
|
|
|
16, 17, 18,
|
|
18, 19, 16,
|
|
|
|
20, 21, 22,
|
|
22, 23, 20,
|
|
|
|
24, 25, 26,
|
|
26, 27, 24,
|
|
|
|
28, 29, 30,
|
|
30, 31, 28
|
|
};
|
|
|
|
return new IndexBuffer(indexx, 48);
|
|
}
|
|
|
|
Shader BlockRenderer::setShader() {
|
|
const std::string vertsrc =
|
|
|
|
#include "vertex.shader"
|
|
|
|
const std::string geosrc =
|
|
|
|
#include "geometry.shader"
|
|
|
|
const std::string fragsrc =
|
|
|
|
#include "fragment.shader"
|
|
|
|
Shader s;
|
|
s.loadShader(vertsrc, geosrc, fragsrc);
|
|
s.Bind();
|
|
|
|
return s;
|
|
}
|
|
|
|
BlockRenderer::BlockRenderer() {}
|