瀏覽代碼

Moved GLString Unit Test

Thomas Buck 11 年之前
父節點
當前提交
2f63765e31
共有 4 個檔案被更改,包括 320 行新增340 行删除
  1. 1
    1
      Makefile
  2. 0
    10
      include/GLString.h
  3. 0
    329
      src/GLString.cpp
  4. 319
    0
      test/GLString.cpp

+ 1
- 1
Makefile 查看文件

@@ -307,7 +307,7 @@ GLString.test:
307 307
 	$(shell sdl-config --cflags) $(shell sdl-config --libs) \
308 308
 	$(GL_LIBS) $(GL_DEFS) -lm -lstdc++ \
309 309
 	src/Texture.cpp src/mtk_tga.cpp \
310
-	src/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
310
+	src/GLString.cpp test/GLString.cpp -o $(BUILD_TEST_DIR)/GLString.test
311 311
 
312 312
 #################################################################
313 313
 

+ 0
- 10
include/GLString.h 查看文件

@@ -119,16 +119,6 @@ public:
119 119
     gl_string_t *GetString(unsigned int id);
120 120
 
121 121
 
122
-#ifdef __TEST__
123
-    /*!
124
-     * \brief Tests GLString
125
-     * \param argc length of argv
126
-     * \param argv array of argument strings
127
-     * \returns 0 on success or an error id
128
-     */
129
-    int _RegressionTest(int argc, char *argv[]);
130
-#endif
131
-
132 122
 private:
133 123
     unsigned int _num_string_max; //!< Max number of strings buffered
134 124
     unsigned int _num_font_max; //!< Max number of font faces

+ 0
- 329
src/GLString.cpp 查看文件

@@ -401,332 +401,3 @@ gl_string_t *GLString::GetString(unsigned int id)
401 401
 	return NULL;
402 402
 }
403 403
 
