ソースを参照

Added GL initialization

Thomas Buck 10年前
コミット
841ec1cd84
3個のファイルの変更83行の追加4行の削除
  1. 2
    0
      include/Window.h
  2. 7
    4
      src/OpenRaider.cpp
  3. 74
    0
      src/Window.cpp

+ 2
- 0
include/Window.h ファイルの表示

@@ -45,6 +45,8 @@ public:
45 45
 
46 46
     virtual void swapBuffersGL() = 0;
47 47
 
48
+    virtual int initializeGL();
49
+
48 50
     virtual void resizeGL(unsigned int w, unsigned int h);
49 51
 
50 52
     virtual void glEnter2D(unsigned int width, unsigned int height);

+ 7
- 4
src/OpenRaider.cpp ファイルの表示

@@ -47,11 +47,15 @@ int OpenRaider::initialize() {
47 47
     if (mWindow->initialize() != 0)
48 48
         return -1;
49 49
 
50
+    // Initialize OpenGL
51
+    if (mWindow->initializeGL() != 0)
52
+        return -2;
53
+
50 54
     mWindow->setFont("~/.OpenRaider/data/test.ttf");
51 55
 
52
-    // Initialize windows font
56
+    // Initialize window font
53 57
     if (mWindow->initializeFont() != 0)
54
-        return -2;
58
+        return -3;
55 59
 
56 60
     mInit = true;
57 61
 
@@ -68,11 +72,10 @@ void OpenRaider::run() {
68 72
 
69 73
         mWindow->eventHandling();
70 74
 
71
-        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
72 75
         glClear(GL_COLOR_BUFFER_BIT);
73 76
 
74 77
         WindowString s;
75
-        s.text = bufferString("Hello World");
78
+        s.text = bufferString("This text is not fixed-width...");
76 79
         s.x = 100;
77 80
         s.y = 100;
78 81
         s.scale = 1.5f;

+ 74
- 0
src/Window.cpp ファイルの表示

@@ -5,6 +5,8 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <cstdio>
9
+#include <cstring>
8 10
 #include <assert.h>
9 11
 
10 12
 #ifdef __APPLE__
@@ -21,6 +23,78 @@
21 23
 Window::~Window() {
22 24
 }
23 25
 
26
+int Window::initializeGL() {
27
+    // Print driver support information
28
+    printf("GL Vendor  : %s\n", glGetString(GL_VENDOR));
29
+    printf("GL Renderer: %s\n", glGetString(GL_RENDERER));
30
+    printf("GL Version : %s\n", glGetString(GL_VERSION));
31
+
32
+    // Testing for goodies
33
+    const char *s = (const char *)glGetString(GL_EXTENSIONS);
34
+    if ((s != NULL) && (s[0] != '\0')) {
35
+        //if (strstr(s, "GL_ARB_multitexture"))
36
+            //mFlags |= Render::fMultiTexture;
37
+    }
38
+
39
+    // Set up Z buffer
40
+    glEnable(GL_DEPTH_TEST);
41
+    glDepthFunc(GL_LESS);
42
+
43
+    // Set up culling
44
+    glEnable(GL_CULL_FACE);
45
+    glFrontFace(GL_CW);
46
+    //glFrontFace(GL_CCW);
47
+    //glCullFace(GL_FRONT);
48
+
49
+    // Set background to black
50
+    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
51
+
52
+    // Disable lighting
53
+    glDisable(GL_LIGHTING);
54
+
55
+    // Set up alpha blending
56
+    glEnable(GL_BLEND);
57
+    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
58
+
59
+    //glEnable(GL_ALPHA_TEST); // Disable per pixel alpha blending
60
+    glAlphaFunc(GL_GREATER, 0);
61
+
62
+    glPointSize(5.0);
63
+
64
+    // Setup shading
65
+    glShadeModel(GL_SMOOTH);
66
+
67
+    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
68
+    glHint(GL_FOG_HINT, GL_NICEST);
69
+    glEnable(GL_COLOR_MATERIAL);
70
+    glEnable(GL_DITHER);
71
+
72
+    // AA polygon edges
73
+    glEnable(GL_POLYGON_SMOOTH);
74
+    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
75
+
76
+    glDisable(GL_LINE_SMOOTH);
77
+    glDisable(GL_POINT_SMOOTH);
78
+    glDisable(GL_AUTO_NORMAL);
79
+    glDisable(GL_LOGIC_OP);
80
+    glDisable(GL_TEXTURE_1D);
81
+    glDisable(GL_STENCIL_TEST);
82
+    glDisable(GL_FOG);
83
+
84
+    glDisable(GL_NORMALIZE);
85
+
86
+    glEnableClientState(GL_VERTEX_ARRAY);
87
+    glDisableClientState(GL_EDGE_FLAG_ARRAY);
88
+    glDisableClientState(GL_COLOR_ARRAY);
89
+    glDisableClientState(GL_NORMAL_ARRAY);
90
+
91
+    glPolygonMode(GL_FRONT, GL_FILL);
92
+
93
+    glMatrixMode(GL_MODELVIEW);
94
+
95
+    return 0;
96
+}
97
+
24 98
 void Window::resizeGL(unsigned int w, unsigned int h) {
25 99
     float fovY = 45.0f;
26 100
     float clipNear = 4.0f;

読み込み中…
キャンセル
保存