From b2b54ddce94708ca2167c97882bf13732c19374c Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sun, 26 Feb 2023 17:28:52 +0000 Subject: [PATCH] Fixing circle shader --- source/engine/debug/debugdraw.c | 1 + source/engine/openglrender.c | 16 ++++++++++++++-- source/shaders/circlevert.glsl | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/source/engine/debug/debugdraw.c b/source/engine/debug/debugdraw.c index c06648e..1a678c7 100644 --- a/source/engine/debug/debugdraw.c +++ b/source/engine/debug/debugdraw.c @@ -26,6 +26,7 @@ void debugdraw_init() { circleShader = MakeShader("circlevert.glsl", "circlefrag.glsl"); shader_setUBO(circleShader, "Projection", 0); + shader_setUBO(circleShader, "Resolution", 0); glGenBuffers(1, &circleVBO); glGenVertexArrays(1, &circleVAO); diff --git a/source/engine/openglrender.c b/source/engine/openglrender.c index 53f473e..01ec699 100644 --- a/source/engine/openglrender.c +++ b/source/engine/openglrender.c @@ -60,6 +60,7 @@ struct sprite *tsprite = NULL; static unsigned int projUBO; +static unsigned int resUBO; void debug_draw_phys(int draw) { debugDrawPhysics = draw; @@ -107,6 +108,14 @@ void openglInit() shader_setUBO(spriteShader, "Projection", 0); shader_setUBO(textShader, "Projection", 0); shader_setUBO(animSpriteShader, "Projection", 0); + +/* + glGenBuffers(1,&resUBO); + glBindBuffer(GL_UNIFORM_BUFFER, resUBO); + glBufferData(GL_UNIFORM_BUFFER, sizeof(float)*2, NULL, GL_DYNAMIC_DRAW); + glBindBufferRange(GL_UNIFORM_BUFFER, 0, resUBO, 0, sizeof(float)*2); + glBindBuffer(GL_UNIFORM_BUFFER,0); +*/ } @@ -126,7 +135,6 @@ void add_zoom(float val) { zoom = val; } void openglRender(struct window *window) { - glCullFace(GL_BACK); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -150,7 +158,11 @@ void openglRender(struct window *window) glBindBuffer(GL_UNIFORM_BUFFER, projUBO); glBufferSubData(GL_UNIFORM_BUFFER, 0, 64, projection); - +/* + float res[2] = {window->width, window->height}; + glBindBuffer(GL_UNIFORM_BUFFER, resUBO); + glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(float)*2, res); +*/ /* Game sprites */ switch (renderMode) { diff --git a/source/shaders/circlevert.glsl b/source/shaders/circlevert.glsl index e98286a..602dc54 100644 --- a/source/shaders/circlevert.glsl +++ b/source/shaders/circlevert.glsl @@ -7,8 +7,13 @@ layout (std140) uniform Projection mat4 projection; }; +layout (std140) uniform Resolution +{ + vec2 resolution; +}; + void main() { gl_Position = projection * vec4(vertex.xy, 0.0, 1.0); - coords = vertex.zw; -} \ No newline at end of file + coords = vertex.zw*resolution; +}