Procházet zdrojové kódy

gl and glfw wrapper

Kajetan Johannes Hammerle před 3 roky
rodič
revize
70c3bed894
7 změnil soubory, kde provedl 102 přidání a 2 odebrání
  1. 3 1
      meson.build
  2. 59 0
      wrapper/GL.cpp
  3. 14 0
      wrapper/GL.h
  4. 17 0
      wrapper/GLFW.cpp
  5. 8 0
      wrapper/GLFW.h
  6. 1 1
      wrapper/Texture.cpp
  7. 0 0
      wrapper/Texture.h

+ 3 - 1
meson.build

@@ -30,7 +30,9 @@ sources = ['Main.cpp',
     'tests/ClockTests.cpp',
     'images/PNGReader.cpp',
     'tests/PNGReaderTests.cpp',
-    'gl/Texture.cpp']
+    'wrapper/Texture.cpp',
+    'wrapper/GL.cpp',
+    'wrapper/GLFW.cpp']
 
 glewDep = dependency('glew')
 glfwDep = dependency('glfw3')

+ 59 - 0
wrapper/GL.cpp

@@ -0,0 +1,59 @@
+#include <GL/glew.h>
+#include <iostream>
+
+#include "wrapper/GL.h"
+
+bool GL::checkAndPrintError(const char* message) {
+    GLenum error = glGetError();
+    switch(error) {
+        case GL_NO_ERROR:
+            return false;
+        case GL_INVALID_ENUM:
+            std::cout << message << ": an unacceptable value is specified for an enumerated argument\n";
+            break;
+        case GL_INVALID_VALUE:
+            std::cout << message << ": a numeric argument is out of range\n";
+            break;
+        case GL_INVALID_OPERATION:
+            std::cout << message << ": the specified operation is not allowed in the current state\n";
+            break;
+        case GL_INVALID_FRAMEBUFFER_OPERATION:
+            std::cout << message << ": the framebuffer object is not complete\n";
+            break;
+        case GL_OUT_OF_MEMORY:
+            std::cout << message << ": there is not enough memory left to execute the command\n";
+            break;
+        case GL_STACK_UNDERFLOW:
+            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow\n";
+            break;
+        case GL_STACK_OVERFLOW:
+            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow\n";
+            break;
+        default:
+            std::cout << message << ": unknown OpenGL error '" << error << ''"\n";
+    }
+    return true;
+}
+
+void GL::enableDepthTesting() {
+    glEnable(GL_DEPTH_TEST);
+}
+
+void GL::disableDepthTesting() {
+    glDisable(GL_DEPTH_TEST);
+}
+
+void GL::prepareMainFramebuffer() {
+    glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+}
+
+void GL::enableBlending() {
+    glEnable(GL_BLEND);
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glBlendEquation(GL_FUNC_ADD);
+}
+
+void GL::disableBlending() {
+    glDisable(GL_BLEND);
+}

+ 14 - 0
wrapper/GL.h

@@ -0,0 +1,14 @@
+#ifndef GL_H
+#define GL_H
+
+namespace GL {
+    bool checkAndPrintError(const char* message);
+    void enableDepthTesting();
+    void disableDepthTesting();
+    void prepareMainFramebuffer();
+    void enableBlending();
+    void disableBlending();
+}
+
+
+#endif

+ 17 - 0
wrapper/GLFW.cpp

@@ -0,0 +1,17 @@
+#include <iostream>
+
+#include <GL/glew.h>
+#include <GLFW/glfw3.h>
+
+#include "wrapper/GLFW.h"
+
+bool GLFW::init() {
+    if(glfwInit()) {
+        atexit([]() {
+            glfwTerminate();
+        });
+        return false;
+    }
+    std::cout << "could not initialize GLFW\n";
+    return true;
+}

+ 8 - 0
wrapper/GLFW.h

@@ -0,0 +1,8 @@
+#ifndef GLFW_H
+#define GLFW_H
+
+namespace GLFW {
+    bool init();
+}
+
+#endif

+ 1 - 1
gl/Texture.cpp → wrapper/Texture.cpp

@@ -1,4 +1,4 @@
-#include "gl/Texture.h"
+#include "wrapper/Texture.h"
 
 Texture::Texture(Mode mode) : texture(0) {
     glGenTextures(1, &texture);

+ 0 - 0
gl/Texture.h → wrapper/Texture.h