404
-
405
-////////////////////////////////////////////////////////////
406
-// Test code
407
-////////////////////////////////////////////////////////////
408
-
409
-
410
-#ifdef __TEST__
411
-
412
-#include <math.h>
413
-
414
-#ifdef __APPLE__
415
-#include <OpenGL/glu.h>
416
-#else
417
-#include <GL/glu.h>
418
-#endif
419
-
420
-#ifdef HAVE_MTK
421
-#include <Texture.h>
422
-#include <mtk_tga.h>
423
-
424
-Texture gTexture;
425
-#else
426
-#error "Requires MTK: Texture and mtk_tga"
427
-#endif
428
-
429
-
430
-GLString *TEXT;
431
-
432
-void swap_buffers();
433
-
434
-
435
-void event_resize(int width, int height)
436
-{
437
-	GLfloat aspect;
438
-
439
-	glMatrixMode(GL_PROJECTION);
440
-	aspect = (GLfloat)width/(GLfloat)height;
441
-
442
-	// Mongoose 2002.01.01, Setup view volume, with a nice FOV
443
-	gluPerspective(40.0, aspect, 1, 2000);
444
-
445
-	glMatrixMode(GL_MODELVIEW);
446
-}
447
-
448
-
449
-void event_display(int width, int height)
450
-{
451
-	static float x = 0.0, y = 0.0, z = -150.0, r = 0.0;
452
-
453
-
454
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
455
-	glLoadIdentity();
456
-
457
-	glTranslatef(0.0, 0.0, -20.0);
458
-	glRotatef((float)cos(r)*180.0, 0.0, 0.0, 1.0);
459
-	r += 0.01;
460
-
461
-	// Mongoose 2002.01.01, Render color quad
462
-	glDisable(GL_TEXTURE_2D);
463
-	glBegin(GL_TRIANGLE_STRIP);
464
-	glColor3f(1.0, 0.0, 0.0);
465
-	glVertex3f(x + 50, y + 50, z);
466
-	glColor3f(0.0, 1.0, 0.0);
467
-	glVertex3f(x - 50, y + 50, z);
468
-	glColor3f(0.0, 0.0, 1.0);
469
-	glVertex3f(x + 50, y - 50, z);
470
-	glColor3f(0.5, 0.5, 0.5);
471
-	glVertex3f(x - 50, y - 50, z);
472
-	glEnd();
473
-
474
-	// Mongoose 2002.01.01, Render text
475
-	glDisable(GL_CULL_FACE);
476
-	glEnable(GL_BLEND);
477
-	glEnable(GL_TEXTURE_2D);
478
-	glColor3f(0.1, 0.2, 1.0);
479
-	TEXT->Render(width, height);
480
-
481
-	glFlush();
482
-	swap_buffers();
483
-}
484
-
485
-
486
-#ifdef HAVE_SDL
487
-#include <SDL/SDL.h>
488
-
489
-
490
-SDL_Surface *SDL_WINDOW = NULL;
491
-
492
-
493
-void swap_buffers()
494
-{
495
-	SDL_GL_SwapBuffers();
496
-}
497
-
498
-
499
-void shutdown_gl()
500
-{
501
-	SDL_Quit();
502
-}
503
-
504
-
505
-void init_gl(unsigned int width, unsigned int height,
506
-				 int argc, char *argv[])
507
-{
508
-	int i, j;
509
-	int id[4];
510
-	float s = 1.0;
511
-
512
-
513
-	// Setup GL
514
-	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
515
-	glShadeModel(GL_SMOOTH);
516
-	glEnable(GL_DEPTH_TEST);
517
-	glDepthFunc(GL_LESS);
518
-	glEnable(GL_BLEND);
519
-	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
520
-
521
-	event_resize(width, height);
522
-
523
-	// Mongoose 2002.01.01, Texture setup
524
-	gTexture.reset();
525
-	gTexture.setFlag(Texture::fUseMipmaps);
526
-	gTexture.setMaxTextureCount(32);
527
-
528
-	if (argc > 1)
529
-	{
530
-		for (i = 1, j = 0; i < argc; ++i, ++j)
531
-		{
532
-			if (j < 4)
533
-			{
534
-				id[j++] = gTexture.loadTGA(argv[i]);
535
-			}
536
-		}
537
-	}
538
-	else
539
-	{
540
-		id[0] = gTexture.loadTGA("data/font-0.tga");
541
-		id[1] = gTexture.loadTGA("data/font-0.tga");
542
-		id[2] = gTexture.loadTGA("data/font-0.tga");
543
-		id[3] = gTexture.loadTGA("data/font-0.tga");
544
-	}
545
-
546
-	printf("%i %i %i %i\n", id[0], id[1], id[2], id[3]);
547
-
548
-	TEXT->Init(4, 4, id);
549
-	i = TEXT->glPrintf((width/2)-12*5, height/2, 0,
550
-							 "[font %i] GLString Test", id[0]);
551
-	if (i)
552
-	{
553
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
554
-	}
555
-
556
-	i = TEXT->glPrintf((width/2)-10*7, height/2+32, 1,
557
-							 "[font %i] GLString Test", id[1]);
558
-
559
-	if (i)
560
-	{
561
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
562
-	}
563
-
564
-	s = 1.1;
565
-	TEXT->Scale(s);
566
-
567
-	i = TEXT->glPrintf((width/2)-10*7, height/2+64, 1,
568
-							 "[font %i] Scaled by %.3f", id[1], s);
569
-
570
-	if (i)
571
-	{
572
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
573
-	}
574
-	i = TEXT->glPrintf((width/2)-10*7, height/2-32, 0,
575
-							 "[font %i] Scaled by %.3f", id[0], s);
576
-
577
-	if (i)
578
-	{
579
-		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
580
-	}
581
-}
582
-
583
-
584
-int main_gl(int argc, char *argv[])
585
-{
586
-  SDL_Event event;
587
-  unsigned int mkeys, mod, key;
588
-  int flags;
589
-  unsigned int width = 640;
590
-  unsigned int height = 460;
591
-  bool fullscreen = false;
592
-  char *driver = NULL;
593
-
594
-
595
-  // Setup clean up on exit
596
-  atexit(shutdown_gl);
597
-
598
-  // Get user settings
599
-  //event_init(&width, &height, &fullscreen, &driver, argc, argv);
600
-
601
-  // Create GL context
602
-  SDL_Init(SDL_INIT_VIDEO);
603
-
604
-#ifndef __APPLE__
605
-  if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0)
606
-  {
607
-	  SDL_ClearError();
608
-
609
-	  // Fallback 1
610
-	  if (SDL_GL_LoadLibrary("libGL.so") < 0)
611
-	  {
612
-		  SDL_ClearError();
613
-
614
-		  // Fallback 2
615
-		  if (SDL_GL_LoadLibrary("libGL.so.1") < 0)
616
-		  {
617
-			  fprintf(stderr, "main_gl> SDL_GL_LoadLibrary failed!\n");
618
-			  fprintf(stderr, "main_gl> Error is [%s].\n", SDL_GetError());
619
-			  exit(1);
620
-		  }
621
-	  }
622
-  }
623
-#endif
624
-
625
-  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
626
-
627
-  if (fullscreen)
628
-  {
629
-	  flags |= SDL_FULLSCREEN;
630
-	  SDL_ShowCursor(SDL_DISABLE);
631
-  }
632
-
633
-  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
634
-  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
635
-  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
636
-  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
637
-  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
638
-  SDL_WINDOW = SDL_SetVideoMode(width, height, 16, flags);
639
-  SDL_WM_SetCaption("GLString Test", "GLString Test");
640
-  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
641
-
642
-  // Init rendering
643
-  init_gl(width, height, argc, argv);
644
-
645
-  for (;;)
646
-  {
647
-	  // Pause for 10-20 ms
648
-	  SDL_Delay(10);
649
-
650
-	  event_display(width, height);
651
-
652
-	  while (SDL_PollEvent(&event))
653
-	  {
654
-		  switch (event.type)
655
-		  {
656
-		  case SDL_QUIT:
657
-			  exit(0);
658
-			  break;
659
-		  case SDL_MOUSEMOTION:
660
-			  break;
661
-		  case SDL_MOUSEBUTTONDOWN:
662
-		  case SDL_MOUSEBUTTONUP:
663
-			  break;
664
-		  case SDL_KEYDOWN:
665
-			  mkeys = (unsigned int)SDL_GetModState();
666
-			  mod = 0;
667
-
668
-			  if (mkeys & KMOD_LSHIFT)
669
-				  mod |= KMOD_LSHIFT;
670
-
671
-			  if (mkeys & KMOD_RSHIFT)
672
-				  mod |= KMOD_RSHIFT;
673
-
674
-			  if (mkeys & KMOD_LCTRL)
675
-				  mod |= KMOD_LCTRL;
676
-
677
-			  if (mkeys & KMOD_RCTRL)
678
-				  mod |= KMOD_RCTRL;
679
-
680
-			  if (mkeys & KMOD_LALT)
681
-				  mod |= KMOD_LALT;
682
-
683
-			  if (mkeys & KMOD_RALT)
684
-				  mod |= KMOD_RALT;
685
-
686
-			  key = event.key.keysym.sym;
687
-
688
-			  switch (key)
689
-			  {
690
-			  case 0x1B: // 27d, ESC
691
-				  exit(0);
692
-				  break;
693
-			  }
694
-			  break;
695
-		  case SDL_KEYUP:
696
-			  break;
697
-		  case SDL_VIDEORESIZE:
698
-			  event_resize(event.resize.w, event.resize.h);
699
-
700
-			  width = event.resize.w;
701
-			  height = event.resize.h;
702
-			  event_display(width, height);
703
-			  break;
704
-		  }
705
-	  }
706
-  }
707
-
708
-  return 0;
709
-}
710
-#else
711
-#error "Requires SDL to create GL Context"
712
-#endif
713
-
714
-
715
-int GLString::_RegressionTest(int argc, char *argv[])
716
-{
717
-	TEXT = this;
718
-	main_gl(argc, argv);
719
-	return 0;
720
-}
721
-
722
-
723
-int main(int argc, char *argv[])
724
-{
725
-  GLString test;
726
-
727
-
728
-  printf("[GLString class test]\n");
729
-
730
-  return test._RegressionTest(argc, argv);
731
-}
732
-#endif

