Vinicius Teshima 1 год назад
Родитель
Сommit
ff13108e0f
5 измененных файлов с 6 добавлено и 156 удалено
  1. 0 18
      shaders/cur.frag
  2. 0 24
      shaders/cur.vert
  3. 0 1
      src/app.h
  4. 0 83
      src/cursor.h
  5. 6 30
      src/main.c

+ 0 - 18
shaders/cur.frag

@@ -1,18 +0,0 @@
-#version 330 core
-
-uniform float time;
-uniform float last_press;
-
-in vec2 uv;
-
-float map01(float x)
-{
-	return (x + 1) / 2;
-}
-
-void main()
-{
-	int c1 = int(time - last_press < 0.8);
-	int c2 = int(floor(time / 0.4)) % 2;
-	gl_FragColor = vec4(1) * (c1 + c2);
-}

+ 0 - 24
shaders/cur.vert

@@ -1,24 +0,0 @@
-#version 330 core
-
-uniform float time;
-uniform vec2 resolution;
-uniform vec2 camera;
-uniform vec2 pos;
-uniform float h;
-uniform float w;
-
-out vec2 uv;
-
-vec2 project_point(vec2 point)
-{
-	return (2.0 * (point - camera)) / resolution;
-}
-
-void main()
-{
-	uv = vec2(float(gl_VertexID & 1),
-		  float((gl_VertexID >> 1) & 1));
-
-	uv = uv * vec2(w, h) + pos;
-	gl_Position = vec4(project_point(uv), 0.0, 1.0);
-}

+ 0 - 1
src/app.h

@@ -29,7 +29,6 @@ struct app {
 };
 
 #include "free_glyph.h"
-#include "cursor.h"
 
 struct ret_app_vec2 {
 	struct app f1;

+ 0 - 83
src/cursor.h

@@ -1,83 +0,0 @@
-#ifndef CURSOR_H
-#define CURSOR_H
-
-#include <stdint.h>
-
-#include "vec2.h"
-
-struct cursor_render {
-	uint32_t prog;
-	struct {
-		uint32_t vert;
-		uint32_t frag;
-	} shaders;
-	struct {
-		int32_t time;
-		int32_t resolution;
-		int32_t camera;
-		int32_t pos;
-		int32_t h;
-		int32_t w;
-		int32_t last_press;
-	} uniforms;
-	uint32_t vao;
-	uint32_t vbo;
-};
-
-struct cursor_render cursor_render_create(const char *vert_path,
-					  const char *frag_path);
-
-void cursor_render_use(struct cursor_render cr);
-void cursor_render_mv_to(struct cursor_render cr, struct vec2f pos);
-void cursor_render_draw(struct cursor_render cr);
-
-#if defined(CURSOR_IMP) || defined(IMP)
-
-#include "shader.h"
-
-struct cursor_render
-cursor_render_create(const char *vert_path, const char *frag_path)
-{
-	struct cursor_render cr = {0};
-	cr.shaders.vert = shader_compile_file_or_exit(vert_path,
-						      GL_VERTEX_SHADER);
-	cr.shaders.frag = shader_compile_file_or_exit(frag_path,
-						      GL_FRAGMENT_SHADER);
-	cr.prog = program_link_or_exit(cr.shaders.vert, cr.shaders.frag);
-
-	cr.uniforms.resolution = get_uniform_or_exit(cr.prog, "resolution");
-	cr.uniforms.camera = get_uniform_or_exit(cr.prog, "camera");
-	cr.uniforms.pos = get_uniform_or_exit(cr.prog, "pos");
-	cr.uniforms.h = get_uniform_or_exit(cr.prog, "h");
-	cr.uniforms.w = get_uniform_or_exit(cr.prog, "w");
-	cr.uniforms.time = get_uniform_or_exit(cr.prog, "time");
-	cr.uniforms.last_press = get_uniform_or_exit(cr.prog, "last_press");
-
-	return cr;
-}
-
-void
-cursor_render_use(struct cursor_render cr)
-{
-	/* glBindVertexArray(cr.vao); */
-	/* glBindBuffer(GL_ARRAY_BUFFER, cr.vbo); */
-	glUseProgram(cr.prog);
-}
-
-
-void
-cursor_render_mv_to(struct cursor_render cr, struct vec2f pos)
-{
-	glUniform2f(cr.uniforms.pos, pos.x, pos.y);
-}
-
-void
-cursor_render_draw(struct cursor_render cr)
-{
-	(void) cr;
-	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-}
-
-#endif /* defined(CURSOR_IMP) || defined(IMP) */
-
-#endif

+ 6 - 30
src/main.c

@@ -11,7 +11,6 @@
 #include "shader.h"
 #include "gl_util.h"
 #include "free_glyph.h"
-#include "cursor.h"
 #include "util_macro.h"
 
 #include <stdio.h>
@@ -30,10 +29,9 @@
 #include FT_FREETYPE_H
 
 
-void handle_events(struct app *app, struct cursor_render *cr);
+void handle_events(struct app *app);
 
 void render_buffer_into_fgr(struct free_glyph_render *fgr,
-			    struct cursor_render *cr,
 			    struct simple_render *sr,
 			    struct app *app);
 
@@ -95,17 +93,12 @@ main(int32_t argc, char **argv)
 		"./shaders/free_font.vert",
 		"./shaders/free_font.frag");
 
