diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index 4b12317..d78d908 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -128,8 +128,12 @@ bool flies_load (s_sequence *seq)
i++;
}
fly_init(map);
- gl_text_init_1(&g_text_flies_in, &g_font_flies, "In 0");
- gl_text_init_1(&g_text_flies_out, &g_font_flies, "Out 0");
+ if (! gl_text_init_1(&g_text_flies_in, &g_font_flies, "In 0"))
+ return false;
+ gl_text_update(&g_text_flies_in);
+ if (! gl_text_init_1(&g_text_flies_out, &g_font_flies, "Out 0"))
+ return false;
+ gl_text_update(&g_text_flies_out);
return true;
}
@@ -196,6 +200,7 @@ bool flies_render (s_sequence *seq)
GL_LINEAR_MIPMAP_LINEAR);
gl_matrix_4f_init_identity(&g_ortho.model_matrix);
gl_matrix_4f_translate(&g_ortho.model_matrix, board_x, 60.0, 0.0);
+ gl_ortho_update_model_matrix(&g_ortho);
glBlendColor(1.0f, 1.0f, 1.0f, 1.0f);
buf_init(&buf, false, sizeof(a), a);
buf_write_1(&buf, "In ");
@@ -218,7 +223,7 @@ bool flies_render (s_sequence *seq)
g_ortho.model_matrix = matrix;
gl_matrix_4f_translate(&g_ortho.model_matrix, 0.0, board_item_h, 0.0);
glBlendColor(0.6f, 0.7f, 0.9f, 1.0f);
- //glRectd(0, 0, board_w, board_h);
+ gl_ortho_rect(&g_ortho, 0, 0, board_w, board_h);
address[1] = 0;
while (address[1] < BOARD_SIZE) {
y = board_item_h * address[1];
@@ -236,7 +241,7 @@ bool flies_render (s_sequence *seq)
case BOARD_ITEM_BLOCK:
glBindTexture(GL_TEXTURE_2D, 0);
glBlendColor(0.0f, 0.0f, 1.0f, 1.0f);
- //glRectd(0, 0, board_item_w + 1.0, board_item_h + 1.0);
+ gl_ortho_rect(&g_ortho, 0, 0, board_item_w + 1.0, board_item_h + 1.0);
break;
case BOARD_ITEM_FLY:
matrix_2 = g_ortho.model_matrix; {
diff --git a/libc3/window/sdl2/gl_deprecated.h b/libc3/window/sdl2/gl_deprecated.h
index a0ab259..51b50db 100644
--- a/libc3/window/sdl2/gl_deprecated.h
+++ b/libc3/window/sdl2/gl_deprecated.h
@@ -10,11 +10,11 @@
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
-#ifndef GL_DEPRECATED_H
-#define GL_DEPRECATED_H
+#ifndef C3_GL_DEPRECATED_H
+#define C3_GL_DEPRECATED_H
#include "types.h"
const char * gl_error_string (GLenum error);
-#endif /* GL_DEPRECATED_H */
+#endif /* C3_GL_DEPRECATED_H */
diff --git a/libc3/window/sdl2/gl_lines.c b/libc3/window/sdl2/gl_lines.c
index d72c240..e1cadfb 100644
--- a/libc3/window/sdl2/gl_lines.c
+++ b/libc3/window/sdl2/gl_lines.c
@@ -12,6 +12,7 @@
*/
#include <libc3/c3.h>
#include "gl_lines.h"
+#include "gl_vertex.h"
s_gl_lines * gl_lines_allocate (s_gl_lines *lines, uw lines_count)
{
@@ -53,6 +54,8 @@ void gl_lines_render (const s_gl_lines *lines, uw lines_count)
assert(glGetError() == GL_NO_ERROR);
glBindVertexArray(lines->gl_vao);
assert(glGetError() == GL_NO_ERROR);
+ glBindVertexArray(lines->gl_vao);
+ assert(glGetError() == GL_NO_ERROR);
glDrawArrays(GL_LINES, 0, lines_count * 2);
assert(glGetError() == GL_NO_ERROR);
}
@@ -74,20 +77,7 @@ bool gl_lines_update (s_gl_lines *lines, uw lines_count)
glBufferData(GL_ARRAY_BUFFER, lines_count * 2 * sizeof(s_gl_vertex),
lines->vertex.data, GL_DYNAMIC_DRAW);
assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(0);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) 0);
- assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(1);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) (3 * sizeof(float)));
- assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(2);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) (6 * sizeof(float)));
+ gl_vertex_attrib();
assert(glGetError() == GL_NO_ERROR);
return true;
}
diff --git a/libc3/window/sdl2/gl_object.c b/libc3/window/sdl2/gl_object.c
index a4cd746..fa0215e 100644
--- a/libc3/window/sdl2/gl_object.c
+++ b/libc3/window/sdl2/gl_object.c
@@ -11,6 +11,7 @@
* THIS SOFTWARE.
*/
#include <libc3/c3.h>
+#include "gl_deprecated.h"
#include "gl_object.h"
#include "gl_vertex.h"
@@ -45,7 +46,9 @@ s_gl_object * gl_object_init (s_gl_object *object)
s_gl_object tmp = {0};
assert(glGetError() == GL_NO_ERROR);
glGenVertexArrays(1, &tmp.gl_vao);
+ assert(glGetError() == GL_NO_ERROR);
glGenBuffers(1, &tmp.gl_vbo);
+ assert(glGetError() == GL_NO_ERROR);
glGenBuffers(1, &tmp.gl_ebo);
assert(glGetError() == GL_NO_ERROR);
*object = tmp;
@@ -54,15 +57,22 @@ s_gl_object * gl_object_init (s_gl_object *object)
void gl_object_render (const s_gl_object *object)
{
+ GLenum error;
assert(object);
assert(glGetError() == GL_NO_ERROR);
- //glBindVertexArray(object->gl_vao);
- //assert(glGetError() == GL_NO_ERROR);
+ glBindVertexArray(object->gl_vao);
+ assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ARRAY_BUFFER, object->gl_vbo);
assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->gl_ebo);
assert(glGetError() == GL_NO_ERROR);
- glDrawArrays(GL_TRIANGLES, 0, object->triangle.count * 3);
+ glDrawElements(GL_TRIANGLES, object->triangle.count * 3, GL_UNSIGNED_INT,
+ NULL);
+ if ((error = glGetError()) != GL_NO_ERROR) {
+ err_write_1("gl_object_render: glDrawElements: ");
+ err_puts(gl_error_string(error));
+ assert(! "gl_object_render: glDrawElements");
+ }
assert(glGetError() == GL_NO_ERROR);
}
@@ -72,9 +82,12 @@ void gl_object_render_wireframe (const s_gl_object *object)
assert(glGetError() == GL_NO_ERROR);
glBindVertexArray(object->gl_vao);
assert(glGetError() == GL_NO_ERROR);
+ glBindBuffer(GL_ARRAY_BUFFER, object->gl_vbo);
+ assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->gl_ebo);
assert(glGetError() == GL_NO_ERROR);
- glDrawElements(GL_LINE_LOOP, object->triangle.count * 3, GL_UNSIGNED_INT, 0);
+ glDrawElements(GL_LINE_LOOP, object->triangle.count * 3, GL_UNSIGNED_INT,
+ NULL);
assert(glGetError() == GL_NO_ERROR);
}
@@ -109,27 +122,14 @@ bool gl_object_update (s_gl_object *object)
glBindBuffer(GL_ARRAY_BUFFER, object->gl_vbo);
assert(glGetError() == GL_NO_ERROR);
glBufferData(GL_ARRAY_BUFFER, object->vertex.count * sizeof(s_gl_vertex),
- object->vertex.data, GL_STATIC_DRAW);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) 0);
- assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(0);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) (3 * sizeof(float)));
- assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(1);
- assert(glGetError() == GL_NO_ERROR);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
- (void *) (6 * sizeof(float)));
+ object->vertex.data, GL_DYNAMIC_DRAW);
assert(glGetError() == GL_NO_ERROR);
- glEnableVertexAttribArray(2);
+ gl_vertex_attrib();
assert(glGetError() == GL_NO_ERROR);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->gl_ebo);
assert(glGetError() == GL_NO_ERROR);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, object->triangle.count * 3,
- object->triangle.data, GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, object->triangle.count * sizeof(s_gl_triangle),
+ object->triangle.data, GL_DYNAMIC_DRAW);
assert(glGetError() == GL_NO_ERROR);
return true;
}
diff --git a/libc3/window/sdl2/gl_ortho.c b/libc3/window/sdl2/gl_ortho.c
index 5efc204..db7aad7 100644
--- a/libc3/window/sdl2/gl_ortho.c
+++ b/libc3/window/sdl2/gl_ortho.c
@@ -12,6 +12,7 @@
*/
#include <math.h>
#include <libc3/c3.h>
+#include "gl_deprecated.h"
#include "gl_ortho.h"
#include "gl_matrix_4f.h"
@@ -159,7 +160,7 @@ void gl_ortho_render (s_gl_ortho *ortho)
&ortho->projection_matrix.xx);
if ((error = glGetError()) != GL_NO_ERROR) {
err_write_1("gl_ortho_render: glUniformMatrix4fv: ");
- err_puts((const char *) glewGetErrorString(error));
+ err_puts(gl_error_string(error));
assert(! "gl_ortho_render: glUniformMatrix4fv");
}
assert(glGetError() == GL_NO_ERROR);
diff --git a/libc3/window/sdl2/gl_sphere.c b/libc3/window/sdl2/gl_sphere.c
index 5357d96..b56f17e 100644
--- a/libc3/window/sdl2/gl_sphere.c
+++ b/libc3/window/sdl2/gl_sphere.c
@@ -72,7 +72,7 @@ s_gl_sphere * gl_sphere_init (s_gl_sphere *sphere, uw seg_u, uw seg_v)
}
triangle = tmp.object.triangle.data;
i = 0;
- while (i < seg_v + 1) {
+ while (i < seg_v) {
j = 0;
while (j < seg_u) {
triangle->a = i * seg_u + j;
diff --git a/libc3/window/sdl2/gl_sprite.c b/libc3/window/sdl2/gl_sprite.c
index 63dc6b3..d812be1 100644
--- a/libc3/window/sdl2/gl_sprite.c
+++ b/libc3/window/sdl2/gl_sprite.c
@@ -121,7 +121,6 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
uw x;
uw y;
uw v;
- uw dimension;
s_gl_sprite tmp = {0};
s_gl_triangle *triangle;
s_gl_vertex *vertex;
@@ -343,14 +342,7 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
free(png_row);
assert(glGetError() == GL_NO_ERROR);
gl_object_init(&tmp.object);
- dimension = 4;
- array_init(&tmp.object.vertex, sym_1("GL.Vertex"), 1,
- &dimension);
- array_allocate(&tmp.object.vertex);
- dimension = 2;
- array_init(&tmp.object.triangle, sym_1("GL.Triangle"), 1,
- &dimension);
- array_allocate(&tmp.object.triangle);
+ gl_object_allocate(&tmp.object, 4, 2);
vertex = tmp.object.vertex.data;
gl_point_3f_init(&vertex[0].position, 0.0, tmp.h, 0.0);
gl_point_3f_init(&vertex[0].normal, 0.0, 0.0, -1.0);
diff --git a/libc3/window/sdl2/gl_text.c b/libc3/window/sdl2/gl_text.c
index c0e0820..b0ee82d 100644
--- a/libc3/window/sdl2/gl_text.c
+++ b/libc3/window/sdl2/gl_text.c
@@ -26,21 +26,14 @@ void gl_text_clean (s_gl_text *text)
s_gl_text * gl_text_init (s_gl_text *text, const s_gl_font *font)
{
- uw dimension;
s_gl_text tmp = {0};
assert(glGetError() == GL_NO_ERROR);
tmp.font = font;
glGenTextures(1, &tmp.texture);
assert(glGetError() == GL_NO_ERROR);
gl_object_init(&tmp.object);
- dimension = 4;
- array_init(&tmp.object.vertex, sym_1("GL.Vertex"), 1,
- &dimension);
- array_allocate(&tmp.object.vertex);
- dimension = 2;
- array_init(&tmp.object.triangle, sym_1("GL.Triangle"), 1,
- &dimension);
- array_allocate(&tmp.object.triangle);
+ assert(glGetError() == GL_NO_ERROR);
+ gl_object_allocate(&tmp.object, 4, 2);
*text = tmp;
return text;
}
@@ -70,6 +63,7 @@ void gl_text_render (const s_gl_text *text)
assert(text);
assert(glGetError() == GL_NO_ERROR);
gl_object_render(&text->object);
+ assert(glGetError() == GL_NO_ERROR);
}
bool gl_text_render_to_texture (s_gl_text *text)
@@ -222,18 +216,18 @@ bool gl_text_update (s_gl_text *text)
if (! gl_text_render_to_texture(text))
return false;
vertex = text->object.vertex.data;
- gl_point_3f_init(&vertex[0].position, 0.0, text->h, 0.0);
- gl_point_3f_init(&vertex[0].normal, 0.0, 0.0, -1.0);
- gl_point_2f_init(&vertex[0].tex_coord, 0.0, 1.0);
- gl_point_3f_init(&vertex[1].position, 0.0, 0.0, 0.0);
- gl_point_3f_init(&vertex[1].normal, 0.0, 0.0, -1.0);
- gl_point_2f_init(&vertex[1].tex_coord, 0.0, 0.0);
- gl_point_3f_init(&vertex[2].position, text->w, text->h, 0.0);
- gl_point_3f_init(&vertex[2].normal, 0.0, 0.0, -1.0);
- gl_point_2f_init(&vertex[2].tex_coord, 1.0, 1.0);
- gl_point_3f_init(&vertex[3].position, text->w, 0.0, 0.0);
- gl_point_3f_init(&vertex[3].normal, 0.0, 0.0, -1.0);
- gl_point_2f_init(&vertex[3].tex_coord, 1.0, 0.0);
+ gl_point_3f_init(&vertex[0].position, 0.0, text->h, 0.0);
+ gl_point_3f_init(&vertex[0].normal, 0.0, 0.0, -1.0);
+ gl_point_2f_init(&vertex[0].tex_coord, 0.0, 1.0);
+ gl_point_3f_init(&vertex[1].position, 0.0, 0.0, 0.0);
+ gl_point_3f_init(&vertex[1].normal, 0.0, 0.0, -1.0);
+ gl_point_2f_init(&vertex[1].tex_coord, 0.0, 0.0);
+ gl_point_3f_init(&vertex[2].position, text->w, text->h, 0.0);
+ gl_point_3f_init(&vertex[2].normal, 0.0, 0.0, -1.0);
+ gl_point_2f_init(&vertex[2].tex_coord, 1.0, 1.0);
+ gl_point_3f_init(&vertex[3].position, text->w, 0.0, 0.0);
+ gl_point_3f_init(&vertex[3].normal, 0.0, 0.0, -1.0);
+ gl_point_2f_init(&vertex[3].tex_coord, 1.0, 0.0);
triangle = text->object.triangle.data;
gl_triangle_init(triangle + 0, 0, 1, 2);
gl_triangle_init(triangle + 1, 1, 3, 2);
diff --git a/libc3/window/sdl2/gl_triangle.c b/libc3/window/sdl2/gl_triangle.c
index c2200f1..b54b14b 100644
--- a/libc3/window/sdl2/gl_triangle.c
+++ b/libc3/window/sdl2/gl_triangle.c
@@ -13,8 +13,8 @@
#include <libc3/c3.h>
#include "gl_triangle.h"
-s_gl_triangle * gl_triangle_init (s_gl_triangle *triangle, u32 a, u32 b,
- u32 c)
+s_gl_triangle * gl_triangle_init (s_gl_triangle *triangle, GLuint a,
+ GLuint b, GLuint c)
{
assert(triangle);
triangle->a = a;
diff --git a/libc3/window/sdl2/gl_triangle.h b/libc3/window/sdl2/gl_triangle.h
index 869ea78..31ddae2 100644
--- a/libc3/window/sdl2/gl_triangle.h
+++ b/libc3/window/sdl2/gl_triangle.h
@@ -15,7 +15,7 @@
#include "types.h"
-s_gl_triangle * gl_triangle_init (s_gl_triangle *triangle, u32 a, u32 b,
- u32 c);
+s_gl_triangle * gl_triangle_init (s_gl_triangle *triangle, GLuint a,
+ GLuint b, GLuint c);
#endif /* GL_TRIANGLE_H */
diff --git a/libc3/window/sdl2/gl_vertex.c b/libc3/window/sdl2/gl_vertex.c
index 8311e82..38aec9a 100644
--- a/libc3/window/sdl2/gl_vertex.c
+++ b/libc3/window/sdl2/gl_vertex.c
@@ -14,6 +14,26 @@
#include "gl_point_3f.h"
#include "gl_vertex.h"
+void gl_vertex_attrib (void)
+{
+ assert(glGetError() == GL_NO_ERROR);
+ glEnableVertexAttribArray(0);
+ assert(glGetError() == GL_NO_ERROR);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
+ (void *) 0);
+ assert(glGetError() == GL_NO_ERROR);
+ glEnableVertexAttribArray(1);
+ assert(glGetError() == GL_NO_ERROR);
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
+ (void *) (3 * sizeof(float)));
+ assert(glGetError() == GL_NO_ERROR);
+ glEnableVertexAttribArray(2);
+ assert(glGetError() == GL_NO_ERROR);
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(s_gl_vertex),
+ (void *) (6 * sizeof(float)));
+ assert(glGetError() == GL_NO_ERROR);
+}
+
void gl_vertex_transform (s_gl_vertex *vertex,
const s_gl_matrix_4f *matrix)
{
diff --git a/libc3/window/sdl2/gl_vertex.h b/libc3/window/sdl2/gl_vertex.h
index 4578204..d227b0b 100644
--- a/libc3/window/sdl2/gl_vertex.h
+++ b/libc3/window/sdl2/gl_vertex.h
@@ -15,6 +15,7 @@
#include "types.h"
+void gl_vertex_attrib (void);
void gl_vertex_transform (s_gl_vertex *vertex,
const s_gl_matrix_4f *matrix);
diff --git a/libc3/window/sdl2/types.h b/libc3/window/sdl2/types.h
index 44bf5f9..520cecd 100644
--- a/libc3/window/sdl2/types.h
+++ b/libc3/window/sdl2/types.h
@@ -285,6 +285,7 @@ struct gl_ortho {
u32 gl_enable_texture_loc;
u32 gl_texture_loc;
u32 gl_shader_program;
+ s_gl_square square;
};
struct gl_sphere {