diff --git a/Makefile b/Makefile index 44de762..b94ddea 100644 --- a/Makefile +++ b/Makefile @@ -73,19 +73,19 @@ endef %.glsl.o: %.glsl $(BUILD_BINARY_O) -include/shader/%.glsl.h: src/shader/%.glsl +include/%.glsl.h: src/%.glsl $(BUILD_BINARY_H) %.data.o: %.data $(BUILD_BINARY_O) -include/level/%.data.h: src/level/%.data +include/%.data.h: src/%.data $(BUILD_BINARY_H) %.data.pal.o: %.data.pal $(BUILD_BINARY_O) -include/level/%.data.pal.h: src/level/%.data.pal +include/%.data.pal.h: src/%.data.pal $(BUILD_BINARY_H) clean: @@ -104,8 +104,10 @@ MAIN_OBJS = \ src/opengl.o \ src/render.o \ src/collision.o \ + src/update.o \ $(patsubst %.glsl,%.glsl.o,$(wildcard src/shader/*.glsl)) \ $(patsubst %.data,%.data.o,$(wildcard src/level/*.data)) \ + $(patsubst %.data,%.data.o,$(wildcard src/font/*.data)) \ $(patsubst %.data.pal,%.data.pal.o,$(wildcard src/level/*.data.pal)) \ $(GLFW) diff --git a/blend/block.blend b/blend/block.blend index 9931975..241d904 100644 Binary files a/blend/block.blend and b/blend/block.blend differ diff --git a/blend/plane.blend b/blend/plane.blend new file mode 100644 index 0000000..40bacd1 Binary files /dev/null and b/blend/plane.blend differ diff --git a/include/font/ter_u32n.data.h b/include/font/ter_u32n.data.h new file mode 100644 index 0000000..0709d3f --- /dev/null +++ b/include/font/ter_u32n.data.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_src_font_ter_u32n_data_start __asm("_binary_src_font_ter_u32n_data_start"); +extern uint32_t _binary_src_font_ter_u32n_data_end __asm("_binary_src_font_ter_u32n_data_end"); +extern uint32_t _binary_src_font_ter_u32n_data_size __asm("_binary_src_font_ter_u32n_data_size"); + +#define src_font_ter_u32n_data_start ((const char *)&_binary_src_font_ter_u32n_data_start) +#define src_font_ter_u32n_data_end ((const char *)&_binary_src_font_ter_u32n_data_end) +#define src_font_ter_u32n_data_size (src_font_ter_u32n_data_end - src_font_ter_u32n_data_start) + +#ifdef __cplusplus +} +#endif diff --git a/include/math/transform.hpp b/include/math/transform.hpp index f36cba0..34c7ed4 100644 --- a/include/math/transform.hpp +++ b/include/math/transform.hpp @@ -149,7 +149,7 @@ template inline constexpr T inverse_length(vec<3, T> v) { float f = dot(v, v); - return 1.0f / sqrt(f); + return 1.0f / sqrt(f); } template diff --git a/include/math/vec.hpp b/include/math/vec.hpp index 83699a6..3e4e704 100644 --- a/include/math/vec.hpp +++ b/include/math/vec.hpp @@ -23,7 +23,7 @@ inline constexpr vec normalize(vec const& v) } template -inline constexpr vec<3, T> reflect(vec const& i, vec const& n) +inline constexpr vec reflect(vec const& i, vec const& n) { return i - dot(n, i) * n * static_cast(2.0); } diff --git a/include/model/plane.h b/include/model/plane.h new file mode 100644 index 0000000..eb22c53 --- /dev/null +++ b/include/model/plane.h @@ -0,0 +1,18 @@ +#pragma once + +const int plane_Plane_triangles[] = { + 0, 1, 2, + 0, 3, 1, +}; + +const int plane_Plane_triangles_length = (sizeof (plane_Plane_triangles)) / (sizeof (plane_Plane_triangles[0])); + +const float plane_vertices[] = { + 1.000000f, 0.000000f, 1.000000f, 1.000000f, 0.000000f, -0.0000f, 1.0000f, -0.0000f, + -1.000000f, 0.000000f, -1.000000f, 0.000000f, 1.000000f, -0.0000f, 1.0000f, -0.0000f, + -1.000000f, 0.000000f, 1.000000f, 0.000000f, 0.000000f, -0.0000f, 1.0000f, -0.0000f, + 1.000000f, 0.000000f, -1.000000f, 1.000000f, 1.000000f, -0.0000f, 1.0000f, -0.0000f, +}; + +const int plane_vertices_length = (sizeof (plane_vertices)) / (sizeof (plane_vertices[0])); + diff --git a/include/model/plane.obj b/include/model/plane.obj new file mode 100644 index 0000000..09b6d6a --- /dev/null +++ b/include/model/plane.obj @@ -0,0 +1,16 @@ +# Blender 4.4.3 +# www.blender.org +mtllib plane.mtl +o Plane +v -1.000000 0.000000 1.000000 +v 1.000000 0.000000 1.000000 +v -1.000000 0.000000 -1.000000 +v 1.000000 0.000000 -1.000000 +vn -0.0000 1.0000 -0.0000 +vt 1.000000 0.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vt 1.000000 1.000000 +s 0 +f 2/1/1 3/2/1 1/3/1 +f 2/1/1 4/4/1 3/2/1 diff --git a/include/render.hpp b/include/render.hpp index 8d8986e..0d82edc 100644 --- a/include/render.hpp +++ b/include/render.hpp @@ -26,6 +26,13 @@ extern "C" { uint uniform_light_pos, struct game_state * state); + void render_font(struct mesh plane_mesh, + uint attrib_position, + uint attrib_texture, + uint attrib_normal, + uint uniform_trans, + uint uniform_texture0); + #ifdef __cplusplus } #endif diff --git a/include/shader/font.fp.glsl.h b/include/shader/font.fp.glsl.h new file mode 100644 index 0000000..cc18a75 --- /dev/null +++ b/include/shader/font.fp.glsl.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_src_shader_font_fp_glsl_start __asm("_binary_src_shader_font_fp_glsl_start"); +extern uint32_t _binary_src_shader_font_fp_glsl_end __asm("_binary_src_shader_font_fp_glsl_end"); +extern uint32_t _binary_src_shader_font_fp_glsl_size __asm("_binary_src_shader_font_fp_glsl_size"); + +#define src_shader_font_fp_glsl_start ((const char *)&_binary_src_shader_font_fp_glsl_start) +#define src_shader_font_fp_glsl_end ((const char *)&_binary_src_shader_font_fp_glsl_end) +#define src_shader_font_fp_glsl_size (src_shader_font_fp_glsl_end - src_shader_font_fp_glsl_start) + +#ifdef __cplusplus +} +#endif diff --git a/include/shader/font.vp.glsl.h b/include/shader/font.vp.glsl.h new file mode 100644 index 0000000..ff038fd --- /dev/null +++ b/include/shader/font.vp.glsl.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_src_shader_font_vp_glsl_start __asm("_binary_src_shader_font_vp_glsl_start"); +extern uint32_t _binary_src_shader_font_vp_glsl_end __asm("_binary_src_shader_font_vp_glsl_end"); +extern uint32_t _binary_src_shader_font_vp_glsl_size __asm("_binary_src_shader_font_vp_glsl_size"); + +#define src_shader_font_vp_glsl_start ((const char *)&_binary_src_shader_font_vp_glsl_start) +#define src_shader_font_vp_glsl_end ((const char *)&_binary_src_shader_font_vp_glsl_end) +#define src_shader_font_vp_glsl_size (src_shader_font_vp_glsl_end - src_shader_font_vp_glsl_start) + +#ifdef __cplusplus +} +#endif diff --git a/include/update.hpp b/include/update.hpp new file mode 100644 index 0000000..3f2b825 --- /dev/null +++ b/include/update.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "state.h" + +#ifdef __cplusplus +extern "C" { +#endif + + void update(struct game_state * state); + +#ifdef __cplusplus +} +#endif diff --git a/rebuild_models.sh b/rebuild_models.sh index c0279e8..d3c7a75 100644 --- a/rebuild_models.sh +++ b/rebuild_models.sh @@ -6,5 +6,6 @@ python ~/model_generator2/generate_indexed_cpp2.py paddle.obj paddle > paddle.h python ~/model_generator2/generate_indexed_cpp2.py block.obj block > block.h python ~/model_generator2/generate_indexed_cpp2.py ball.obj ball > ball.h python ~/model_generator2/generate_indexed_cpp2.py cube.obj cube > cube.h +python ~/model_generator2/generate_indexed_cpp2.py plane.obj plane > plane.h rm -f *.mtl diff --git a/src/collision.cpp b/src/collision.cpp index 25eb461..632be77 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -1,4 +1,5 @@ #include +#include #include "collision.hpp" @@ -51,8 +52,8 @@ vec2 _t0_t1(float signed_distance, t0 = t1; t1 = tmp; } - t0 = clamp(t0, 0.0, 1.0); - t1 = clamp(t0, 0.0, 1.0); + t0 = clamp(t0, -1.0, 1.0); + t1 = clamp(t0, -1.0, 1.0); return vec2(t0, t1); } } @@ -76,14 +77,96 @@ bool point_in_triangle(vec3 point, float y = (e * a) - (d * b); float z = x + y - ((a * c) - (b * b)); - return (z < 0) and not ((x < 0) or (y < 0)); + return (z < 0) && !((x < 0) || (y < 0)); } -vec2 collision_inner(vec3 plane_normal, - vec3 a, vec3 b, vec3 c, - vec3 point, - vec3 velocity) +struct ct { + bool collision; + float t; +}; + +#define NONE -99999999.0f + +ct lowest_root(float a, + float b, + float c, + float max_r) { + float determinant = b * b - 4.0f * a * c; + if (determinant < 0.0f) + return ct(false, max_r); + + float sqrt_det = sqrtf(determinant); + float r_2a = 1.0f / (2.0f * a); + float r1 = (-b - sqrt_det) * r_2a; + float r2 = (-b + sqrt_det) * r_2a; + if (r1 > r2) { + float tmp = r1; + r1 = r2; + r2 = tmp; + } + if (r1 > 0 && (max_r == NONE || r1 < max_r)) + return ct(true, r1); + if (r2 > 0 && (max_r == NONE || r2 < max_r)) + return ct(true, r2); + return ct(false, max_r); +} + +ct triangle_point_collide(vec3 tri_point, + vec3 point, + vec3 velocity, + float t) +{ + float a = dot(velocity, velocity); + float b = 2.0f * dot(velocity, point - tri_point); + vec3 c0 = (tri_point - point); + float c = dot(c0, c0) - 1.0f; + return lowest_root(a, b, c, t); +} + +struct ctf0 { + bool collision; + float t; + float f0; +}; + +ctf0 triangle_edge_collide(vec3 tri_point1, + vec3 tri_point2, + vec3 point, + vec3 velocity, + float t) +{ + vec3 edge = tri_point2 - tri_point1; + vec3 base = tri_point1 - point; + + float edge_dot_edge = dot(edge, edge); + float edge_dot_velocity = dot(edge, velocity); + float edge_dot_base = dot(edge, base); + float velocity_dot_velocity = dot(velocity, velocity); + + float a = edge_dot_edge * -velocity_dot_velocity + (edge_dot_velocity * edge_dot_velocity); + float b = edge_dot_edge * 2.0f * (dot(velocity, base)) - 2.0f * edge_dot_velocity * edge_dot_base; + float c = edge_dot_edge * (1.0f - dot(base, base)) + (edge_dot_base * edge_dot_base); + + ct res = lowest_root(a, b, c, t); + float f0 = NONE; + if (res.collision) { + f0 = (edge_dot_velocity * res.t - edge_dot_base) * (1.0f / edge_dot_edge); + } + return ctf0(res.collision, t, f0); +} + +struct t0t1pip { + float t0; + float t1; + vec3 pip; +}; + +t0t1pip collision_inner(vec3 a, vec3 b, vec3 c, + vec3 point, + vec3 velocity) +{ + vec3 plane_normal = _plane_normal(a, b, c); vec3 plane_origin = a; float plane_d = _plane_d(plane_normal, plane_origin); float signed_distance = _signed_distance(plane_normal, plane_d, point); @@ -91,29 +174,60 @@ vec2 collision_inner(vec3 plane_normal, float n_dot_v = dot(plane_normal, velocity); float r_n_dot_v = 1.0f / n_dot_v; - //bool embedded = n_dot_v == 0.0f; + bool embedded = n_dot_v == 0.0f; if (n_dot_v == 0.0f) { - if (fabsf(signed_distance) >= 1.0f) - return false; + if (fabsf(signed_distance) >= 1.0) + return t0t1pip(NONE, NONE, vec3(0, 0, 0)); } - - vec2 t0_t1 = _t0_t1(signed_distance, r_n_dot_v); - float t0 = t0_t1.x; - //float t1 = t0_t1.y; + vec2 t0t1 = _t0_t1(signed_distance, r_n_dot_v); + float t0 = t0t1.x; + float t1 = t0t1.y; vec3 plane_intersection_point = point - plane_normal + t0 * velocity; - bool inside = point_in_triangle(plane_intersection_point, a, b, c); - float inside_f = inside ? 1.0f : 0.0f; - return vec2(inside_f, t0); + bool inside = point_in_triangle(plane_intersection_point, a, b, c); + + bool collision = false; + vec3 collision_point; + float t = NONE; + vec3 abc[] = {a, b, c}; + for (int i = 0; i < 3; i++) { + vec3 tri_point = abc[i]; + ct res = triangle_point_collide(tri_point, point, velocity, t); + t = res.t; + if (res.collision) { + collision_point = tri_point; + collision = true; + } + } + + for (int i = 0; i < 3; i++) { + vec3 p1 = abc[i]; + vec3 p2 = abc[(i + 1) % 3]; + ctf0 res = triangle_edge_collide(p1, p2, point, velocity, t); + if (res.collision && res.f0 >= 0.0 && res.f0 <= 1.0) { + t = res.t; + collision_point = p1 + res.f0 * (p2 - p1); + collision = true; + } + } + + if (inside && collision) { + printf("r_n_dot_v %f %f %f %f\n", n_dot_v, r_n_dot_v, t0, t1); + + return t0t1pip(t0, t1, plane_intersection_point); + } + else + return t0t1pip(NONE, NONE, vec3(0, 0, 0)); } vec4 collision(mat4x4 trans, vec3 point, vec3 velocity) { bool collision = false; - float smallest = 0.0f; + float smallest = -9999.0f; vec3 smallest_normal = vec3(0, 0, 0); + //printf("velocity %f %f %f\n", velocity.x, velocity.y, velocity.z); for (int i = 0; i < cube_Cube_triangles_length / 3; i++) { const float * a = &cube_vertices[cube_Cube_triangles[i * 3 + 0] * 8]; @@ -124,27 +238,27 @@ vec4 collision(mat4x4 trans, vec3 bp = trans * vec3(b[0], b[1], b[2]); vec3 cp = trans * vec3(c[0], c[1], c[2]); - vec3 plane_normal = _plane_normal(ap, bp, cp); - - vec2 res = collision_inner(plane_normal, ap, bp, cp, point, velocity); - bool inside = res.x == 1.0f; - float t0 = res.y; + t0t1pip res = collision_inner(ap, bp, cp, point, velocity); + bool inside = res.t0 != NONE; if (!inside) continue; - if (collision == false || t0 < smallest) { - smallest = t0; + if (collision == false || res.t0 < smallest) { + printf("new smallest %f %f\n", smallest, res.t0); + smallest = res.t0; + + vec3 plane_normal = _plane_normal(ap, bp, cp); smallest_normal = plane_normal; } collision = true; } - float collision_f = collision ? 1.0 : 0.0; + //float collision_f = collision ? 1.0 : 0.0; return vec4(smallest_normal.x, smallest_normal.y, smallest_normal.z, - collision_f); + collision ? smallest : -9999.0f); } /* diff --git a/src/font/ter_u32n.data b/src/font/ter_u32n.data new file mode 100644 index 0000000..2cd561d Binary files /dev/null and b/src/font/ter_u32n.data differ diff --git a/src/main.c b/src/main.c index e407bdb..e95bd38 100644 --- a/src/main.c +++ b/src/main.c @@ -9,13 +9,20 @@ #include "shader/vertex_color.fp.glsl.h" #include "shader/vertex_color.vp.glsl.h" +#include "shader/font.fp.glsl.h" +#include "shader/font.vp.glsl.h" + +#include "font/ter_u32n.data.h" + #include "opengl.h" #include "render.hpp" +#include "update.hpp" #include "model/block.h" #include "model/paddle.h" #include "model/ball.h" //#include "model/cube.h" +#include "model/plane.h" int vp_width = 1600; int vp_height = 1200; @@ -116,6 +123,34 @@ int main() uint uniform_base_color = glGetUniformLocation(program, "base_color"); uint uniform_light_pos = glGetUniformLocation(program, "light_pos"); + // + struct mesh plane_mesh; + + plane_mesh.vtx = make_buffer(GL_ARRAY_BUFFER, plane_vertices, (sizeof (plane_vertices))); + plane_mesh.idx = make_buffer(GL_ELEMENT_ARRAY_BUFFER, plane_Plane_triangles, (sizeof (plane_Plane_triangles))); + plane_mesh.length = plane_Plane_triangles_length; + + uint font_program = compile_shader(src_shader_font_vp_glsl_start, + src_shader_font_vp_glsl_size, + src_shader_font_fp_glsl_start, + src_shader_font_fp_glsl_size); + glUseProgram(font_program); + uint font__attrib_position = glGetAttribLocation(font_program, "position"); + uint font__attrib_texture = glGetAttribLocation(font_program, "_texture"); + uint font__attrib_normal = glGetAttribLocation(font_program, "normal"); + uint font__uniform_trans = glGetUniformLocation(font_program, "trans"); + uint font__uniform_texture0 = glGetUniformLocation(font_program, "texture0"); + + ////////////////////////////////////////////////////////////////////// + // textures + ////////////////////////////////////////////////////////////////////// + + uint terminus_font = make_texture(src_font_ter_u32n_data_start, + GL_RED, + 256, + 256, + GL_RED); + ////////////////////////////////////////////////////////////////////// // main loop ////////////////////////////////////////////////////////////////////// @@ -142,7 +177,6 @@ int main() glEnable(GL_DEPTH_TEST); glClearDepth(-1000.0f); - glDepthFunc(GL_GREATER); glClearColor(0.1, 0.2, 0.3, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -164,7 +198,8 @@ int main() float left = axes[2] * 0.5 + 0.5; float right = axes[5] * 0.5 + 0.5; - paddle_dx = right - left; + float sensitivity = 0.4f; + paddle_dx = (right - left) * sensitivity; //state.ball_dx = deadzone(axes[0]); //state.ball_dy = deadzone(axes[1]); @@ -173,12 +208,13 @@ int main() } float extent = 0.25; - state.paddle_x += paddle_dx * 0.4; + state.paddle_x += paddle_dx; if (state.paddle_x < extent) state.paddle_x = extent; if (state.paddle_x > 12 - extent) state.paddle_x = 12 - extent; - //state.paddle_y += paddle_dy * 0.4; + + update(&state); if ((state.ball_x + state.ball_dx * 0.4) > 12.25f) { state.ball_x = 12.25f; @@ -186,8 +222,6 @@ int main() } else if ((state.ball_x + state.ball_dx * 0.4) < -0.25f) { state.ball_x = -0.25f; state.ball_dx = -state.ball_dx; - } else { - state.ball_x += state.ball_dx * 0.4; } if ((state.ball_y + state.ball_dy * 0.4) > 27.0f) { @@ -196,10 +230,11 @@ int main() } else if ((state.ball_y + state.ball_dy * 0.4) < 0.0f) { state.ball_y = 0.0f; state.ball_dy = -state.ball_dy; - } else { - state.ball_y += state.ball_dy * 0.4; } + glDepthFunc(GL_GREATER); + glUseProgram(program); + render(paddle_mesh, block_mesh, ball_mesh, @@ -212,6 +247,17 @@ int main() uniform_light_pos, &state); + glDepthFunc(GL_ALWAYS); + glUseProgram(font_program); + + render_font(plane_mesh, + font__attrib_position, + font__attrib_texture, + font__attrib_normal, + font__uniform_trans, + font__uniform_texture0 + ); + glfwSwapBuffers(window); glfwPollEvents(); diff --git a/src/opengl.c b/src/opengl.c index b41cd3d..46a8535 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -69,3 +69,24 @@ int make_buffer(unsigned int target, glBufferData(target, size, data, GL_STATIC_DRAW); return buffer; } + +int make_texture(const void * data, + int internalformat, + int width, + int height, + int format) +{ + unsigned int texture; + glGenTextures(1, &texture); + glActiveTexture(GL_TEXTURE0); + + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, GL_UNSIGNED_BYTE, data); + + return texture; +} diff --git a/src/opengl.h b/src/opengl.h index 3bbaed1..9281097 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -6,3 +6,9 @@ unsigned int compile_shader(const void * vp, int make_buffer(unsigned int target, const void * data, size_t size); + +int make_texture(const void * data, + int internalformat, + int width, + int height, + int format); diff --git a/src/render.cpp b/src/render.cpp index 5e7e8d5..5d216f3 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -139,8 +139,8 @@ void render(mesh paddle_mesh, for (int y = 0; y < 28; y++) { for (int x = 0; x < 13; x++) { char tile = level[y * 13 + x]; - //if (tile == 0) - //continue; + if (tile == 0) + continue; const float cs = 1.0f / 255.0f; vec3 base_color = vec3(((float)pal[tile * 3 + 0]) * cs, @@ -152,15 +152,6 @@ void render(mesh paddle_mesh, mat4x4 trans = a * t * rx; - vec4 res = collision(t * rx, - vec3(state->ball_x * 4.0f, -state->ball_y * 2.0f, 0), - vec3(0, 0, 0)); - bool collision = res.w == 1.0f; - if (collision) { - //vec3 normal = vec3(res.x, res.y, res.z); - base_color = vec3(1, 0, 0); - } - //mat3x3 normal_trans = transpose(inverse(submatrix(trans, 0, 0))); mat3x3 normal_trans = submatrix(rx, 3, 3); @@ -173,7 +164,6 @@ void render(mesh paddle_mesh, } } - ////////////////////////////////////////////////////////////////////// // render paddle ////////////////////////////////////////////////////////////////////// @@ -275,3 +265,48 @@ void render(mesh paddle_mesh, glDrawElements(GL_TRIANGLES, paddle_mesh.length, GL_UNSIGNED_INT, 0); } } + +void render_font(struct mesh plane_mesh, + uint attrib_position, + uint attrib_texture, + uint attrib_normal, + uint uniform_trans, + uint uniform_texture0) +{ + glBindBuffer(GL_ARRAY_BUFFER, plane_mesh.vtx); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, plane_mesh.idx); + + glVertexAttribPointer(attrib_position, + 3, + GL_FLOAT, + GL_FALSE, + (sizeof (float)) * 8, + (void*)(0 * 4) + ); + glVertexAttribPointer(attrib_texture, + 2, + GL_FLOAT, + GL_FALSE, + (sizeof (float)) * 8, + (void*)(3 * 4) + ); + glVertexAttribPointer(attrib_normal, + 3, + GL_FLOAT, + GL_FALSE, + (sizeof (float)) * 8, + (void*)(5 * 4) + ); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texture); + glEnableVertexAttribArray(attrib_normal); + + mat4x4 r = rotate_y(PI / 1.0f) * rotate_z(PI / 1.0f) * rotate_x(PI / 2.0f); + + mat4x4 trans = scale(0.5f) * r; + + glUniform4fv(uniform_trans, 4, &trans[0][0]); + glUniform1i(uniform_texture0, 0); + + glDrawElements(GL_TRIANGLES, plane_mesh.length, GL_UNSIGNED_INT, 0); +} diff --git a/src/shader/font.fp.glsl b/src/shader/font.fp.glsl new file mode 100644 index 0000000..b82c282 --- /dev/null +++ b/src/shader/font.fp.glsl @@ -0,0 +1,15 @@ +#version 120 + +uniform sampler2D texture0; + +varying vec2 fp_texture; + +void main() +{ + vec4 c = texture2D(texture0, fp_texture); + + float i = c.x == 0 ? 0.0 : 1.0; + + gl_FragColor = vec4(i, i, i, 1.0); + //gl_FragColor = vec4(fp_texture.xy, 1, 1.0); +} diff --git a/src/shader/font.vp.glsl b/src/shader/font.vp.glsl new file mode 100644 index 0000000..cd81711 --- /dev/null +++ b/src/shader/font.vp.glsl @@ -0,0 +1,26 @@ +#version 120 + +attribute vec3 position; +attribute vec2 _texture; +attribute vec3 normal; + +varying vec2 fp_texture; + +uniform vec4 trans[4]; + +vec4 transform4(vec4 v) +{ + return vec4(dot(trans[0], v), + dot(trans[1], v), + dot(trans[2], v), + dot(trans[3], v)); +} + +void main() +{ + vec4 pos = transform4(vec4(position, 1)); + + fp_texture = _texture; + + gl_Position = pos; +} diff --git a/src/update.cpp b/src/update.cpp new file mode 100644 index 0000000..4a35809 --- /dev/null +++ b/src/update.cpp @@ -0,0 +1,16 @@ +#include +#include + +#include "update.hpp" +#include "collision.hpp" +#include "state.h" + +#include "level/level1.data.h" +#include "level/level1.data.pal.h" + +#include "math/float_types.hpp" +#include "math/transform.hpp" + +void update(struct game_state * state) +{ +}