+ 319
- 0
test/GLString.cpp 查看文件

@@ -0,0 +1,319 @@
1
+/*!
2
+ * \file GLString.cpp
3
+ * \brief Open GL rendering font/string Unit Test
4
+ *
5
+ * \author Mongoose
6
+ */
7
+
8
+#include <math.h>
9
+
10
+#ifdef __APPLE__
11
+#include <OpenGL/glu.h>
12
+#else
13
+#include <GL/glu.h>
14
+#endif
15
+
16
+#ifdef HAVE_MTK
17
+#include <Texture.h>
18
+#include <mtk_tga.h>
19
+
20
+Texture gTexture;
21
+#else
22
+#error "Requires MTK: Texture and mtk_tga"
23
+#endif
24
+
25
+#include <GLString.h>
26
+
27
+GLString *TEXT;
28
+
29
+void swap_buffers();
30
+
31
+
32
+void event_resize(int width, int height)
33
+{
34
+	GLfloat aspect;
35
+
36
+	glMatrixMode(GL_PROJECTION);
37
+	aspect = (GLfloat)width/(GLfloat)height;
38
+
39
+	// Mongoose 2002.01.01, Setup view volume, with a nice FOV
40
+	gluPerspective(40.0, aspect, 1, 2000);
41
+
42
+	glMatrixMode(GL_MODELVIEW);
43
+}
44
+
45
+
46
+void event_display(int width, int height)
47
+{
48
+	static float x = 0.0, y = 0.0, z = -150.0, r = 0.0;
49
+
50
+
51
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
52
+	glLoadIdentity();
53
+
54
+	glTranslatef(0.0, 0.0, -20.0);
55
+	glRotatef((float)cos(r)*180.0, 0.0, 0.0, 1.0);
56
+	r += 0.01;
57
+
58
+	// Mongoose 2002.01.01, Render color quad
59
+	glDisable(GL_TEXTURE_2D);
60
+	glBegin(GL_TRIANGLE_STRIP);
61
+	glColor3f(1.0, 0.0, 0.0);
62
+	glVertex3f(x + 50, y + 50, z);
63
+	glColor3f(0.0, 1.0, 0.0);
64
+	glVertex3f(x - 50, y + 50, z);
65
+	glColor3f(0.0, 0.0, 1.0);
66
+	glVertex3f(x + 50, y - 50, z);
67
+	glColor3f(0.5, 0.5, 0.5);
68
+	glVertex3f(x - 50, y - 50, z);
69
+	glEnd();
70
+
71
+	// Mongoose 2002.01.01, Render text
72
+	glDisable(GL_CULL_FACE);
73
+	glEnable(GL_BLEND);
74
+	glEnable(GL_TEXTURE_2D);
75
+	glColor3f(0.1, 0.2, 1.0);
76
+	TEXT->Render(width, height);
77
+
78
+	glFlush();
79
+	swap_buffers();
80
+}
81
+
82
+
83
+#ifdef HAVE_SDL
84
+#include <SDL/SDL.h>
85
+
86
+
87
+SDL_Surface *SDL_WINDOW = NULL;
88
+
89
+
90
+void swap_buffers()
91
+{
92
+	SDL_GL_SwapBuffers();
93
+}
94
+
95
+
96
+void shutdown_gl()
97
+{
98
+	SDL_Quit();
99
+}
100
+
101
+
102
+void init_gl(unsigned int width, unsigned int height,
103
+				 int argc, char *argv[])
104
+{
105
+	int i, j;
106
+	int id[4];
107
+	float s = 1.0;
108
+
109
+
110
+	// Setup GL
111
+	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
112
+	glShadeModel(GL_SMOOTH);
113
+	glEnable(GL_DEPTH_TEST);
114
+	glDepthFunc(GL_LESS);
115
+	glEnable(GL_BLEND);
116
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
117
+
118
+	event_resize(width, height);
119
+
120
+	// Mongoose 2002.01.01, Texture setup
121
+	gTexture.reset();
122
+	gTexture.setFlag(Texture::fUseMipmaps);
123
+	gTexture.setMaxTextureCount(32);
124
+
125
+	if (argc > 1)
126
+	{
127
+		for (i = 1, j = 0; i < argc; ++i, ++j)
128
+		{
129
+			if (j < 4)
130
+			{
131
+				id[j++] = gTexture.loadTGA(argv[i]);
132
+			}
133
+		}
134
+	}
135
+	else
136
+	{
137
+		id[0] = gTexture.loadTGA("data/font-0.tga");
138
+		id[1] = gTexture.loadTGA("data/font-0.tga");
139
+		id[2] = gTexture.loadTGA("data/font-0.tga");
140
+		id[3] = gTexture.loadTGA("data/font-0.tga");
141
+	}
142
+
143
+	printf("%i %i %i %i\n", id[0], id[1], id[2], id[3]);
144
+
145
+	TEXT->Init(4, 4, id);
146
+	i = TEXT->glPrintf((width/2)-12*5, height/2, 0,
147
+							 "[font %i] GLString Test", id[0]);
148
+	if (i)
149
+	{
150
+		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
151
+	}
152
+
153
+	i = TEXT->glPrintf((width/2)-10*7, height/2+32, 1,
154
+							 "[font %i] GLString Test", id[1]);
155
+
156
+	if (i)
157
+	{
158
+		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
159
+	}
160
+
161
+	s = 1.1;
162
+	TEXT->Scale(s);
163
+
164
+	i = TEXT->glPrintf((width/2)-10*7, height/2+64, 1,
165
+							 "[font %i] Scaled by %.3f", id[1], s);
166
+
167
+	if (i)
168
+	{
169
+		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
170
+	}
171
+	i = TEXT->glPrintf((width/2)-10*7, height/2-32, 0,
172
+							 "[font %i] Scaled by %.3f", id[0], s);
173
+
174
+	if (i)
175
+	{
176
+		printf("TEXT->glPrintf> ERROR code %i ( 0 means no error )\n", i);
177
+	}
178
+}
179
+
180
+
181
+int main_gl(int argc, char *argv[])
182
+{
183
+  SDL_Event event;
184
+  unsigned int mkeys, mod, key;
185
+  int flags;
186
+  unsigned int width = 640;
187
+  unsigned int height = 460;
188
+  bool fullscreen = false;
189
+  char *driver = NULL;
190
+
191
+
192
+  // Setup clean up on exit
193
+  atexit(shutdown_gl);
194
+
195
+  // Get user settings
196
+  //event_init(&width, &height, &fullscreen, &driver, argc, argv);
197
+
198
+  // Create GL context
199
+  SDL_Init(SDL_INIT_VIDEO);
200
+
201
+#ifndef __APPLE__
202
+  if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0)
203
+  {
204
+	  SDL_ClearError();
205
+
206
+	  // Fallback 1
207
+	  if (SDL_GL_LoadLibrary("libGL.so") < 0)
208
+	  {
209
+		  SDL_ClearError();
210
+
211
+		  // Fallback 2
212
+		  if (SDL_GL_LoadLibrary("libGL.so.1") < 0)
213
+		  {
214
+			  fprintf(stderr, "main_gl> SDL_GL_LoadLibrary failed!\n");
215
+			  fprintf(stderr, "main_gl> Error is [%s].\n", SDL_GetError());
216
+			  exit(1);
217
+		  }
218
+	  }
219
+  }
220
+#endif
221
+
222
+  flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
223
+
224
+  if (fullscreen)
225
+  {
226
+	  flags |= SDL_FULLSCREEN;
227
+	  SDL_ShowCursor(SDL_DISABLE);
228
+  }
229
+
230
+  SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
231
+  SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
232
+  SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
233
+  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
234
+  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
235
+  SDL_WINDOW = SDL_SetVideoMode(width, height, 16, flags);
236
+  SDL_WM_SetCaption("GLString Test", "GLString Test");
237
+  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
238
+
239
+  // Init rendering
240
+  init_gl(width, height, argc, argv);
241
+
242
+  for (;;)
243
+  {
244
+	  // Pause for 10-20 ms
245
+	  SDL_Delay(10);
246
+
247
+	  event_display(width, height);
248
+
249
+	  while (SDL_PollEvent(&event))
250
+	  {
251
+		  switch (event.type)
252
+		  {
253
+		  case SDL_QUIT:
254
+			  exit(0);
255
+			  break;
256
+		  case SDL_MOUSEMOTION:
257
+			  break;
258
+		  case SDL_MOUSEBUTTONDOWN:
259
+		  case SDL_MOUSEBUTTONUP:
260
+			  break;
261
+		  case SDL_KEYDOWN:
262
+			  mkeys = (unsigned int)SDL_GetModState();
263
+			  mod = 0;
264
+
265
+			  if (mkeys & KMOD_LSHIFT)
266
+				  mod |= KMOD_LSHIFT;
267
+
268
+			  if (mkeys & KMOD_RSHIFT)
269
+				  mod |= KMOD_RSHIFT;
270
+
271
+			  if (mkeys & KMOD_LCTRL)
272
+				  mod |= KMOD_LCTRL;
273
+
274
+			  if (mkeys & KMOD_RCTRL)
275
+				  mod |= KMOD_RCTRL;
276
+
277
+			  if (mkeys & KMOD_LALT)
278
+				  mod |= KMOD_LALT;
279
+
280
+			  if (mkeys & KMOD_RALT)
281
+				  mod |= KMOD_RALT;
282
+
283
+			  key = event.key.keysym.sym;
284
+
285
+			  switch (key)
286
+			  {
287
+			  case 0x1B: // 27d, ESC
288
+				  exit(0);
289
+				  break;
290
+			  }
291
+			  break;
292
+		  case SDL_KEYUP:
293
+			  break;
294
+		  case SDL_VIDEORESIZE:
295
+			  event_resize(event.resize.w, event.resize.h);
296
+
297
+			  width = event.resize.w;
298
+			  height = event.resize.h;
299
+			  event_display(width, height);
300
+			  break;
301
+		  }
302
+	  }
303
+  }
304
+
305
+  return 0;
306
+}
307
+#else
308
+#error "Requires SDL to create GL Context"
309
+#endif
310
+
311
+int main(int argc, char *argv[])
312
+{
313
+  printf("[GLString class test]\n");
314
+
315
+  TEXT = new GLString();
316
+  main_gl(argc, argv);
317
+  return 0;
318
+}
319
+

Loading…
取消
儲存