sandbox
This commit is contained in:
161
modules/Archimedes-Modules/Sandbox/Sandbox.h
Normal file
161
modules/Archimedes-Modules/Sandbox/Sandbox.h
Normal file
@@ -0,0 +1,161 @@
|
||||
// This only works with opengl!!!!
|
||||
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/WindowModule/WindowModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
class Sandbox : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Sandbox(Archimedes::App*, void*);
|
||||
|
||||
Sandbox() { name = "Sandbox"; }
|
||||
|
||||
~Sandbox();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event& e) override;
|
||||
|
||||
private:
|
||||
|
||||
Archimedes::Window* window;
|
||||
|
||||
std::string cubeVS = "#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform uvec2 res;\n"
|
||||
"uniform vec4 clearColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = model * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
"}\0";
|
||||
std::string cubeFS = "#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform uvec2 res;\n"
|
||||
"uniform vec4 clearColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = vec4(0.6f, 0.1f, 0.1f, 1.0f);\n"
|
||||
"}\n\0";
|
||||
|
||||
std::string gridFS = "#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform uvec2 res;\n"
|
||||
"uniform vec4 clearColor;\n"
|
||||
"vec2 pos = gl_FragCoord.xy - res / 2.0f;\n"
|
||||
"int gridSpacing = 50;"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" switch((int(pos.x)) * (int(pos.y))) {\n"
|
||||
" case 0:\n"
|
||||
" FragColor = vec4(1.0f);\n"
|
||||
" break;\n"
|
||||
" default:\n"
|
||||
" switch((int(pos.x) % gridSpacing) * (int(pos.y) % gridSpacing)) {\n"
|
||||
" case 0:\n"
|
||||
" FragColor = vec4(0.7f, 0.7f, 0.7f, 1.0f);\n"
|
||||
" break;\n"
|
||||
" default:\n"
|
||||
" discard;\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
"}\n\0";
|
||||
|
||||
Archimedes::Shader cubeShader, gridShader;
|
||||
Archimedes::RenderTarget cube, grid;
|
||||
|
||||
float gridVertices[24] = {
|
||||
-1.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, -1.0f,
|
||||
-1.0f, 0.0f, -1.0f,
|
||||
};
|
||||
|
||||
unsigned int gridIndices[6] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0
|
||||
};
|
||||
|
||||
float vertices[24] = {
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
|
||||
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
|
||||
};
|
||||
|
||||
unsigned int indices[36] = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
|
||||
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
4,
|
||||
|
||||
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
5,
|
||||
4,
|
||||
0,
|
||||
|
||||
|
||||
3,
|
||||
2,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
3,
|
||||
|
||||
|
||||
0,
|
||||
3,
|
||||
7,
|
||||
7,
|
||||
4,
|
||||
0,
|
||||
|
||||
|
||||
1,
|
||||
2,
|
||||
6,
|
||||
6,
|
||||
5,
|
||||
1,
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#ifdef SANDBOX_DYNAMIC
|
||||
typedef Sandbox mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
Reference in New Issue
Block a user