Pārlūkot izejas kodu

Finished most of WindowSDL

Thomas Buck 10 gadus atpakaļ
vecāks
revīzija
fe8d624d75
5 mainītis faili ar 51 papildinājumiem un 4 dzēšanām
  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 Parādīt failu

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

+ 2
- 2
include/Window.h Parādīt failu

@@ -23,7 +23,7 @@ public:
23 23
     /*!
24 24
      * \brief Deconstructs an object of Window
25 25
      */
26
-    virtual ~Window() {}
26
+    virtual ~Window();
27 27
 
28 28
     virtual void setSize(unsigned int width, unsigned int height) = 0;
29 29
 
@@ -35,7 +35,7 @@ public:
35 35
 
36 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 41
 #endif

+ 15
- 1
src/OpenRaider.cpp Parādīt failu

@@ -8,13 +8,18 @@
8 8
 #include <cstdio>
9 9
 #include <assert.h>
10 10
 
11
+#include "WindowSDL.h"
12
+
11 13
 #include "utils/strings.h"
12 14
 #include "OpenRaider.h"
13 15
 
14 16
 OpenRaider::OpenRaider() {
17
+    mWindow = NULL;
15 18
 }
16 19
 
17 20
 OpenRaider::~OpenRaider() {
21
+    if (mWindow)
22
+        delete mWindow;
18 23
 }
19 24
 
20 25
 int OpenRaider::loadConfig(const char *config) {
@@ -23,6 +28,15 @@ int OpenRaider::loadConfig(const char *config) {
23 28
     char *configFile = fullPath(config, 0);
24 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 Parādīt failu

@@ -5,10 +5,40 @@
5 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 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 Parādīt failu

@@ -69,6 +69,7 @@ int main(int argc, char *argv[]) {
69 69
     }
70 70
 
71 71
     // Initialize the "subsystems"
72
+    gOpenRaider->initialize();
72 73
 
73 74
     return 0;
74 75
 }

Notiek ielāde…
Atcelt
Saglabāt