testgles2_sdf: build with CMake + fix build errors/warnings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 676a8e7..778cb79 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -127,6 +127,7 @@ add_sdl_test_executable(testgesture testgesture.c)
add_sdl_test_executable(testgl2 testgl2.c)
add_sdl_test_executable(testgles testgles.c)
add_sdl_test_executable(testgles2 testgles2.c)
+add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES testgles2_sdf.c testutils.c)
add_sdl_test_executable(testhaptic testhaptic.c)
add_sdl_test_executable(testhotplug testhotplug.c)
add_sdl_test_executable(testrumble testrumble.c)
@@ -329,7 +330,7 @@ if(N3DS)
foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
- ctr_generate_smdh("${SMDH_FILE}"
+ ctr_generate_smdh("${SMDH_FILE}"
NAME "SDL-${APP}"
DESCRIPTION "SDL2 Test suite"
AUTHOR "SDL2 Contributors"
@@ -366,7 +367,7 @@ foreach(APP IN LISTS SDL_TESTS_NEEDS_RESOURCES)
endif()
endforeach(RESOURCE_FILE)
if(APPLE)
- # Make sure resource files get installed into macOS/iOS .app bundles.
+ # Make sure resource files get installed into macOS/iOS .app bundles.
target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
endif()
diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index 93c21b9..a61f9ba 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>
@@ -29,6 +26,8 @@
#include "SDL_opengles2.h"
+#include "testutils.h"
+
typedef struct GLES2_Context
{
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
@@ -56,7 +55,7 @@ typedef enum
} GLES2_Uniform;
-GLuint g_uniform_locations[16];
+GLint g_uniform_locations[16];
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
@@ -127,8 +126,8 @@ quit(int rc)
* source: Passed-in shader source code.
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
-void
-process_shader(GLuint *shader, const char * source, GLint shader_type)
+void
+process_shader(GLint *shader, const char *source, GLenum shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
@@ -153,7 +152,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
if (status != GL_TRUE) {
ctx.glGetShaderInfoLog(*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);
}
}
@@ -163,7 +162,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; \
@@ -183,7 +182,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; \
@@ -197,7 +196,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; \
@@ -246,7 +245,7 @@ static float matrix_mvp[4][4];
typedef struct shader_data
{
- GLuint shader_program, shader_frag, shader_vert;
+ GLint shader_program, shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
@@ -254,7 +253,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);
@@ -273,7 +272,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;
@@ -293,15 +292,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;
@@ -342,43 +341,26 @@ void loop()
if (sym == SDLK_TAB) {
SDL_Log("Tab");
-
-
}
if (sym == SDLK_LEFT) {
- g_val -= 0.05;
+ g_val -= 0.05f;
}
if (sym == SDLK_RIGHT) {
- g_val += 0.05;
+ g_val += 0.05f;
}
if (sym == SDLK_UP) {
- g_angle -= 1;
+ g_angle -= 1.0f;
}
if (sym == SDLK_DOWN) {
- g_angle += 1;
+ g_angle += 1.0f;
}
-
break;
}
- if (sym == SDLK_LEFT) {
- g_val -= 0.05f;
- }
- if (sym == SDLK_RIGHT) {
- g_val += 0.05f;
- }
- if (sym == SDLK_UP) {
- g_angle -= 1.0f;
- }
- if (sym == SDLK_DOWN) {
- g_angle += 1.0f;
- }
-
break;
- }
case SDL_WINDOWEVENT:
switch (event.window.event) {
@@ -411,19 +393,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);
@@ -434,7 +406,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);
}
@@ -803,9 +775,9 @@ int main(int argc, char *argv[])
SDL_Log("%2.2f frames per second\n",
((double)frames * 1000) / (now - then));
}
-#if !defined(__ANDROID__) && !defined(__NACL__)
+#if !defined(__ANDROID__) && !defined(__NACL__)
quit(0);
-#endif
+#endif
return 0;
}