Ver código fonte

Finished most of WindowSDL

Thomas Buck 10 anos atrás
pai
commit
fe8d624d75
5 arquivos alterados com 51 adições e 4 exclusões
  1. 2
    0
      include/OpenRaider.h
  2. 2
    2
      include/Window.h
  3. 15
    1
      src/OpenRaider.cpp
  4. 31
    1
      src/Window.cpp
  5. 1
    0
      src/main.cpp

+ 2
- 0
include/OpenRaider.h Ver arquivo

32
      */
32
      */
33
     int loadConfig(const char *config);
33
     int loadConfig(const char *config);
34
 
34
 
35
+    int initialize();
36
+
35
 private:
37
 private:
36
     Window *mWindow;
38
     Window *mWindow;
37
 };
39
 };

+ 2
- 2
include/Window.h Ver arquivo

23
     /*!
23
     /*!
24
      * \brief Deconstructs an object of Window
24
      * \brief Deconstructs an object of Window
25
      */
25
      */
26
-    virtual ~Window() {}
26
+    virtual ~Window();
27
 
27
 
28
     virtual void setSize(unsigned int width, unsigned int height) = 0;
28
     virtual void setSize(unsigned int width, unsigned int height) = 0;
29
 
29
 
35
 
35
 
36
     virtual void writeString(WindowString *s) = 0;
36
     virtual void writeString(WindowString *s) = 0;
37
 
37
 
38
-    virtual void resizeGL(unsigned int width, unsigned int height);
38
+    virtual void resizeGL(unsigned int w, unsigned int h);
39
 };
39
 };
40
 
40
 
41
 #endif
41
 #endif

+ 15
- 1
src/OpenRaider.cpp Ver arquivo

8
 #include <cstdio>
8
 #include <cstdio>
9
 #include <assert.h>
9
 #include <assert.h>
10
 
10
 
11
+#include "WindowSDL.h"
12
+
11
 #include "utils/strings.h"
13
 #include "utils/strings.h"
12
 #include "OpenRaider.h"
14
 #include "OpenRaider.h"
13
 
15
 
14
 OpenRaider::OpenRaider() {
16
 OpenRaider::OpenRaider() {
17
+    mWindow = NULL;
15
 }
18
 }
16
 
19
 
17
 OpenRaider::~OpenRaider() {
20
 OpenRaider::~OpenRaider() {
21
+    if (mWindow)
22
+        delete mWindow;
18
 }
23
 }
19
 
24
 
20
 int OpenRaider::loadConfig(const char *config) {
25
 int OpenRaider::loadConfig(const char *config) {
23
     char *configFile = fullPath(config, 0);
28
     char *configFile = fullPath(config, 0);
24
     printf("Trying to load \"%s\"...\n", configFile);
29
     printf("Trying to load \"%s\"...\n", configFile);
25
 
30
 
26
-    return -1;
31
+    return 0;
32
+}
33
+
34
+int OpenRaider::initialize() {
35
+    assert(mWindow == NULL);
36
+
37
+    mWindow = new WindowSDL();
38
+    mWindow->initialize();
39
+
40
+    return 0;
27
 }
41
 }
28
 
42
 

+ 31
- 1
src/Window.cpp Ver arquivo

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#include <assert.h>
8
 
9
 
10
+#ifdef __APPLE__
11
+#include <OpenGL/gl.h>
12
+#include <OpenGL/glu.h>
13
+#else
14
+#include <GL/gl.h>
15
+#include <GL/glu.h>
16
+#endif
17
+
18
+#include "math/math.h"
9
 #include "Window.h"
19
 #include "Window.h"
10
 
20
 
11
-void Window::resizeGL(unsigned int width, unsigned int height) {
21
+Window::~Window() {
22
+}
23
+
24
+void Window::resizeGL(unsigned int w, unsigned int h) {
25
+    float fovY = 45.0f;
26
+    float clipNear = 4.0f;
27
+    float clipFar = 4000.0f;
28
+
29
+    assert(w > 0);
30
+    assert(h > 0);
31
+
32
+    glViewport(0, 0, w, h);
33
+    glMatrixMode(GL_PROJECTION);
34
+    glLoadIdentity();
35
+
36
+    // Adjust clipping
37
+    GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
38
+    GLfloat fW = fH * ((GLfloat)w) / ((GLfloat)h);
39
+    glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
12
 
40
 
41
+    glMatrixMode(GL_MODELVIEW);
42
+    glLoadIdentity();
13
 }
43
 }
14
 
44
 

+ 1
- 0
src/main.cpp Ver arquivo

69
     }
69
     }
70
 
70
 
71
     // Initialize the "subsystems"
71
     // Initialize the "subsystems"
72
+    gOpenRaider->initialize();
72
 
73
 
73
     return 0;
74
     return 0;
74
 }
75
 }

Carregando…
Cancelar
Salvar