Thomas Buck 10 anni fa
parent
commit
64d182c6cb
3 ha cambiato i file con 62 aggiunte e 0 eliminazioni
  1. 4
    0
      include/Window.h
  2. 37
    0
      src/Window.cpp
  3. 21
    0
      src/WindowSDL.cpp

+ 4
- 0
include/Window.h Vedi File

@@ -46,6 +46,10 @@ public:
46 46
 
47 47
     virtual void resizeGL(unsigned int w, unsigned int h);
48 48
 
49
+    virtual void glEnter2D(unsigned int width, unsigned int height);
50
+
51
+    virtual void glExit2D();
52
+
49 53
     virtual void setFont(const char *font) = 0;
50 54
 
51 55
     virtual int initializeFont() = 0;

+ 37
- 0
src/Window.cpp Vedi File

@@ -42,3 +42,40 @@ void Window::resizeGL(unsigned int w, unsigned int h) {
42 42
     glLoadIdentity();
43 43
 }
44 44
 
45
+void Window::glEnter2D(unsigned int width, unsigned int height) {
46
+    glPushAttrib(GL_ENABLE_BIT);
47
+    glDisable(GL_DEPTH_TEST);
48
+    glDisable(GL_CULL_FACE);
49
+    glEnable(GL_TEXTURE_2D);
50
+
51
+    /* This allows alpha blending of 2D textures with the scene */
52
+    glEnable(GL_BLEND);
53
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
54
+
55
+    glViewport(0, 0, width, height);
56
+
57
+    glMatrixMode(GL_PROJECTION);
58
+    glPushMatrix();
59
+    glLoadIdentity();
60
+
61
+    glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, 0.0, 1.0);
62
+
63
+    glMatrixMode(GL_MODELVIEW);
64
+    glPushMatrix();
65
+    glLoadIdentity();
66
+
67
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
68
+}
69
+
70
+void Window::glExit2D() {
71
+    glMatrixMode(GL_MODELVIEW);
72
+    glPopMatrix();
73
+
74
+    glMatrixMode(GL_PROJECTION);
75
+    glPopMatrix();
76
+
77
+    glPopAttrib();
78
+
79
+    glMatrixMode(GL_MODELVIEW);
80
+}
81
+

+ 21
- 0
src/WindowSDL.cpp Vedi File

@@ -8,6 +8,16 @@
8 8
 #include <cstdio>
9 9
 #include <assert.h>
10 10
 
11
+#include "SDL_ttf.h"
12
+
13
+#ifdef __APPLE__
14
+#include <OpenGL/gl.h>
15
+#include <OpenGL/glu.h>
16
+#else
17
+#include <GL/gl.h>
18
+#include <GL/glu.h>
19
+#endif
20
+
11 21
 #include "config.h"
12 22
 #include "utils/strings.h"
13 23
 #include "WindowSDL.h"
@@ -39,8 +49,14 @@ WindowSDL::~WindowSDL() {
39 49
         SDL_Quit();
40 50
     }
41 51
 
52
+    if (mFontInit)
53
+        TTF_Quit();
54
+
42 55
     if (mDriver)
43 56
         delete [] mDriver;
57
+
58
+    if (mFont)
59
+        delete [] mFont;
44 60
 }
45 61
 
46 62
 void WindowSDL::setDriver(const char *driver) {
@@ -207,6 +223,11 @@ int WindowSDL::initializeFont() {
207 223
     assert(mFont != NULL);
208 224
     assert(mFont[0] != '\0');
209 225
 
226
+    if (TTF_Init() != 0) {
227
+        printf("Could not initialize SDL-TTF!\n");
228
+        return -1;
229
+    }
230
+
210 231
     mFontInit = true;
211 232
     return 0;
212 233
 }

Loading…
Annulla
Salva