Uses moggle now
This commit is contained in:
parent
9cf9887a09
commit
9e6a51a844
6 changed files with 54 additions and 56 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
build*
|
||||||
|
*.user
|
||||||
|
|
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -7,3 +7,6 @@
|
||||||
[submodule "contrib/ImageStreams"]
|
[submodule "contrib/ImageStreams"]
|
||||||
path = contrib/ImageStreams
|
path = contrib/ImageStreams
|
||||||
url = ../ImageStreams/
|
url = ../ImageStreams/
|
||||||
|
[submodule "contrib/moggle"]
|
||||||
|
path = contrib/moggle
|
||||||
|
url = ../moggle/
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
add_subdirectory("NSAppWrapper")
|
add_subdirectory("NSAppWrapper")
|
||||||
add_subdirectory("CLWrapper")
|
add_subdirectory("CLWrapper")
|
||||||
add_subdirectory("ImageStreams")
|
add_subdirectory("ImageStreams")
|
||||||
|
add_subdirectory("moggle")
|
||||||
|
|
1
contrib/moggle
Submodule
1
contrib/moggle
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit bb8a9ab41750803845dfc540b183d2647e2da8e8
|
|
@ -3,7 +3,7 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
file(GLOB sources "*.cpp")
|
file(GLOB sources "*.cpp")
|
||||||
|
|
||||||
set(libs ${JCLWrapper_LIBRARIES} ${JNSAppWrapper_LIBRARIES} ${ImageStreams_LIBRARIES})
|
set(libs ${JCLWrapper_LIBRARIES} ${JNSAppWrapper_LIBRARIES} ${ImageStreams_LIBRARIES} moggle_xxx)
|
||||||
message(STATUS "Linking against the following libraries: ${libs}")
|
message(STATUS "Linking against the following libraries: ${libs}")
|
||||||
|
|
||||||
foreach(source ${sources})
|
foreach(source ${sources})
|
||||||
|
|
100
src/main.cpp
100
src/main.cpp
|
@ -3,6 +3,11 @@
|
||||||
#include <NSWrapper.hpp>
|
#include <NSWrapper.hpp>
|
||||||
#include <png.hpp>
|
#include <png.hpp>
|
||||||
|
|
||||||
|
#include <moggle/core/gl.hpp>
|
||||||
|
#include <moggle/core/shader.hpp>
|
||||||
|
#include <moggle/core/vao.hpp>
|
||||||
|
#include <moggle/core/vbo.hpp>
|
||||||
|
|
||||||
#include <OpenGL/gl3.h>
|
#include <OpenGL/gl3.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -16,12 +21,17 @@ using namespace std;
|
||||||
|
|
||||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||||
|
|
||||||
const GLfloat quad[] = {
|
struct Vertex{
|
||||||
|
moggle::vector3<GLfloat> position;
|
||||||
|
moggle::vector3<GLfloat> color;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Vertex quad[] = {
|
||||||
// x y z, r g b
|
// x y z, r g b
|
||||||
1, -1, 0, 1, 0, 0,
|
{{1, -1, 0}, {1, 0, 0}},
|
||||||
-1, -1, 0, 0, 1, 0,
|
{{-1, -1, 0}, {0, 1, 0}},
|
||||||
1, 1, 0, 0, 0, 1,
|
{{1, 1, 0}, {0, 0, 1}},
|
||||||
-1, 1, 0, 1, 1, 1
|
{{-1, 1, 0}, {1, 1, 1}}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void check_shader(GLuint s){
|
static void check_shader(GLuint s){
|
||||||
|
@ -43,70 +53,50 @@ string slurp(string filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
float time;
|
float time = 0;
|
||||||
GLuint program;
|
moggle::shader_program program;
|
||||||
GLint uniform;
|
moggle::vao v;
|
||||||
GLuint vao;
|
moggle::vbo<Vertex> quad_vbo;
|
||||||
GLuint posBufferName;
|
|
||||||
|
enum {
|
||||||
|
POS_ATTR,
|
||||||
|
COL_ATTR
|
||||||
|
};
|
||||||
|
|
||||||
void initialize(){
|
void initialize(){
|
||||||
time = 0;
|
auto vs = moggle::shader::from_file(moggle::shader_type::vertex, "Fractal.vsh");
|
||||||
program = glCreateProgram();
|
auto fs = moggle::shader::from_file(moggle::shader_type::fragment, "Fractal.fsh");
|
||||||
|
|
||||||
auto v_source_str = slurp("Fractal.vsh");
|
program.attach(vs);
|
||||||
auto v_source = v_source_str.c_str();
|
program.attach(fs);
|
||||||
GLuint v = glCreateShader(GL_VERTEX_SHADER);
|
|
||||||
glShaderSource(v, 1, &v_source, NULL);
|
|
||||||
glCompileShader(v);
|
|
||||||
check_shader(v);
|
|
||||||
|
|
||||||
auto f_source_str = slurp("Fractal.fsh");
|
program.bind_attribute(POS_ATTR, "position");
|
||||||
auto f_source = f_source_str.c_str();
|
program.bind_attribute(COL_ATTR, "color");
|
||||||
GLuint f = glCreateShader(GL_FRAGMENT_SHADER);
|
|
||||||
glShaderSource(f, 1, &f_source, NULL);
|
|
||||||
glCompileShader(f);
|
|
||||||
check_shader(f);
|
|
||||||
|
|
||||||
glAttachShader(program, v);
|
program.link();
|
||||||
glAttachShader(program, f);
|
|
||||||
|
|
||||||
glBindAttribLocation(program, 0, "position");
|
v.bind();
|
||||||
glBindAttribLocation(program, 1, "color");
|
quad_vbo.bind(GL_ARRAY_BUFFER);
|
||||||
|
quad_vbo.data(quad);
|
||||||
|
|
||||||
glLinkProgram(program);
|
moggle::gl::enable_vertex_attribute_array(POS_ATTR);
|
||||||
|
moggle::gl::enable_vertex_attribute_array(COL_ATTR);
|
||||||
|
|
||||||
uniform = glGetUniformLocation(program, "rotation");
|
v.attribute(POS_ATTR, quad_vbo, &Vertex::position);
|
||||||
|
v.attribute(COL_ATTR, quad_vbo, &Vertex::color);
|
||||||
glDetachShader(program, v);
|
|
||||||
glDeleteShader(v);
|
|
||||||
glDetachShader(program, f);
|
|
||||||
glDeleteShader(f);
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glGenBuffers(1, &posBufferName);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, posBufferName);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, 4*6*4, quad, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*4, BUFFER_OFFSET(0));
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*4, BUFFER_OFFSET(3*4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(){
|
void draw(){
|
||||||
time += 1/60.0f;
|
time += 1/60.0f;
|
||||||
|
|
||||||
glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
|
moggle::gl::clear_color(0.65f, 0.65f, 0.65f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(program);
|
program.use();
|
||||||
glUniform1f(uniform, time);
|
program.uniform<GLfloat>("rotation").set(time);
|
||||||
glBindVertexArray(vao);
|
v.bind();
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
moggle::gl::draw_arrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -195,7 +185,7 @@ int main() {
|
||||||
app.create_window({
|
app.create_window({
|
||||||
[&](ContextParameters){
|
[&](ContextParameters){
|
||||||
a.initialize();
|
a.initialize();
|
||||||
b.initialize();
|
// b.initialize();
|
||||||
},
|
},
|
||||||
[&](ContextParameters){
|
[&](ContextParameters){
|
||||||
a.draw();
|
a.draw();
|
||||||
|
|
Reference in a new issue