Thomas Buck 10 лет назад
Родитель
Сommit
947533bb1b
3 измененных файлов: 46 добавлений и 16 удалений
  1. 9
    0
      include/WindowSDL.h
  2. 6
    3
      src/OpenRaider.cpp
  3. 31
    13
      src/WindowSDL.cpp

+ 9
- 0
include/WindowSDL.h Просмотреть файл

@@ -11,6 +11,14 @@
11 11
 #include "SDL.h"
12 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 22
 #include "Window.h"
15 23
 
16 24
 /*!
@@ -64,6 +72,7 @@ private:
64 72
     bool mFontInit;
65 73
     char *mFontName;
66 74
     TTF_Font *mFont;
75
+    GLuint mFontTexture;
67 76
 };
68 77
 
69 78
 #endif

+ 6
- 3
src/OpenRaider.cpp Просмотреть файл

@@ -68,13 +68,16 @@ void OpenRaider::run() {
68 68
 
69 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 75
         s.text = bufferString("Hello World");
73 76
         s.x = 100;
74 77
         s.y = 100;
75
-        s.scale = 1.0;
78
+        s.scale = 1.5f;
76 79
         s.color[0] = s.color[1] = s.color[2] = 0xFF;
77
-        mWindow->writeString(&s);*/
80
+        mWindow->writeString(&s);
78 81
 
79 82
         mWindow->swapBuffersGL();
80 83
 

+ 31
- 13
src/WindowSDL.cpp Просмотреть файл

@@ -228,6 +228,8 @@ int WindowSDL::initializeFont() {
228 228
         return -2;
229 229
     }
230 230
 
231
+    glGenTextures(1, &mFontTexture);
232
+
231 233
     mFontInit = true;
232 234
     return 0;
233 235
 }
@@ -248,22 +250,38 @@ void WindowSDL::writeString(WindowString *s) {
248 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 286
     SDL_FreeSurface(surface);
269 287
 }

Загрузка…
Отмена
Сохранить