sdl2-compat: fix test/testgles2_sdf.c warnings

From d8a9e165288436206b96e4e1edc8cffb94b2d197 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 29 Nov 2022 23:57:53 +0100
Subject: [PATCH] fix test/testgles2_sdf.c warnings

---
 test/testgles2_sdf.c | 60 ++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)

diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index 1386d55..cb5808b 100644
--- a/test/testgles2_sdf.c
+++ b/test/testgles2_sdf.c
@@ -10,9 +10,6 @@
   freely.
 */
 #include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
 
 #ifdef __EMSCRIPTEN__
 #include <emscripten/emscripten.h>
@@ -62,7 +59,7 @@ typedef enum
 } GLES2_Uniform;
 
 
-GLuint g_uniform_locations[16];
+GLint g_uniform_locations[16];
 
 
 
@@ -141,7 +138,7 @@ quit(int rc)
  * shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
  */
 void 
-process_shader(GLuint *shader, const char * source, GLint shader_type)
+process_shader(GLenum *shader, const char * source, GLenum shader_type)
 {
     GLint status = GL_FALSE;
     const char *shaders[1] = { NULL };
@@ -166,7 +163,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
     if(status != GL_TRUE) {
         ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
         buffer[length] = '\0';
-        SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
+        SDL_Log("Shader compilation failed: %s", buffer);
         quit(-1);
     }
 }
@@ -176,7 +173,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
  * To get correct rotation for most cases when a_angle is disabled cosine
  * value is decremented by 1.0 to get proper output with 0.0 which is default value
  */
-static const Uint8 GLES2_VertexSrc_Default_[] = " \
+static const char GLES2_VertexSrc_Default_[] = " \
     uniform mat4 u_projection; \
     attribute vec2 a_position; \
     attribute vec2 a_texCoord; \
@@ -196,7 +193,7 @@ static const Uint8 GLES2_VertexSrc_Default_[] = " \
     } \
 ";
 
-static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
+static const char GLES2_FragmentSrc_TextureABGRSrc_[] = " \
     precision mediump float; \
     uniform sampler2D u_texture; \
     uniform vec4 u_color; \
@@ -210,7 +207,7 @@ static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
 ";
 
 /* RGB to ABGR conversion */
-static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \
+static const char GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \
     #extension GL_OES_standard_derivatives : enable\n\
     \
     precision mediump float; \
@@ -263,7 +260,8 @@ static float matrix_mvp[4][4];
 
 typedef struct shader_data
 {
-    GLuint shader_program, shader_frag, shader_vert;
+    GLint shader_program;
+    GLenum shader_frag, shader_vert;
 
     GLint attr_position;
     GLint attr_color, attr_mvp;
@@ -271,7 +269,7 @@ typedef struct shader_data
 } shader_data;
 
 static void
-Render(unsigned int width, unsigned int height, shader_data* data)
+Render(int width, int height, shader_data* data)
 {
     float *verts = g_verts;
     ctx.glViewport(0, 0, 640, 480);
@@ -291,7 +289,7 @@ Render(unsigned int width, unsigned int height, shader_data* data)
 
 void renderCopy_angle(float degree_angle) 
 {
-    const float radian_angle = (float)(3.141592 * degree_angle) / 180.0;
+    const float radian_angle = (float)(3.141592 * degree_angle) / 180.0f;
     const GLfloat s = (GLfloat) SDL_sin(radian_angle);
     const GLfloat c = (GLfloat) SDL_cos(radian_angle) - 1.0f;
     GLfloat *verts = g_verts + 16;
@@ -312,15 +310,15 @@ void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
     GLfloat minu, maxu, minv, maxv;
     GLfloat *verts = g_verts;
 
-    minx = dstrect->x;
-    miny = dstrect->y;
-    maxx = dstrect->x + dstrect->w;
-    maxy = dstrect->y + dstrect->h;
+    minx = (GLfloat)dstrect->x;
+    miny = (GLfloat)dstrect->y;
+    maxx = (GLfloat)(dstrect->x + dstrect->w);
+    maxy = (GLfloat)(dstrect->y + dstrect->h);
 
-    minu = (GLfloat) srcrect->x / g_surf_sdf->w;
-    maxu = (GLfloat) (srcrect->x + srcrect->w) / g_surf_sdf->w;
-    minv = (GLfloat) srcrect->y / g_surf_sdf->h;
-    maxv = (GLfloat) (srcrect->y + srcrect->h) / g_surf_sdf->h;
+    minu = (GLfloat) srcrect->x / (GLfloat)g_surf_sdf->w;
+    maxu = (GLfloat) (srcrect->x + srcrect->w) / (GLfloat)g_surf_sdf->w;
+    minv = (GLfloat) srcrect->y / (GLfloat)g_surf_sdf->h;
+    maxv = (GLfloat) (srcrect->y + srcrect->h) / (GLfloat)g_surf_sdf->h;
 
     *(verts++) = minx;
     *(verts++) = miny;
@@ -368,9 +366,10 @@ void loop()
 
                 if (sym == SDLK_LEFT)  g_val -= 0.05;
                 if (sym == SDLK_RIGHT) g_val += 0.05;
-                if (sym == SDLK_UP)    g_angle -= 1;
-                if (sym == SDLK_DOWN)  g_angle += 1;
  
+                if (sym == SDLK_UP)    g_angle -= 1.0f;
+                if (sym == SDLK_DOWN)  g_angle += 1.0f;
+
 
                 break;
             }
@@ -407,20 +406,9 @@ void loop()
     matrix_mvp[3][0] = -1.0f;
     matrix_mvp[3][3] = 1.0f;
 
-    matrix_mvp[0][0] = 2.0f / 640.0;
-    matrix_mvp[1][1] = -2.0f / 480.0;
+    matrix_mvp[0][0] = 2.0f / 640.0f;
+    matrix_mvp[1][1] = -2.0f / 480.0f;
     matrix_mvp[3][1] = 1.0f;
-    
-    if (0)
-    {
-        float *f = (float *) matrix_mvp;
-        SDL_Log("-----------------------------------");
-        SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
-        SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
-        SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
-        SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
-        SDL_Log("-----------------------------------");
-    }
 
     renderCopy_angle(g_angle);
 
@@ -431,7 +419,7 @@ void loop()
         SDL_GL_GetDrawableSize(state->windows[0], &w, &h);
 
         rs.x = 0; rs.y = 0; rs.w = g_surf_sdf->w; rs.h = g_surf_sdf->h;
-        rd.w = g_surf_sdf->w * g_val; rd.h = g_surf_sdf->h * g_val;
+        rd.w = (int)((float)g_surf_sdf->w * g_val); rd.h = (int)((float)g_surf_sdf->h * g_val);
         rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2;
         renderCopy_position(&rs, &rd);
     }