add triangle test
This commit is contained in:
82
modules/Archimedes-Modules/TestTriangle/TestTriangle.cpp
Normal file
82
modules/Archimedes-Modules/TestTriangle/TestTriangle.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include "TestTriangle.h"
|
||||||
|
#include "modules/ImguiModule/ImguiModule.h"
|
||||||
|
|
||||||
|
#define GLEW_STATIC
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
TestTriangle::TestTriangle(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||||
|
|
||||||
|
name = "TestTriangle";
|
||||||
|
|
||||||
|
WindowModule* wm = new WindowModule(a, h);
|
||||||
|
deps[*wm] = wm;
|
||||||
|
}
|
||||||
|
|
||||||
|
TestTriangle::~TestTriangle() {
|
||||||
|
|
||||||
|
if(app) {
|
||||||
|
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||||
|
|
||||||
|
|
||||||
|
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||||
|
|
||||||
|
wm->releaseWindow(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTriangle::onLoad() {
|
||||||
|
|
||||||
|
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||||
|
|
||||||
|
if(!wm) {
|
||||||
|
std::cout << "No WindowModule for TestTriangle!\n";
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
window = wm->aquireWindow();
|
||||||
|
|
||||||
|
wm->getRenderer()->getCmdList().push_back([this](){
|
||||||
|
// 0. copy our vertices array in a buffer for OpenGL to use
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
// 1. then set the vertex attributes pointers
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
// 2. use our shader program when we want to render an object
|
||||||
|
glUseProgram(program);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
// 3. now draw the object
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
|
||||||
|
glGenBuffers(1, &vbo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
|
||||||
|
vs = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
glShaderSource(vs, 1, &vertexShaderSource, NULL);
|
||||||
|
glCompileShader(vs);
|
||||||
|
|
||||||
|
fs = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
glShaderSource(fs, 1, &fragShaderSource, NULL);
|
||||||
|
glCompileShader(fs);
|
||||||
|
|
||||||
|
program = glCreateProgram();
|
||||||
|
|
||||||
|
glAttachShader(program, vs);
|
||||||
|
glAttachShader(program, fs);
|
||||||
|
glLinkProgram(program);
|
||||||
|
|
||||||
|
glDeleteShader(vs);
|
||||||
|
glDeleteShader(fs);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestTriangle::run() {
|
||||||
|
}
|
||||||
54
modules/Archimedes-Modules/TestTriangle/TestTriangle.h
Normal file
54
modules/Archimedes-Modules/TestTriangle/TestTriangle.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "Archimedes.h"
|
||||||
|
|
||||||
|
#include "modules/WindowModule/WindowModule.h"
|
||||||
|
|
||||||
|
class TestTriangle : public Archimedes::Module {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TestTriangle(Archimedes::App*, void*);
|
||||||
|
|
||||||
|
TestTriangle() { name = "TestTriangle"; }
|
||||||
|
|
||||||
|
~TestTriangle();
|
||||||
|
|
||||||
|
void onLoad();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Archimedes::Window* window;
|
||||||
|
|
||||||
|
std::list<std::function<void()>>::iterator rcmd_it;
|
||||||
|
|
||||||
|
float vertices[3 * 3] = {
|
||||||
|
0.5, 0.5, 0.0,
|
||||||
|
0.5, 0.5, 0.0,
|
||||||
|
0.0, 0.5, 0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int vao, vbo, vs, fs, program;
|
||||||
|
int success;
|
||||||
|
|
||||||
|
const char *vertexShaderSource =
|
||||||
|
"#version 330 core\n"
|
||||||
|
"layout (location = 0) in vec3 aPos;\n"
|
||||||
|
"void main() {\n"
|
||||||
|
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||||
|
"}\0";
|
||||||
|
|
||||||
|
const char *fragShaderSource =
|
||||||
|
"#version 330 core\n"
|
||||||
|
"out vec4 FragColor;\n"
|
||||||
|
"void main() {\n"
|
||||||
|
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||||
|
"}\0";
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef TESTTRIANGLE_DYNAMIC
|
||||||
|
typedef TestTriangle mtype;
|
||||||
|
#include "endModule.h"
|
||||||
|
#endif
|
||||||
@@ -96,26 +96,6 @@ void ImguiModule::onLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ImguiModule::onEvent(const Archimedes::Event &e) {
|
bool ImguiModule::onEvent(const Archimedes::Event &e) {
|
||||||
/*
|
|
||||||
#if WINDOW == 2
|
|
||||||
if(e.userData != nullptr) {
|
|
||||||
unsigned int type = app->getEventType(e);
|
|
||||||
|
|
||||||
if(type == app->getEventType(Archimedes::ResizeWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::CloseWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::KeyPressedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::KeyReleasedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::ScrollWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::MouseMovedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::FocusedWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::FocusLostWindowEvent())
|
|
||||||
|| type == app->getEventType(Archimedes::MovedWindowEvent())) {
|
|
||||||
ImGui_ImplSDL3_ProcessEvent((SDL_Event*) e.userData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user