83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "TestTriangle.h"
|
|
#include "modules/WindowModule/WindowModule.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() {
|
|
}
|