Explorar el Código

GLString Unit Test uses TTF font.

Now works every time.
Thomas Buck hace 11 años
padre
commit
f8ef0e75ff
Se han modificado 4 ficheros con 58 adiciones y 70 borrados
  1. 4
    4
      Makefile
  2. 3
    2
      src/Render.cpp
  3. 3
    1
      src/Texture.cpp
  4. 48
    63
      test/GLString.cpp

+ 4
- 4
Makefile Ver fichero

@@ -305,11 +305,11 @@ TombRaider.test:
305 305
 
306 306
 GLString.test:
307 307
 	mkdir -p $(BUILD_TEST_DIR)
308
-	$(CC) -Wall -Iinclude -DHAVE_MTK -DHAVE_SDL -DUSING_MTK_TGA \
308
+	$(CC) -Wall -Iinclude -DHAVE_SDL_TTF -DHAVE_SDL \
309 309
 	$(shell sdl-config --cflags) $(shell sdl-config --libs) \
310
-	$(GL_LIBS) $(GL_DEFS) -lm -lstdc++ \
311
-	src/Texture.cpp src/mtk_tga.cpp \
312
-	src/GLString.cpp test/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
310
+	$(GL_LIBS) $(GL_DEFS) -lSDL_ttf -lm -lstdc++ \
311
+	src/Texture.cpp src/GLString.cpp \
312
+	test/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
313 313
 
314 314
 #################################################################
315 315
 

+ 3
- 2
src/Render.cpp Ver fichero

@@ -252,9 +252,9 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
252 252
 	}
253 253
 
254 254
 	extern char *gFontFilename;
