Browse Source

GLString Unit Test uses TTF font.

Now works every time.
Thomas Buck 11 years ago
parent
commit
f8ef0e75ff
4 changed files with 58 additions and 70 deletions
  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 View File

305
 
305
 
306
 GLString.test:
306
 GLString.test:
307
 	mkdir -p $(BUILD_TEST_DIR)
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
 	$(shell sdl-config --cflags) $(shell sdl-config --libs) \
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 View File

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

+ 3
- 1
src/Texture.cpp View File

285
 		delete [] texture->texture;
285
 		delete [] texture->texture;
286
 		delete [] texture->glyphs;
286
 		delete [] texture->glyphs;
287
 		delete texture;
287
 		delete texture;
288
+
289
+        return gFontTest->textureId;
288
 	}
290
 	}
289
 	else
291
 	else
290
 	{
292
 	{
291
 		return -2;
293
 		return -2;
292
 	}
294
 	}
293
 
295
 
294
-	return 0;
296
+	return -3;
295
 }
297
 }
296
 
298
 
297
 
299
 

+ 48
- 63
test/GLString.cpp View File

13
 #include <GL/glu.h>
13
 #include <GL/glu.h>
14
 #endif
14
 #endif
15
 
15
 
16
-#ifdef HAVE_MTK
16
+#ifdef HAVE_SDL_TTF
17
 #include <Texture.h>
17
 #include <Texture.h>
18
-#include <mtk_tga.h>
19
-
20
 Texture gTexture;
18
 Texture gTexture;
21
 #else
19
 #else
22
-#error "Requires MTK: Texture and mtk_tga"
20
+#error "Requires SDL_TTF"
23
 #endif
21
 #endif
24
 
22
 
25
 #include <GLString.h>
23
 #include <GLString.h>
77
 	glDisable(GL_CULL_FACE);
75
 	glDisable(GL_CULL_FACE);
78
 	glEnable(GL_BLEND);
76
 	glEnable(GL_BLEND);
79
 	glEnable(GL_TEXTURE_2D);
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
 	TEXT->Render(width, height);
81
 	TEXT->Render(width, height);
82
+    glExitMode2d();
82
 
83
 
83
 	glFlush();
84
 	glFlush();
84
 	swap_buffers();
85
 	swap_buffers();
103
 	SDL_Quit();
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
 	// Setup GL
113
 	// Setup GL
116
 	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
114
 	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
127
 	gTexture.setFlag(Texture::fUseMipmaps);
125
 	gTexture.setFlag(Texture::fUseMipmaps);
128
 	gTexture.setMaxTextureCount(32);
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
   }
195
   }
224
 #endif
196
 #endif
225
 
197
 
226
-  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
198
+  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE;
227
 
199
 
228
   if (fullscreen)
200
   if (fullscreen)
229
   {
201
   {
241
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
213
   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
242
 
214
 
243
   // Init rendering
215
   // Init rendering
244
-  init_gl(width, height, argc, argv);
216
+  init_gl(width, height);
245
 
217
 
246
   for (;;)
218
   for (;;)
247
   {
219
   {
284
 			  if (mkeys & KMOD_RALT)
256
 			  if (mkeys & KMOD_RALT)
285
 				  mod |= KMOD_RALT;
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
 			  key = event.key.keysym.sym;
265
 			  key = event.key.keysym.sym;
288
 
266
 
289
 			  switch (key)
267
 			  switch (key)
291
 			  case 0x1B: // 27d, ESC
269
 			  case 0x1B: // 27d, ESC
292
 				  exit(0);
270
 				  exit(0);
293
 				  break;
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
 			  break;
281
 			  break;
296
 		  case SDL_KEYUP:
282
 		  case SDL_KEYUP:
297
 			  break;
283
 			  break;
298
 		  case SDL_VIDEORESIZE:
284
 		  case SDL_VIDEORESIZE:
299
-			  event_resize(event.resize.w, event.resize.h);
300
-
301
 			  width = event.resize.w;
285
 			  width = event.resize.w;
302
 			  height = event.resize.h;
286
 			  height = event.resize.h;
287
+			  event_resize(width, height);
303
 			  event_display(width, height);
288
 			  event_display(width, height);
304
 			  break;
289
 			  break;
305
 		  }
290
 		  }

Loading…
Cancel
Save