-	struct cursor_render cr = cursor_render_create(
-		"./shaders/cur.vert",
-		"./shaders/cur.frag");
-
 	struct simple_render sr = sr_create(
 		"./shaders/simple.vert",
 		"./shaders/simple.frag");
 	(void) sr;
 
 	app.fgr = &fgr;
-	app.cr = &cr;
 
 	uint32_t frame_target_dur = (uint32_t)(1000 / app.target_fps);
 
@@ -119,7 +112,7 @@ main(int32_t argc, char **argv)
 	while ( app.running ) {
 		fr_start = SDL_GetTicks();
 
-		handle_events(&app, &cr);
+		handle_events(&app);
 
 		if ( app.show_fps == true ) {
 			fps_text_size = (size_t) snprintf(fps_text, 128,
@@ -133,7 +126,7 @@ main(int32_t argc, char **argv)
 		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 		glClear(GL_COLOR_BUFFER_BIT);
 
-		render_buffer_into_fgr(&fgr, &cr, &sr, &app);
+		render_buffer_into_fgr(&fgr, &sr, &app);
 
 		SDL_GL_SwapWindow(app.win.ptr);
 
@@ -149,9 +142,8 @@ main(int32_t argc, char **argv)
 }
 
 void
-handle_events(struct app *app, struct cursor_render *cr)
+handle_events(struct app *app)
 {
-	(void) cr;
 	SDL_Event e = {0};
 	bool done = false;
 	while ( SDL_PollEvent(&e) ) {
@@ -201,11 +193,10 @@ handle_events(struct app *app, struct cursor_render *cr)
 }
 
 void
-render_buffer_into_fgr(struct free_glyph_render *fgr, struct cursor_render *cr,
-		       struct simple_render *sr, struct app *app)
+render_buffer_into_fgr(struct free_glyph_render *fgr, struct simple_render *sr,
+		       struct app *app)
 {
 	(void) fgr;
-	(void) cr;
 	(void) app;
 	uint32_t ticks = SDL_GetTicks();
 	float cur_row = (float)(buffer_calc_cur_row(&app->buf)
@@ -239,21 +230,6 @@ render_buffer_into_fgr(struct free_glyph_render *fgr, struct cursor_render *cr,
 				      (int32_t) fgr->glyphs.size);
 	}
 
-	/* cursor_render_use(*cr); */
-	/* { */
-	/* 	glUniform1f(cr->uniforms.time, ((float) ticks) / 1000.0f); */
-	/* 	glUniform2f(cr->uniforms.camera, (float)cpos.x, (float)cpos.y); */
-	/* 	glUniform2f(cr->uniforms.resolution, */
-	/* 		    (float) app->win.w, */
-	/* 		    (float) app->win.h); */
-	/* 	glUniform1f(cr->uniforms.h, (float) 32); */
-	/* 	glUniform1f(cr->uniforms.w, (float) 3); */
-
-	/* 	struct vec2 c_pos = vec2(cur_pos.x, cur_pos.y); */
-	/* 	cursor_render_mv_to(*cr, vec2_to_f(c_pos)); */
-	/* 	cursor_render_draw(*cr); */
-	/* } */
-
 	sr_use(sr);
 	{
 		glUniform1f(sr_get_uniform(sr, "time"), time);