* WIP change
This commit is contained in:
parent
63dc5ae6b7
commit
d24d5357b8
8 changed files with 133 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,3 +6,5 @@ build*
|
|||
Makefile
|
||||
CMakeFiles
|
||||
cmake_install.cmake
|
||||
game/game
|
||||
tests/tests
|
||||
|
|
|
@ -8,12 +8,14 @@ find_package(X11 REQUIRED)
|
|||
set(GAME_SRC
|
||||
src/main.cpp
|
||||
src/opengl.cpp
|
||||
src/glclasses.cpp
|
||||
src/config.cpp
|
||||
src/simulation.cpp
|
||||
)
|
||||
|
||||
set(GAME_HEADERS
|
||||
include/opengl.h
|
||||
include/glclasses.h
|
||||
include/vector.h
|
||||
include/config.h
|
||||
include/simulation.h
|
||||
|
|
35
KKK/game/include/glclasses.h
Normal file
35
KKK/game/include/glclasses.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
||||
template <GLenum T> class BufferObject {
|
||||
private:
|
||||
GLuint m_name;
|
||||
GLvoid* m_mappointer;
|
||||
protected:
|
||||
public:
|
||||
BufferObject();
|
||||
~BufferObject();
|
||||
void bind();
|
||||
void bind(GLuint index, GLintptr offset = 0, GLsizeiptr size = 0);
|
||||
void fill(GLenum usage, GLsizei size = 0, GLvoid* data = NULL);
|
||||
void subfill(GLintptr offset, GLsizei size, const GLvoid* data);
|
||||
void map(GLenum access);
|
||||
void unmap();
|
||||
};
|
||||
|
||||
typedef BufferObject<GL_ARRAY_BUFFER> VBO;
|
||||
typedef BufferObject<GL_ELEMENT_ARRAY_BUFFER> IBO;
|
||||
|
||||
class VAO {
|
||||
private:
|
||||
int[3] foo;
|
||||
|
||||
protected:
|
||||
public:
|
||||
VAO();
|
||||
~VAO();
|
||||
bind();
|
||||
fill(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride = 0, const GLvoid* pointer = NULL);
|
||||
}
|
12
KKK/game/include/renderer.h
Normal file
12
KKK/game/include/renderer.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
#include <epoxy/glx.h>
|
||||
|
||||
class Renderer {
|
||||
private:
|
||||
protected:
|
||||
public:
|
||||
Renderer();
|
||||
~Renderer();
|
||||
};
|
|
@ -1,10 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
|
||||
struct Vec2d
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
double length() {
|
||||
return sqrt(x*x + y*y);
|
||||
}
|
||||
double distance(Vec2d other) {
|
||||
Vec2d tmp = (*this - other);
|
||||
return tmp.length();
|
||||
}
|
||||
|
||||
Vec2d & operator+=(const Vec2d& rhs) {
|
||||
x+=rhs.x;
|
||||
y+=rhs.y;
|
||||
|
@ -49,3 +59,31 @@ struct Vec2d
|
|||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct Mat4d {
|
||||
std::array<double, 16> data;
|
||||
|
||||
const Mat4d operator*(const Mat4d& rhs) const {
|
||||
Mat4d result;
|
||||
result[0] = result[0]*rhs[0] + result[1]*result[5] + result[2]*result[9] + result[3]*result[13];
|
||||
result[1] = result[0]*rhs[1] + result[1]*result[6] + result[2]*result[10] + result[3]*result[14];
|
||||
result[2] = result[0]*rhs[2] + result[1]*result[7] + result[2]*result[11] + result[3]*result[15];
|
||||
result[3] = result[0]*rhs[3] + result[1]*result[8] + result[2]*result[12] + result[3]*result[16];
|
||||
|
||||
result[4] = result[4]*rhs[0] + result[5]*result[5] + result[6]*result[9] + result[7]*result[13];
|
||||
result[5] = result[4]*rhs[1] + result[5]*result[6] + result[6]*result[10] + result[7]*result[14];
|
||||
result[6] = result[4]*rhs[2] + result[5]*result[7] + result[6]*result[11] + result[7]*result[15];
|
||||
result[7] = result[4]*rhs[3] + result[5]*result[8] + result[6]*result[12] + result[7]*result[16];
|
||||
|
||||
result[8] = result[8]*rhs[0] + result[9]*result[5] + result[10]*result[9] + result[11]*result[13];
|
||||
result[9] = result[8]*rhs[1] + result[9]*result[6] + result[10]*result[10] + result[11]*result[14];
|
||||
result[10] = result[8]*rhs[2] + result[9]*result[7] + result[10]*result[11] + result[11]*result[15];
|
||||
result[11] = result[8]*rhs[3] + result[9]*result[8] + result[10]*result[12] + result[11]*result[16];
|
||||
|
||||
result[12] = result[12]*rhs[0] + result[13]*result[5] + result[14]*result[9] + result[15]*result[13];
|
||||
result[13] = result[12]*rhs[1] + result[13]*result[6] + result[14]*result[10] + result[15]*result[14];
|
||||
result[14] = result[12]*rhs[2] + result[13]*result[7] + result[14]*result[11] + result[15]*result[15];
|
||||
result[15] = result[12]*rhs[3] + result[13]*result[8] + result[14]*result[12] + result[15]*result[16];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
38
KKK/game/src/glclasses.cpp
Normal file
38
KKK/game/src/glclasses.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <include/glclasses.h>
|
||||
|
||||
#define TBufferObject_(pre, post) template <GLenum T> pre BufferObject<T>::post
|
||||
#define TBufferObject(...) TBufferObject_(__VA_ARGS__)
|
||||
|
||||
TBufferObject(, BufferObject)() {
|
||||
glGenBuffers(1, &m_name);
|
||||
}
|
||||
|
||||
TBufferObject(, ~BufferObject)() {
|
||||
glDeleteBuffers(1, m_name);
|
||||
}
|
||||
|
||||
TBufferObject(void, bind)() {
|
||||
glBindBuffer(T, m_name);
|
||||
}
|
||||
|
||||
TBufferObject(void, bind)(GLuint index, GLintptr offset, GLsizeiptr size) {
|
||||
//todo
|
||||
}
|
||||
|
||||
TBufferObject(void, fill)(GLenum usage, GLsizei size, GLvoid* data) {
|
||||
glBufferData(T, size, data, usage);
|
||||
}
|
||||
|
||||
TBufferObject(void, subfill)(GLintptr offset, GLsizei size, const GLvoid* data) {
|
||||
glBufferSubData(T, offset, size, data);
|
||||
}
|
||||
|
||||
TBufferObject(void, map)(GLenum access) {
|
||||
//todo
|
||||
}
|
||||
|
||||
TBufferObject(void, unmap)() {
|
||||
//todo
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +70,7 @@ endofthejedi::GLWindow::GLWindow(unsigned int width, unsigned int height)
|
|||
endofthejedi::GLWindow::~GLWindow() {
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXDestroyContext(m_display, m_glcontext);
|
||||
XFree(m_visualinfo);
|
||||
XDestroyWindow(m_display, m_window);
|
||||
XCloseDisplay(m_display);
|
||||
}
|
||||
|
|
5
KKK/game/src/renderer.cpp
Normal file
5
KKK/game/src/renderer.cpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <include/renderer.h>
|
||||
|
||||
Renderer::Renderer() {
|
||||
|
||||
}
|
Loading…
Reference in a new issue