| @@ -56,11 +56,14 @@ deushax/deushax | |||
| deushax/editor | |||
| monsterz/monsterz | |||
| test/testsuite | |||
| test/tutorial/tut01 | |||
| test/tutorial/tut02 | |||
| test/benchsuite | |||
| test/quad | |||
| test/sandbox | |||
| test/math/pi | |||
| test/math/poly | |||
| test/math/remez | |||
| test/xolotl/xolotl | |||
| tools/make-font | |||
| # Our data | |||
| @@ -327,6 +327,8 @@ AC_CONFIG_FILES( | |||
| src/Makefile | |||
| test/Makefile | |||
| test/math/Makefile | |||
| test/tutorial/Makefile | |||
| test/xolotl/Makefile | |||
| gfx/Makefile | |||
| gfx/font/Makefile | |||
| tools/Makefile | |||
| @@ -1,5 +1,5 @@ | |||
| SUBDIRS = math | |||
| SUBDIRS = math tutorial xolotl | |||
| AM_CPPFLAGS = -I$(top_srcdir)/src | |||
| @@ -0,0 +1,23 @@ | |||
| AM_CPPFLAGS = -I$(top_srcdir)/src | |||
| all-local: $(noinst_PROGRAMS) | |||
| test x$(MAKE_FSELF) = xno || make_fself tut01$(EXEEXT) tut01.self | |||
| test x$(MAKE_FSELF) = xno || make_fself tut02$(EXEEXT) tut01.self | |||
| CLEANFILES = $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \ | |||
| $(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ | |||
| $(noinst_PROGRAMS:%$(EXEEXT)=%.exe) | |||
| noinst_PROGRAMS = tut01 tut02 | |||
| tut01_SOURCES = tut01.cpp | |||
| tut01_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | |||
| tut01_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | |||
| tut01_DEPENDENCIES = $(top_builddir)/src/liblol.a | |||
| tut02_SOURCES = tut02.cpp | |||
| tut02_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | |||
| tut02_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | |||
| tut02_DEPENDENCIES = $(top_builddir)/src/liblol.a | |||
| @@ -0,0 +1,124 @@ | |||
| // | |||
| // Lol Engine - Triangle tutorial | |||
| // | |||
| // Copyright: (c) 2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include "core.h" | |||
| #include "lolgl.h" | |||
| #include "loldebug.h" | |||
| using namespace std; | |||
| using namespace lol; | |||
| #if USE_SDL && defined __APPLE__ | |||
| # include <SDL_main.h> | |||
| #endif | |||
| #if defined _WIN32 | |||
| # undef main /* FIXME: still needed? */ | |||
| #endif | |||
| class Triangle : public WorldEntity | |||
| { | |||
| public: | |||
| Triangle() | |||
| { | |||
| m_vertices[0] = vec2( 0.0, 0.8); | |||
| m_vertices[1] = vec2(-0.8, -0.8); | |||
| m_vertices[2] = vec2( 0.8, -0.8); | |||
| } | |||
| virtual void TickDraw(float deltams) | |||
| { | |||
| WorldEntity::TickDraw(deltams); | |||
| if (!m_ready) | |||
| { | |||
| m_shader = Shader::Create( | |||
| "#version 120\n" | |||
| "attribute vec2 coord2d;" | |||
| "void main(void) {" | |||
| " gl_Position = vec4(coord2d, 0.0, 1.0);" | |||
| "}", | |||
| "#version 120\n" | |||
| "void main(void) {" | |||
| " gl_FragColor[0] = 0.0;" | |||
| " gl_FragColor[1] = 0.0;" | |||
| " gl_FragColor[2] = 1.0;" | |||
| "}"); | |||
| m_attrib = m_shader->GetAttribLocation("coord2d"); | |||
| m_ready = true; | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| /* Method 1: store vertex buffer on the GPU memory */ | |||
| glGenBuffers(1, &m_vbo); | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
| glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices, | |||
| GL_STATIC_DRAW); | |||
| #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| /* Method 2: upload vertex information at each frame */ | |||
| #else | |||
| #endif | |||
| /* FIXME: this object never cleans up */ | |||
| } | |||
| m_shader->Bind(); | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
| glEnableVertexAttribArray(m_attrib); | |||
| glVertexAttribPointer(m_attrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | |||
| #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| /* Never used for now */ | |||
| glEnableVertexAttribArray(m_attrib); | |||
| glVertexAttribPointer(m_attrib, 2, GL_FLOAT, GL_FALSE, 0, m_vertices); | |||
| #else | |||
| glEnableClientState(GL_VERTEX_ARRAY); | |||
| glVertexPointer(3, GL_FLOAT, 0, m_vertices); | |||
| #endif | |||
| glDrawArrays(GL_TRIANGLES, 0, 3); | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| glDisableVertexAttribArray(m_attrib); | |||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | |||
| #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| /* Never used for now */ | |||
| glDisableVertexAttribArray(m_attrib); | |||
| #else | |||
| glDisableClientState(GL_VERTEX_ARRAY); | |||
| #endif | |||
| } | |||
| private: | |||
| vec2 m_vertices[3]; | |||
| Shader *m_shader; | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| GLuint m_vbo; | |||
| #endif | |||
| int m_attrib; | |||
| bool m_ready; | |||
| }; | |||
| int main() | |||
| { | |||
| Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); | |||
| new DebugFps(5, 5); | |||
| new Triangle(); | |||
| app.Run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -0,0 +1,196 @@ | |||
| // | |||
| // Lol Engine - Cube tutorial | |||
| // | |||
| // Copyright: (c) 2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include "core.h" | |||
| #include "lolgl.h" | |||
| #include "loldebug.h" | |||
| using namespace std; | |||
| using namespace lol; | |||
| #if USE_SDL && defined __APPLE__ | |||
| # include <SDL_main.h> | |||
| #endif | |||
| #if defined _WIN32 | |||
| # undef main /* FIXME: still needed? */ | |||
| #endif | |||
| class Cube : public WorldEntity | |||
| { | |||
| public: | |||
| Cube() | |||
| { | |||
| /* Front */ | |||
| m_vertices[0] = vec3(-1.0, -1.0, 1.0); | |||
| m_vertices[1] = vec3( 1.0, -1.0, 1.0); | |||
| m_vertices[2] = vec3( 1.0, 1.0, 1.0); | |||
| m_vertices[3] = vec3(-1.0, 1.0, 1.0); | |||
| /* Back */ | |||
| m_vertices[4] = vec3(-1.0, -1.0, -1.0); | |||
| m_vertices[5] = vec3( 1.0, -1.0, -1.0); | |||
| m_vertices[6] = vec3( 1.0, 1.0, -1.0); | |||
| m_vertices[7] = vec3(-1.0, 1.0, -1.0); | |||
| m_colors[0] = vec3(1.0, 0.0, 0.0); | |||
| m_colors[1] = vec3(0.0, 1.0, 0.0); | |||
| m_colors[2] = vec3(0.0, 0.0, 1.0); | |||
| m_colors[3] = vec3(1.0, 1.0, 1.0); | |||
| m_colors[4] = vec3(1.0, 0.0, 0.0); | |||
| m_colors[5] = vec3(0.0, 1.0, 0.0); | |||
| m_colors[6] = vec3(0.0, 0.0, 1.0); | |||
| m_colors[7] = vec3(1.0, 1.0, 1.0); | |||
| m_indices[0] = i16vec3(0, 1, 2); | |||
| m_indices[1] = i16vec3(2, 3, 0); | |||
| m_indices[2] = i16vec3(1, 5, 6); | |||
| m_indices[3] = i16vec3(6, 2, 1); | |||
| m_indices[4] = i16vec3(7, 6, 5); | |||
| m_indices[5] = i16vec3(5, 4, 7); | |||
| m_indices[6] = i16vec3(4, 0, 3); | |||
| m_indices[7] = i16vec3(3, 7, 4); | |||
| m_indices[8] = i16vec3(4, 5, 1); | |||
| m_indices[9] = i16vec3(1, 0, 4); | |||
| m_indices[10] = i16vec3(3, 2, 6); | |||
| m_indices[11] = i16vec3(6, 7, 3); | |||
| } | |||
| virtual void TickGame(float deltams) | |||
| { | |||
| real x(4.08f); x.print(); | |||
| WorldEntity::TickGame(deltams); | |||
| m_angle += deltams; | |||
| vec3 axis_y(0, 1, 0); | |||
| mat4 anim = mat4::rotate(m_angle * 0.0001f, axis_y); | |||
| mat4 model = mat4::translate(vec3(0, 0, -4)); | |||
| mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0)); | |||
| mat4 proj = mat4::perspective(M_PI / 4, 640.0f, 480.0f, -10.0f, 10.0f); | |||
| anim = mat4(1.0f); | |||
| model = mat4(1.0f); | |||
| view = mat4(1.0f); | |||
| m_matrix = proj * view * model * anim; | |||
| proj.printf(); | |||
| view.printf(); | |||
| model.printf(); | |||
| anim.printf(); | |||
| printf("\n"); | |||
| m_matrix.printf(); | |||
| printf("\n"); | |||
| m_vertices[0].printf(); | |||
| (m_matrix * vec4(m_vertices[0], 1)).printf(); | |||
| printf("\n"); | |||
| } | |||
| virtual void TickDraw(float deltams) | |||
| { | |||
| WorldEntity::TickDraw(deltams); | |||
| if (!m_ready) | |||
| { | |||
| m_shader = Shader::Create( | |||
| "#version 120\n" | |||
| "attribute vec3 coord3d;" | |||
| "attribute vec3 v_color;" | |||
| "uniform mat4 mvp;" | |||
| "varying vec3 f_color;" | |||
| "void main(void) {" | |||
| " gl_Position = mvp * vec4(coord3d, 1.0);" | |||
| " f_color = v_color;" | |||
| "}", | |||
| "#version 120\n" | |||
| "varying vec3 f_color;" | |||
| "void main(void) {" | |||
| " gl_FragColor = vec4(f_color, 1.0);" | |||
| " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);" | |||
| "}"); | |||
| m_coord = m_shader->GetAttribLocation("coord3d"); | |||
| m_color = m_shader->GetAttribLocation("v_color"); | |||
| m_mvp = m_shader->GetUniformLocation("mvp"); | |||
| m_ready = true; | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| /* Method 1: store vertex buffer on the GPU memory */ | |||
| glGenBuffers(1, &m_vbo); | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
| glBufferData(GL_ARRAY_BUFFER, sizeof(m_vertices), m_vertices, | |||
| GL_STATIC_DRAW); | |||
| glGenBuffers(1, &m_cbo); | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_cbo); | |||
| glBufferData(GL_ARRAY_BUFFER, sizeof(m_colors), m_colors, | |||
| GL_STATIC_DRAW); | |||
| glGenBuffers(1, &m_ibo); | |||
| glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | |||
| glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_indices), m_indices, | |||
| GL_STATIC_DRAW); | |||
| #else | |||
| #endif | |||
| /* FIXME: this object never cleans up */ | |||
| } | |||
| m_shader->Bind(); | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| glEnableVertexAttribArray(m_coord); | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | |||
| glVertexAttribPointer(m_coord, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||
| glEnableVertexAttribArray(m_color); | |||
| glBindBuffer(GL_ARRAY_BUFFER, m_cbo); | |||
| glVertexAttribPointer(m_color, 3, GL_FLOAT, GL_FALSE, 0, 0); | |||
| glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); | |||
| int size; | |||
| glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); | |||
| glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0); | |||
| glDisableVertexAttribArray(m_coord); | |||
| glDisableVertexAttribArray(m_color); | |||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | |||
| #else | |||
| glEnableClientState(GL_VERTEX_ARRAY); | |||
| glVertexPointer(3, GL_FLOAT, 0, m_vertices); | |||
| glDisableClientState(GL_VERTEX_ARRAY); | |||
| #endif | |||
| } | |||
| private: | |||
| float m_angle; | |||
| mat4 m_matrix; | |||
| vec3 m_vertices[8]; | |||
| vec3 m_colors[8]; | |||
| i16vec3 m_indices[12]; | |||
| Shader *m_shader; | |||
| #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ | |||
| GLuint m_vbo, m_cbo, m_ibo; | |||
| #endif | |||
| int m_coord, m_color, m_mvp; | |||
| bool m_ready; | |||
| }; | |||
| int main() | |||
| { | |||
| Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); | |||
| new DebugFps(5, 5); | |||
| new Cube(); | |||
| app.Run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| AM_CPPFLAGS = -I$(top_srcdir)/src | |||
| all-local: $(noinst_PROGRAMS) | |||
| test x$(MAKE_FSELF) = xno || make_fself xolotl$(EXEEXT) xolotl.self | |||
| CLEANFILES = $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \ | |||
| $(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ | |||
| $(noinst_PROGRAMS:%$(EXEEXT)=%.exe) | |||
| noinst_PROGRAMS = xolotl | |||
| xolotl_SOURCES = xolotl.cpp xolotl.h | |||
| xolotl_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ | |||
| xolotl_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ | |||
| xolotl_DEPENDENCIES = $(top_builddir)/src/liblol.a | |||
| @@ -0,0 +1,78 @@ | |||
| // | |||
| // Lol Engine - Xolotl algorithm test | |||
| // | |||
| // Copyright: (c) 2011 Soren Renner | |||
| // (c) 2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include "core.h" | |||
| #include "lolgl.h" | |||
| #include "loldebug.h" | |||
| using namespace std; | |||
| using namespace lol; | |||
| #if USE_SDL && defined __APPLE__ | |||
| # include <SDL_main.h> | |||
| #endif | |||
| #if defined _WIN32 | |||
| # undef main /* FIXME: still needed? */ | |||
| #endif | |||
| #include "xolotl.h" | |||
| class Xolotl : public WorldEntity | |||
| { | |||
| public: | |||
| Xolotl() | |||
| { | |||
| for(int i = 0; i < 2000; i++) { | |||
| float x = (i - 1000.0) / 100.0; | |||
| graph[i].x = x; | |||
| graph[i].y = sin(x * 10.0) / (1.0 + x * x); | |||
| } | |||
| } | |||
| virtual ~Xolotl() | |||
| { | |||
| } | |||
| virtual char const *GetName() { return "Xolotl"; } | |||
| virtual void TickGame(float deltams) | |||
| { | |||
| } | |||
| virtual void TickDraw(float deltams) | |||
| { | |||
| } | |||
| private: | |||
| vec2 graph[2000]; | |||
| }; | |||
| int main() | |||
| { | |||
| Application app("Xolotl", ivec2(640, 480), 60.0f); | |||
| /* Register some debug stuff */ | |||
| new DebugFps(5, 5); | |||
| Cell<3> c; | |||
| app.Run(); | |||
| return EXIT_SUCCESS; | |||
| } | |||
| @@ -0,0 +1,58 @@ | |||
| // | |||
| // Lol Engine - Xolotl algorithm test | |||
| // | |||
| // Copyright: (c) 2011 Soren Renner | |||
| // (c) 2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| using namespace lol; | |||
| struct Voxel | |||
| { | |||
| bool passable, lock, copymarker; | |||
| struct Voxel *imposter; | |||
| }; | |||
| struct MSV : public Voxel | |||
| { | |||
| }; | |||
| struct Ray | |||
| { | |||
| float theta, phi; | |||
| vec3 origin, xyz, dxyz, ddxyz, lxyz, popdelta; | |||
| struct Voxel *terminalvoxel; | |||
| bool terminate; | |||
| ivec3 counter; | |||
| int scale; | |||
| float length; | |||
| bool di, dj, dk, changed, traced, far; | |||
| int face; | |||
| vec3 normal, bloxnorm, corner; | |||
| int dtl; | |||
| }; | |||
| template <int M> struct Cell : public MSV | |||
| { | |||
| Voxel blox[M * M * M]; | |||
| vec3 bloxnorm[M * M * M]; | |||
| int m; | |||
| void Serp(Voxel v, Voxel w) | |||
| { | |||
| for (int i = 0; i < M; i++) | |||
| for (int j = 0; j < M; j++) | |||
| for (int k = 0; k < M; k++) | |||
| if ((i == M_2) + (j == M_2) + (k == M_2) >= 2) | |||
| blox[(i * M + j) * M + k] = v; | |||
| else | |||
| blox[(i * M + j) * M + k] = w; | |||
| } | |||
| static const int M_2 = M / 2; | |||
| }; | |||