Browse Source

Font rendering working

Thomas Buck 10 years ago
parent
commit
947533bb1b
3 changed files with 46 additions and 16 deletions
  1. 9
    0
      include/WindowSDL.h
  2. 6
    3
      src/OpenRaider.cpp
  3. 31
    13
      src/WindowSDL.cpp

+ 9
- 0
include/WindowSDL.h View File

11
 #include "SDL.h"
11
 #include "SDL.h"
12
 #include "SDL_ttf.h"
12
 #include "SDL_ttf.h"
13
 
13
 
14
+#ifdef __APPLE__
15
+#include <OpenGL/gl.h>
16
+#include <OpenGL/glu.h>
17
+#else
18
+#include <GL/gl.h>
19
+#include <GL/glu.h>
20
+#endif
21
+
14
 #include "Window.h"
22
 #include "Window.h"
15
 
23
 
16
 /*!
24
 /*!
64
     bool mFontInit;
72
     bool mFontInit;
65
     char *mFontName;
73
     char *mFontName;
66
     TTF_Font *mFont;
74
     TTF_Font *mFont;
75
+    GLuint mFontTexture;
67
 };
76
 };
68
 
77
 
69
 #endif
78
 #endif

+ 6
- 3
src/OpenRaider.cpp View File

68
 
68
 
69
         mWindow->eventHandling();
69
         mWindow->eventHandling();
70
 
70
 
71
-        /*WindowString s;
71
+        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
72
+        glClear(GL_COLOR_BUFFER_BIT);
73
+
74
+        WindowString s;
72
         s.text = bufferString("Hello World");
75
         s.text = bufferString("Hello World");
73
         s.x = 100;
76
         s.x = 100;
74
         s.y = 100;
77
         s.y = 100;
75
-        s.scale = 1.0;
78
+        s.scale = 1.5f;
76
         s.color[0] = s.color[1] = s.color[2] = 0xFF;
79
         s.color[0] = s.color[1] = s.color[2] = 0xFF;
77
-        mWindow->writeString(&s);*/
80
+        mWindow->writeString(&s);
78
 
81
 
79
         mWindow->swapBuffersGL();
82
         mWindow->swapBuffersGL();
80
 
83
 

+ 31
- 13
src/WindowSDL.cpp View File

228
         return -2;
228
         return -2;
229
     }
229
     }
230
 
230
 
231
+    glGenTextures(1, &mFontTexture);
232
+
231
     mFontInit = true;
233
     mFontInit = true;
232
     return 0;
234
     return 0;
233
 }
235
 }
248
         return;
250
         return;
249
     }
251
     }
250
 
252
 
251
-    SDL_Surface *window = SDL_GetWindowSurface(mWindow);
252
-    if (window == NULL) {
253
-        printf("SDL_GetWindowSurface Error: %s\n", SDL_GetError());
254
-        return;
253
+    GLenum textureFormat;
254
+    if (surface->format->BytesPerPixel == 4) {
255
+        if (surface->format->Rmask == 0x000000FF)
256
+            textureFormat = GL_RGBA;
257
+        else
258
+            textureFormat = GL_BGRA_EXT;
259
+    } else {
260
+        textureFormat = GL_RGB;
255
     }
261
     }
256
 
262
 
257
-    SDL_Rect destination;
258
-    destination.x = s->x;
259
-    destination.y = s->y;
260
-    destination.w = (int)((float)surface->w * s->scale);
261
-    destination.h = (int)((float)surface->h * s->scale);
263
+    glBindTexture(GL_TEXTURE_2D, mFontTexture);
264
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
265
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
266
+    glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
262
 
267
 
263
-    if (SDL_BlitScaled(surface, NULL, window, &destination) != 0) {
264
-        printf("SDL_BlitScaled Error: %s\n", SDL_GetError());
265
-        return;
266
-    }
268
+    glEnter2D(mWidth, mHeight);
269
+
270
+    glBegin(GL_QUADS);
271
+        glTexCoord2f(0.0f, 0.0f);
272
+        glVertex2i(s->x, s->y);
273
+
274
+        glTexCoord2f(0.0f, 1.0f);
275
+        glVertex2i(s->x, (int)((float)surface->h * s->scale));
276
+
277
+        glTexCoord2f(1.0f, 1.0f);
278
+        glVertex2i((int)((float)surface->w * s->scale), (int)((float)surface->h * s->scale));
279
+
280
+        glTexCoord2f(1.0f, 0.0f);
281
+        glVertex2i((int)((float)surface->w * s->scale), s->y);
282
+    glEnd();
283
+
284
+    glExit2D();
267
 
285
 
268
     SDL_FreeSurface(surface);
286
     SDL_FreeSurface(surface);
269
 }
287
 }

Loading…
Cancel
Save