255
-	if ((mTexture.loadFontTTF(gFontFilename,
255
+	if (mTexture.loadFontTTF(gFontFilename,
256 256
 									  //0x303f, 0x3093-0x303f)) // Hiragana
257
-									  32, 126 - 32))  // ASCII
257
+									  32, 126 - 32)  // ASCII
258 258
 		 > -1)
259 259
 	{
260 260
 		++numTextures;
@@ -266,6 +266,7 @@ void Render::initTextures(char *textureDir, unsigned int *numLoaded,
266 266
 	if ((font_id = mTexture.loadTGA(filename)) > -1)
267 267
 	{
268 268
 		++numTextures;
269
+        printf("Loaded TGA Font into %d\n", font_id);
269 270
 	}
270 271
 
271 272
 	// Werid that it isn't linear, must be some storage deal in Texture

+ 3
- 1
src/Texture.cpp Ver fichero

@@ -285,13 +285,15 @@ int Texture::loadFontTTF(const char *filename,
285 285
 		delete [] texture->texture;
286 286
 		delete [] texture->glyphs;
287 287
 		delete texture;
288
+
289
+        return gFontTest->textureId;
288 290
 	}
289 291
 	else
290 292
 	{
291 293
 		return -2;
292 294
 	}
293 295
 
294
-	return 0;
296
+	return -3;
295 297
 }
296 298
 
297 299
 

+ 48
- 63
test/GLString.cpp Ver fichero

@@ -13,13 +13,11 @@
13 13
 #include <GL/glu.h>
14 14
 #endif
15 15
 
16
-#ifdef HAVE_MTK
16
+#ifdef HAVE_SDL_TTF
17 17
 #include <Texture.h>
18
-#include <mtk_tga.h>
19
-
20 18
 Texture gTexture;
21 19
 #else
22
-#error "Requires MTK: Texture and mtk_tga"
20
+#error "Requires SDL_TTF"
23 21
 #endif
24 22
 
25 23
 #include <GLString.h>
@@ -77,8 +75,11 @@ void event_display(int width, int height)
77 75
 	glDisable(GL_CULL_FACE);
78 76
 	glEnable(GL_BLEND);
79 77
 	glEnable(GL_TEXTURE_2D);
80
-	glColor3f(0.1, 0.2, 1.0);
78
+	glColor3f(0.75, 0.5, 1.0);
79
+
80
+    glEnterMode2d(width, height);
81 81
 	TEXT->Render(width, height);
82
+    glExitMode2d();
82 83
 
83 84
 	glFlush();
84 85
 	swap_buffers();
@@ -103,14 +104,11 @@ void shutdown_gl()
103 104
 	SDL_Quit();
104 105
 }
105 106
 
106
-
107
-void init_gl(unsigned int width, unsigned int height,
108
-				 int argc, char *argv[])
107
+void init_gl(unsigned int width, unsigned int height)
109 108
 {
110
-	int i, j;
111
-	int id[4];
112
-	float s = 1.0;
113
-
109
+    int i;
110
+	int id;
111
+    const char *errorText = "TEXT->glPrintf> ERROR code %i\n";
114 112
 
115 113
 	// Setup GL
116 114
 	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -127,56 +125,30 @@ void init_gl(unsigned int width, unsigned int height,
127 125
 	gTexture.setFlag(Texture::fUseMipmaps);
128 126
 	gTexture.setMaxTextureCount(32);
129 127
 
130
-	if (argc > 1)
131
-	{
132
-		for (i = 1, j = 0; i < argc; ++i, ++j)
133
-		{
134
-			if (j < 4)
135
-			{
136
-				id[j] = gTexture.loadTGA(argv[i]);
137
-			}
138
-		}
139
-	}
140
-	else
141
-	{
142
-		// id[0] = gTexture.loadTGA("data/font-0.tga");
143
-		// id[1] = gTexture.loadTGA("data/font-1.tga");
144
-		// id[2] = gTexture.loadTGA("data/font-2.tga");
145
-		// id[3] = gTexture.loadTGA("data/font-3.tga");
146
-        id[0] = id[1] = id[2] = id[3] = gTexture.loadTGA("data/font-0.tga");
147
-	}
128
+    id = gTexture.loadFontTTF("data/test.ttf", 32, 126 - 32);  // ASCII
148 129
 
149
-	TEXT->Init(4, 4, id);
150
-	i = TEXT->glPrintf((width/2)-12*5, height/2, 0,
151
-							 "[font %i] GLString Test", id[0]);
152
-	if (i)
153
-	{
154
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
130
+	TEXT->Init(4, 1, &id);
131
+    i = TEXT->glPrintf((width/2)-50, height/2-32, 0, "OpenRaider");
132
+    if (i) {
133
+        printf(errorText, i);
134
+    }
135
+	i = TEXT->glPrintf((width/2)-50, height/2, 0, "GLString");
136
+	if (i) {
137
+	    printf(errorText, i);
155 138
 	}
156
-
157
-	i = TEXT->glPrintf((width/2)-12*5, height/2+32, 1,
158
-							 "[font %i] GLString Test", id[1]);
159
-	if (i)
160
-	{
161
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
162
-	}
163
-
164
-	s = 1.1;
165
-	TEXT->Scale(s);
166
-
167
-	i = TEXT->glPrintf((width/2)-10*7, height/2+64, 1,
168
-							 "[font %i] Scaled by %.1f", id[2], s);
169
-	if (i)
170
-	{
171
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
172
-	}
173
-
174
-	i = TEXT->glPrintf((width/2)-10*7, height/2-32, 0,
175
-							 "[font %i] Scaled by %.1f", id[3], s);
176
-	if (i)
177
-	{
178
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
139
+	TEXT->Scale(1.2);
140
+	i = TEXT->glPrintf((width/2)-100, height/2+32, 0, "Unit Test by Mongoose");
141
+	if (i) {
142
+        printf(errorText, i);
143
+    }
144
+	i = TEXT->glPrintf((width/2)-100, height/2+64, 0, "ported to TTF by xythobuz");
145
+	if (i) {
146
+        printf(errorText, i);
179 147
 	}
148
+    TEXT->setActive(0, true);
149
+    TEXT->setActive(1, true);
150
+    TEXT->setActive(2, true);
151
+    TEXT->setActive(3, true);
180 152
 }
181 153
 
182 154
 
@@ -223,7 +195,7 @@ int main_gl(int argc, char *argv[])
223 195
   }
224 196
 #endif
225 197
 
226
-  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
198
+  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE;
227 199
 
228 200
   if (fullscreen)
229 201
   {
@@ -241,7 +213,7 @@ int main_gl(int argc, char *argv[])
241 213
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
242 214
 
243 215
   // Init rendering
244
-  init_gl(width, height, argc, argv);
216
+  init_gl(width, height);
245 217
 
246 218
   for (;;)
247 219
   {
@@ -284,6 +256,12 @@ int main_gl(int argc, char *argv[])
284 256
 			  if (mkeys & KMOD_RALT)
285 257
 				  mod |= KMOD_RALT;
286 258
 
259
+              if (mkeys & KMOD_LMETA)
260
+                  mod |= KMOD_LMETA;
261
+
262
+              if (mkeys & KMOD_RMETA)
263
+                  mod |= KMOD_RMETA;
264
+
287 265
 			  key = event.key.keysym.sym;
288 266
 
289 267
 			  switch (key)
@@ -291,15 +269,22 @@ int main_gl(int argc, char *argv[])
291 269
 			  case 0x1B: // 27d, ESC
292 270
 				  exit(0);
293 271
 				  break;
272
+#ifdef __APPLE__
273
+              case 113: // q
274
+                  if ((mod & KMOD_RMETA) || (mod & KMOD_LMETA))
275
+                      exit(0);
276
+                  break;
277
+#endif
278
+              case 114: // r
279
+                  break;
294 280
 			  }
295 281
 			  break;
296 282
 		  case SDL_KEYUP:
297 283
 			  break;
298 284
 		  case SDL_VIDEORESIZE:
299
-			  event_resize(event.resize.w, event.resize.h);
300
-
301 285
 			  width = event.resize.w;
302 286
 			  height = event.resize.h;
287
+			  event_resize(width, height);
303 288
 			  event_display(width, height);
304 289
 			  break;
305 290
 		  }

Loading…
Cancelar
Guardar