summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c78
1 files changed, 13 insertions, 65 deletions
diff --git a/main.c b/main.c
index 49f4730..92d6b23 100644
--- a/main.c
+++ b/main.c
@@ -283,96 +283,42 @@ int main(int argc, char **argv) {
#endif
gl_geometry_init();
+ text_init();
SDL_GL_SetSwapInterval(1); // vsync
- #if 0
- float vertices[][6] = {
- {0, 0, 1, 0, 0, 1},
- {50, 0, 0, 1, 0, 1},
- {0, 50, 0, 0, 1, 1},
- };
- char const *vshader_code = "#version 110\n\
- attribute vec2 v_pos;\n\
- attribute vec4 v_color;\n\
- varying vec4 color;\n\
- uniform vec2 window_size;\n\
- void main() {\n\
- float x = v_pos.x / window_size.x * 2.0 - 1.0;\n\
- float y = 1.0 - v_pos.y / window_size.y * 2.0;\n\
- gl_Position = vec4(x, y, 0.0, 1.0);\n\
- color = v_color;\n\
- }\n\
- ";
- char const *fshader_code = "#version 110\n\
- varying vec4 color;\n\
- void main() {\n\
- gl_FragColor = color;\n\
- }\n\
- ";
- GLuint program = gl_compile_and_link_shaders(vshader_code, fshader_code);
- GLuint v_pos = gl_attrib_loc(program, "v_pos");
- GLuint v_color = gl_attrib_loc(program, "v_color");
- GLint u_window_size = gl_uniform_loc(program, "window_size");
-
- GLuint vbo = 0, vao = 0;
- glGenBuffers(1, &vbo);
- glGenVertexArrays(1, &vao);
-
- glBindVertexArray(vao);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW);
- glVertexAttribPointer(v_pos, 2, GL_FLOAT, 0, 6 * sizeof(float), (void *)0);
- glEnableVertexAttribArray(v_pos);
- glVertexAttribPointer(v_color, 4, GL_FLOAT, 0, 6 * sizeof(float), (void *)(2 * sizeof(float)));
- glEnableVertexAttribArray(v_color);
- glBindVertexArray(0);
-
- while (1) {
- int w, h;
- SDL_GetWindowSize(window, &w, &h);
-
- SDL_Event event;
- while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT) return 0;
-
- glViewport(0, 0, w, h);
- glClearColor(0,0,0,1);
- glClear(GL_COLOR_BUFFER_BIT);
-
-
- glUseProgram(program);
- glUniform2f(u_window_size, (float)w, (float)h);
- glBindVertexArray(vao);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
- SDL_GL_SwapWindow(window);
+ Font *font = text_font_load("assets/font.ttf", 16);
+ if (!font) {
+ die("%s", text_get_err());
}
- #endif
while (1) {
int w, h;
SDL_GetWindowSize(window, &w, &h);
ted->window_width = (float)w;
ted->window_height = (float)h;
+ gl_window_width = (float)w, gl_window_height = (float)h;
SDL_Event event;
while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT) return 0;
+ (void)settings;
glViewport(0, 0, w, h);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
- for (int i = 0; i < 20; ++i) {
- gl_geometry_rect(rect(V2(0, 10*(float)i), V2(100, 100)), 0xffffffff >> i);
+ for (int i = 0; i < 200; ++i) {
+ gl_geometry_rect(rect(V2(0, 4*(float)i), V2(100, 100)), 0xffffffff >> i);
- gl_geometry_draw(ted);
+ gl_geometry_draw();
}
+ text_render(font, "hello", 5, 5);
SDL_GL_SwapWindow(window);
}
return 0;
-
+#if 0
ted_load_fonts(ted);
if (ted_haserr(ted))
die("Error loading font: %s", ted_geterr(ted));
@@ -456,6 +402,7 @@ int main(int argc, char **argv) {
ted->window_height = (float)window_height_int;
}
window_width = ted->window_width, window_height = ted->window_height;
+ gl_window_width = window_width, gl_window_height = window_height;
while (SDL_PollEvent(&event)) {
TextBuffer *buffer = ted->active_buffer;
@@ -786,4 +733,5 @@ int main(int argc, char **argv) {
#endif
return 0;
+#endif
}