Bladeren bron

namespaced opengl, added unicode support, (fixes #80)

naelstrof 7 jaren geleden
bovenliggende
commit
0b66444ad4
15 gewijzigde bestanden met toevoegingen van 4878 en 4841 verwijderingen
  1. 12
    3
      CMakeLists.txt
  2. 43
    43
      src/framebuffer.cpp
  3. 1
    1
      src/framebuffer.hpp
  4. 0
    2131
      src/gl_core_3_0.c
  5. 2773
    0
      src/gl_core_3_0.cpp
  6. 0
    2564
      src/gl_core_3_0.h
  7. 1949
    0
      src/gl_core_3_0.hpp
  8. 24
    24
      src/glrectangle.cpp
  9. 1
    1
      src/glrectangle.hpp
  10. 1
    1
      src/main.cpp
  11. 44
    44
      src/shader.cpp
  12. 1
    1
      src/shader.hpp
  13. 21
    21
      src/slop.cpp
  14. 7
    6
      src/window.cpp
  15. 1
    1
      src/window.hpp

+ 12
- 3
CMakeLists.txt Bestand weergeven

@@ -21,19 +21,19 @@ endif()
21 21
 
22 22
 include_directories("${PROJECT_BINARY_DIR}")
23 23
 
24
-add_definitions(-DSLOP_VERSION="v6.3.44")
24
+add_definitions(-DSLOP_VERSION="v6.3.45")
25 25
 
26 26
 # The names have to be unique unfortunately.
27 27
 set(EXECUTABLE_NAME "slop")
28 28
 set(LIBRARY_NAME "slopy")
29 29
 
30 30
 add_library(${LIBRARY_NAME} SHARED  src/mouse.cpp
31
+                                    src/gl_core_3_0.cpp
31 32
                                     src/keyboard.cpp
32 33
                                     src/x.cpp
33 34
                                     src/slopstates.cpp
34 35
                                     src/framebuffer.cpp
35 36
                                     src/resource.cpp
36
-                                    src/gl_core_3_0.c
37 37
                                     src/shader.cpp
38 38
                                     src/window.cpp
39 39
                                     src/slop.cpp
@@ -72,7 +72,16 @@ target_link_libraries(${LIBRARY_NAME} ${X11_LIBRARIES}
72 72
                                       ${XRENDER_LIBRARY}
73 73
                                       ${XEXT_LIBRARIES})
74 74
 
75
-target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME})
75
+target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} )
76
+
77
+set( SLOP_UNICODE TRUE CACHE BOOL "To enable or disable unicode support, really should be left to TRUE since old nvidia drivers crash with it off." )
78
+if ( SLOP_UNICODE )
79
+    # ICU is required for old nvidia drivers to work for whatever reason.
80
+    find_package(ICU REQUIRED COMPONENTS uc)
81
+    add_definitions(-DCXXOPTS_USE_UNICODE)
82
+    include_directories( ${ICU_INCLUDE_DIR} )
83
+    target_link_libraries(${EXECUTABLE_NAME} ${ICU_UC_LIBRARIES} )
84
+endif()
76 85
 
77 86
 install( TARGETS ${EXECUTABLE_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin" )
78 87
 install( TARGETS ${LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" )

+ 43
- 43
src/framebuffer.cpp Bestand weergeven

@@ -1,17 +1,17 @@
1 1
 #include "framebuffer.hpp"
2 2
 
3 3
 slop::Framebuffer::Framebuffer( int w, int h ) {
4
-    glGenFramebuffers( 1, &fbuffer );
5
-    glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
6
-    glGenTextures(1, &image);
7
-    glBindTexture(GL_TEXTURE_2D, image);
8
-    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
9
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
10
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
11
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
12
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
13
-    glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
14
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
4
+    gl::GenFramebuffers( 1, &fbuffer );
5
+    gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
6
+    gl::GenTextures( 1, &image );
7
+    gl::BindTexture( gl::TEXTURE_2D, image );
8
+    gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGBA, w, h, 0, gl::RGBA, gl::UNSIGNED_BYTE, NULL );
9
+    gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST );
10
+    gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST );
11
+    gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE );
12
+    gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE );
13
+    gl::FramebufferTexture2D( gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, image, 0 );
14
+    gl::BindFramebuffer( gl::FRAMEBUFFER, 0 );
15 15
     // generate our vertex and uv buffers
16 16
     std::vector<glm::vec2> verts;
17 17
     std::vector<glm::vec2> uvs;
@@ -29,11 +29,11 @@ slop::Framebuffer::Framebuffer( int w, int h ) {
29 29
     verts.push_back( glm::vec2(1,-1) );
30 30
     uvs.push_back( glm::vec2( 1, 0 ) );
31 31
 
32
-    glGenBuffers( 2, buffers );
33
-    glBindBuffer( GL_ARRAY_BUFFER, buffers[0] );
34
-    glBufferData( GL_ARRAY_BUFFER, verts.size() * sizeof( glm::vec2 ), &verts[0], GL_STATIC_DRAW );
35
-    glBindBuffer( GL_ARRAY_BUFFER, buffers[1] );
36
-    glBufferData( GL_ARRAY_BUFFER, uvs.size() * sizeof( glm::vec2 ), &uvs[0], GL_STATIC_DRAW );
32
+    gl::GenBuffers( 2, buffers );
33
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffers[0] );
34
+    gl::BufferData( gl::ARRAY_BUFFER, verts.size() * sizeof( glm::vec2 ), &verts[0], gl::STATIC_DRAW );
35
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffers[1] );
36
+    gl::BufferData( gl::ARRAY_BUFFER, uvs.size() * sizeof( glm::vec2 ), &uvs[0], gl::STATIC_DRAW );
37 37
     vertCount = verts.size();
38 38
     generatedDesktopImage = false;
39 39
 }
@@ -45,44 +45,44 @@ void slop::Framebuffer::setShader( slop::Shader* shader ) {
45 45
         XGrabServer(x11->display);
46 46
         XImage* image = XGetImage( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0xffffffff, ZPixmap );
47 47
         XUngrabServer(x11->display);
48
-        glEnable(GL_TEXTURE_2D);
49
-        glGenTextures(1, &desktopImage);
50
-        glBindTexture(GL_TEXTURE_2D, desktopImage);
51
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
52
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
53
-        //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
54
-        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0])));
48
+        gl::Enable(gl::TEXTURE_2D);
49
+        gl::GenTextures(1, &desktopImage);
50
+        gl::BindTexture(gl::TEXTURE_2D, desktopImage);
51
+        gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
52
+        gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
53
+        //gl::TexEnvf(gl::TEXTURE_ENV, gl::TEXTURE_ENV_MODE, gl::MODULATE);
54
+        gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGB, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0, gl::BGRA, gl::UNSIGNED_BYTE, (void*)(&(image->data[0])));
55 55
         XDestroyImage( image );
56 56
         generatedDesktopImage = true;
57 57
     }
58 58
 }
59 59
 
60 60
 slop::Framebuffer::~Framebuffer() {
61
-    glDeleteTextures(1, &image);
62
-    glDeleteFramebuffers(1,&fbuffer);
63
-    glDeleteBuffers(2,buffers);
61
+    gl::DeleteTextures(1, &image);
62
+    gl::DeleteFramebuffers(1,&fbuffer);
63
+    gl::DeleteBuffers(2,buffers);
64 64
 }
65 65
 
66 66
 void slop::Framebuffer::resize( int w, int h ) {
67 67
     // Regenerate the image
68
-    glDeleteTextures(1, &image);
69
-    glBindTexture(GL_TEXTURE_2D, image);
70
-    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
71
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
72
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
68
+    gl::DeleteTextures(1, &image);
69
+    gl::BindTexture(gl::TEXTURE_2D, image);
70
+    gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGBA, w, h, 0, gl::RGBA, gl::UNSIGNED_BYTE, NULL);
71
+    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR);
72
+    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR);
73 73
 
74 74
     // Re-bind it to the framebuffer
75
-    glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
76
-    glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
77
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
75
+    gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
76
+    gl::FramebufferTexture2D( gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, image, 0);
77
+    gl::BindFramebuffer(gl::FRAMEBUFFER, 0);
78 78
 }
79 79
 
80 80
 void slop::Framebuffer::bind() {
81
-    glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
81
+    gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
82 82
 }
83 83
 
84 84
 void slop::Framebuffer::unbind() {
85
-    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
85
+    gl::BindFramebuffer( gl::FRAMEBUFFER, 0 );
86 86
 }
87 87
 
88 88
 void slop::Framebuffer::draw(glm::vec2 mouse, float time, glm::vec4 color){
@@ -102,15 +102,15 @@ void slop::Framebuffer::draw(glm::vec2 mouse, float time, glm::vec4 color){
102 102
     if ( shader->hasParameter( "time" ) ) {
103 103
         shader->setParameter( "time", time );
104 104
     }
105
-    glActiveTexture(GL_TEXTURE0);
106
-    glBindTexture( GL_TEXTURE_2D, image );
105
+    gl::ActiveTexture(gl::TEXTURE0);
106
+    gl::BindTexture( gl::TEXTURE_2D, image );
107 107
     if ( shader->hasParameter( "desktop" ) ) {
108 108
 		shader->setParameter( "desktop", 1 );
109
-        glActiveTexture(GL_TEXTURE0 + 1);
110
-        glBindTexture( GL_TEXTURE_2D, desktopImage );
109
+        gl::ActiveTexture(gl::TEXTURE0 + 1);
110
+        gl::BindTexture( gl::TEXTURE_2D, desktopImage );
111 111
     }
112
-    glEnable( GL_TEXTURE_2D );
113
-    glDrawArrays( GL_TRIANGLES, 0, vertCount );
114
-    glDisable( GL_TEXTURE_2D );
112
+    gl::Enable( gl::TEXTURE_2D );
113
+    gl::DrawArrays( gl::TRIANGLES, 0, vertCount );
114
+    gl::Disable( gl::TEXTURE_2D );
115 115
     shader->unbind();
116 116
 }

+ 1
- 1
src/framebuffer.hpp Bestand weergeven

@@ -21,7 +21,7 @@
21 21
 #ifndef N_FRAMEBUFFER_H_
22 22
 #define N_FRAMEBUFFER_H_
23 23
 
24
-#include "gl_core_3_0.h"
24
+#include "gl_core_3_0.hpp"
25 25
 #include <glm/glm.hpp>
26 26
 #include <GL/gl.h>
27 27
 #include <vector>

+ 0
- 2131
src/gl_core_3_0.c
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 2773
- 0
src/gl_core_3_0.cpp
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 0
- 2564
src/gl_core_3_0.h
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 1949
- 0
src/gl_core_3_0.hpp
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 24
- 24
src/glrectangle.cpp Bestand weergeven

@@ -188,21 +188,21 @@ void slop::GLRectangle::generateBuffers() {
188 188
     center_verts.push_back( br );
189 189
     center_uvs.push_back( glm::vec2(1, 0) );
190 190
 
191
-    glGenBuffers( 6, (GLuint*)&buffer );
192
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.corner_verts );
193
-    glBufferData( GL_ARRAY_BUFFER, corner_verts.size() * sizeof( glm::vec2 ), &corner_verts[0], GL_STATIC_DRAW );
194
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.corner_uvs );
195
-    glBufferData( GL_ARRAY_BUFFER, corner_uvs.size() * sizeof( glm::vec2 ), &corner_uvs[0], GL_STATIC_DRAW );
196
-
197
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.rectangle_verts );
198
-    glBufferData( GL_ARRAY_BUFFER, rectangle_verts.size() * sizeof( glm::vec2 ), &rectangle_verts[0], GL_STATIC_DRAW );
199
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.rectangle_uvs );
200
-    glBufferData( GL_ARRAY_BUFFER, rectangle_uvs.size() * sizeof( glm::vec2 ), &rectangle_uvs[0], GL_STATIC_DRAW );
201
-
202
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.center_verts );
203
-    glBufferData( GL_ARRAY_BUFFER, center_verts.size() * sizeof( glm::vec2 ), &center_verts[0], GL_STATIC_DRAW );
204
-    glBindBuffer( GL_ARRAY_BUFFER, buffer.rectangle_uvs );
205
-    glBufferData( GL_ARRAY_BUFFER, center_uvs.size() * sizeof( glm::vec2 ), &center_uvs[0], GL_STATIC_DRAW );
191
+    gl::GenBuffers( 6, (GLuint*)&buffer );
192
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.corner_verts );
193
+    gl::BufferData( gl::ARRAY_BUFFER, corner_verts.size() * sizeof( glm::vec2 ), &corner_verts[0], gl::STATIC_DRAW );
194
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.corner_uvs );
195
+    gl::BufferData( gl::ARRAY_BUFFER, corner_uvs.size() * sizeof( glm::vec2 ), &corner_uvs[0], gl::STATIC_DRAW );
196
+
197
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.rectangle_verts );
198
+    gl::BufferData( gl::ARRAY_BUFFER, rectangle_verts.size() * sizeof( glm::vec2 ), &rectangle_verts[0], gl::STATIC_DRAW );
199
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.rectangle_uvs );
200
+    gl::BufferData( gl::ARRAY_BUFFER, rectangle_uvs.size() * sizeof( glm::vec2 ), &rectangle_uvs[0], gl::STATIC_DRAW );
201
+
202
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.center_verts );
203
+    gl::BufferData( gl::ARRAY_BUFFER, center_verts.size() * sizeof( glm::vec2 ), &center_verts[0], gl::STATIC_DRAW );
204
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer.rectangle_uvs );
205
+    gl::BufferData( gl::ARRAY_BUFFER, center_uvs.size() * sizeof( glm::vec2 ), &center_uvs[0], gl::STATIC_DRAW );
206 206
     corner_vertCount = corner_verts.size();
207 207
     rectangle_vertCount = rectangle_verts.size();
208 208
     center_vertCount = center_verts.size();
@@ -210,35 +210,35 @@ void slop::GLRectangle::generateBuffers() {
210 210
 
211 211
 slop::GLRectangle::~GLRectangle() {
212 212
     delete shader;
213
-    glDeleteBuffers( 6, (GLuint*)&buffer );
213
+    gl::DeleteBuffers( 6, (GLuint*)&buffer );
214 214
 }
215 215
 
216 216
 void slop::GLRectangle::draw( glm::mat4& matrix ) {
217
-    glEnable( GL_BLEND );
218
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
217
+    gl::Enable( gl::BLEND );
218
+    gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
219 219
     shader->bind();
220 220
     shader->setParameter( "projection", matrix );
221 221
     if ( highlight ) {
222 222
         // Draw the center of the highlight
223 223
         shader->setParameter( "color", color );
224 224
         shader->setAttribute( "position", buffer.center_verts, 2 );
225
-        glDrawArrays(GL_TRIANGLES, 0, center_vertCount );
225
+        gl::DrawArrays(gl::TRIANGLES, 0, center_vertCount );
226 226
         // Set the color to have no alpha, then draw the borders.
227 227
         glm::vec4 fullAlpha = glm::vec4(color.r,color.g,color.b,1);
228 228
         shader->setParameter( "color", fullAlpha );
229 229
         shader->setAttribute( "position", buffer.corner_verts, 2 );
230
-        glDrawArrays(GL_TRIANGLES, 0, corner_vertCount );
230
+        gl::DrawArrays(gl::TRIANGLES, 0, corner_vertCount );
231 231
         shader->setAttribute( "position", buffer.rectangle_verts, 2 );
232
-        glDrawArrays(GL_TRIANGLES, 0, rectangle_vertCount );
232
+        gl::DrawArrays(gl::TRIANGLES, 0, rectangle_vertCount );
233 233
     } else {
234 234
         shader->setParameter( "color", color );
235 235
         shader->setAttribute( "position", buffer.corner_verts, 2 );
236
-        glDrawArrays(GL_TRIANGLES, 0, corner_vertCount );
236
+        gl::DrawArrays(gl::TRIANGLES, 0, corner_vertCount );
237 237
         shader->setAttribute( "position", buffer.rectangle_verts, 2 );
238
-        glDrawArrays(GL_TRIANGLES, 0, rectangle_vertCount );
238
+        gl::DrawArrays(gl::TRIANGLES, 0, rectangle_vertCount );
239 239
     }
240 240
     shader->unbind();
241
-    glDisable( GL_BLEND );
241
+    gl::Disable( gl::BLEND );
242 242
 }
243 243
 
244 244
 glm::vec4 slop::GLRectangle::getRect() {

+ 1
- 1
src/glrectangle.hpp Bestand weergeven

@@ -21,7 +21,7 @@
21 21
 #ifndef N_GLRECTANGLE_H_
22 22
 #define N_GLRECTANGLE_H_
23 23
 
24
-#include "gl_core_3_0.h"
24
+#include "gl_core_3_0.hpp"
25 25
 #include <iostream>
26 26
 #include <glm/glm.hpp>
27 27
 #include <GL/gl.h>

+ 1
- 1
src/main.cpp Bestand weergeven

@@ -24,8 +24,8 @@
24 24
 #include <vector>
25 25
 #include <glm/glm.hpp>
26 26
 
27
-#include "cxxopts.hpp"
28 27
 #include "slop.hpp"
28
+#include "cxxopts.hpp"
29 29
 
30 30
 using namespace slop;
31 31
 

+ 44
- 44
src/shader.cpp Bestand weergeven

@@ -27,7 +27,7 @@ slop::Shader::Shader( std::string vert, std::string frag, bool file ) {
27 27
     const char* fragsrc = frag_contents.c_str();
28 28
 
29 29
     // Create the program to link to.
30
-    program = glCreateProgram();
30
+    program = gl::CreateProgram();
31 31
     
32 32
     if ( vert_contents.length() <= 0 ) {
33 33
         std::string errstring = "Failed to open file (or is empty) `" + vert + "`.\n";
@@ -40,26 +40,26 @@ slop::Shader::Shader( std::string vert, std::string frag, bool file ) {
40 40
     }
41 41
 
42 42
     // Compile both shaders.
43
-    unsigned int vertShader = glCreateShader( GL_VERTEX_SHADER );
44
-    glShaderSource( vertShader, 1, &vertsrc , NULL );
43
+    unsigned int vertShader = gl::CreateShader( gl::VERTEX_SHADER );
44
+    gl::ShaderSource( vertShader, 1, &vertsrc , NULL );
45 45
     std::string errortxt;
46 46
     int err = compile( vertShader, errortxt );
47 47
 
48 48
     if ( err ) {
49 49
         std::string errstring = "Failed to compile shader `" + vert + "`:\n" + errortxt;
50 50
         throw new std::runtime_error(errstring);
51
-        glDeleteShader( vertShader );
51
+        gl::DeleteShader( vertShader );
52 52
         return;
53 53
     }
54 54
 
55
-    unsigned int fragShader = glCreateShader( GL_FRAGMENT_SHADER );
56
-    glShaderSource( fragShader, 1, &fragsrc, NULL );
55
+    unsigned int fragShader = gl::CreateShader( gl::FRAGMENT_SHADER );
56
+    gl::ShaderSource( fragShader, 1, &fragsrc, NULL );
57 57
     err = compile( fragShader, errortxt );
58 58
     if ( err ) {
59 59
         std::string errstring = "Failed to compile shader `" + frag + "`:\n" + errortxt;
60 60
         throw new std::runtime_error(errstring);
61
-        glDeleteShader( vertShader );
62
-        glDeleteShader( fragShader );
61
+        gl::DeleteShader( vertShader );
62
+        gl::DeleteShader( fragShader );
63 63
         return;
64 64
     }
65 65
 
@@ -68,19 +68,19 @@ slop::Shader::Shader( std::string vert, std::string frag, bool file ) {
68 68
     if ( err ) {
69 69
         std::string errstring = "Failed to link shader `" + vert + "` and  `" + frag + "`:\n" + errortxt;
70 70
         throw new std::runtime_error(errstring);
71
-        glDeleteShader( vertShader );
72
-        glDeleteShader( fragShader );
71
+        gl::DeleteShader( vertShader );
72
+        gl::DeleteShader( fragShader );
73 73
         return;
74 74
     }
75 75
 
76 76
     // Clean up :)
77
-    glDeleteShader( vertShader );
78
-    glDeleteShader( fragShader );
79
-    glUseProgram( 0 );
77
+    gl::DeleteShader( vertShader );
78
+    gl::DeleteShader( fragShader );
79
+    gl::UseProgram( 0 );
80 80
 }
81 81
 
82 82
 slop::Shader::~Shader() {
83
-    glDeleteProgram( program );
83
+    gl::DeleteProgram( program );
84 84
 }
85 85
 
86 86
 unsigned int slop::Shader::getProgram() {
@@ -88,20 +88,20 @@ unsigned int slop::Shader::getProgram() {
88 88
 }
89 89
 
90 90
 void slop::Shader::bind() {
91
-    glUseProgram( program );
91
+    gl::UseProgram( program );
92 92
 }
93 93
 
94 94
 int slop::Shader::compile( unsigned int shader, std::string& error ) {
95
-    glCompileShader( shader );
95
+    gl::CompileShader( shader );
96 96
 
97 97
     // Compiling the shader is the easy part, all this junk down here is for printing the error it might generate.
98
-    int result = GL_FALSE;
98
+    int result;
99 99
     int logLength;
100
-    glGetShaderiv( shader, GL_COMPILE_STATUS, &result );
101
-    glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &logLength );
102
-    if ( result == GL_FALSE ) {
100
+    gl::GetShaderiv( shader, gl::COMPILE_STATUS, &result );
101
+    gl::GetShaderiv( shader, gl::INFO_LOG_LENGTH, &logLength );
102
+    if ( result == false ) {
103 103
         char* errormsg = new char[ logLength ];
104
-        glGetShaderInfoLog( shader, logLength, NULL, errormsg );
104
+        gl::GetShaderInfoLog( shader, logLength, NULL, errormsg );
105 105
         error = errormsg;
106 106
         delete[] errormsg;
107 107
         return 1;
@@ -110,18 +110,18 @@ int slop::Shader::compile( unsigned int shader, std::string& error ) {
110 110
 }
111 111
 
112 112
 int slop::Shader::link( unsigned int vertshader, unsigned int fragshader, std::string& error ) {
113
-    glAttachShader( program, vertshader );
114
-    glAttachShader( program, fragshader );
115
-    glLinkProgram( program );
113
+    gl::AttachShader( program, vertshader );
114
+    gl::AttachShader( program, fragshader );
115
+    gl::LinkProgram( program );
116 116
 
117 117
     // Linking the shader is the easy part, all this junk down here is for printing the error it might generate.
118
-    int result = GL_FALSE;
118
+    int result = false;
119 119
     int logLength;
120
-    glGetProgramiv( program, GL_LINK_STATUS, &result);
121
-    glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logLength);
122
-    if ( result == GL_FALSE ) {
120
+    gl::GetProgramiv( program, gl::LINK_STATUS, &result);
121
+    gl::GetProgramiv( program, gl::INFO_LOG_LENGTH, &logLength);
122
+    if ( result == false ) {
123 123
         char* errormsg = new char[ logLength ];
124
-        glGetProgramInfoLog( program, logLength, NULL, errormsg );
124
+        gl::GetProgramInfoLog( program, logLength, NULL, errormsg );
125 125
         error = errormsg;
126 126
         delete[] errormsg;
127 127
         return 1;
@@ -130,47 +130,47 @@ int slop::Shader::link( unsigned int vertshader, unsigned int fragshader, std::s
130 130
 }
131 131
 
132 132
 unsigned int slop::Shader::getUniformLocation( std::string name ) {
133
-    glUseProgram( program );
134
-    return glGetUniformLocation( program, name.c_str() );
133
+    gl::UseProgram( program );
134
+    return gl::GetUniformLocation( program, name.c_str() );
135 135
 }
136 136
 
137 137
 bool slop::Shader::hasParameter( std::string name ) {
138
-    glUseProgram( program );
139
-    return glGetUniformLocation( program, name.c_str() ) != -1;
138
+    gl::UseProgram( program );
139
+    return gl::GetUniformLocation( program, name.c_str() ) != -1;
140 140
 }
141 141
 
142 142
 void slop::Shader::setParameter( std::string name, int foo ) {
143
-    glUniform1i( getUniformLocation( name ), foo );
143
+    gl::Uniform1i( getUniformLocation( name ), foo );
144 144
 }
145 145
 
146 146
 void slop::Shader::setParameter( std::string name, float foo ) {
147
-    glUniform1f( getUniformLocation( name ), foo );
147
+    gl::Uniform1f( getUniformLocation( name ), foo );
148 148
 }
149 149
 
150 150
 void slop::Shader::setParameter( std::string name, glm::mat4& foo ) {
151
-    glUniformMatrix4fv( getUniformLocation( name ), 1, GL_FALSE, glm::value_ptr( foo ) );
151
+    gl::UniformMatrix4fv( getUniformLocation( name ), 1, false, glm::value_ptr( foo ) );
152 152
 }
153 153
 
154 154
 void slop::Shader::setParameter( std::string name, glm::vec4 foo ) {
155
-    glUniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
155
+    gl::Uniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
156 156
 }
157 157
 
158 158
 void slop::Shader::setParameter( std::string name, glm::vec2 foo ) {
159
-    glUniform2f( getUniformLocation( name ), foo.x, foo.y );
159
+    gl::Uniform2f( getUniformLocation( name ), foo.x, foo.y );
160 160
 }
161 161
 
162 162
 void slop::Shader::setAttribute( std::string name, unsigned int buffer, unsigned int stepsize ) {
163
-    unsigned int a = glGetAttribLocation( program, name.c_str() );
164
-    glEnableVertexAttribArray( a );
165
-    glBindBuffer( GL_ARRAY_BUFFER, buffer );
166
-    glVertexAttribPointer( a, stepsize, GL_FLOAT, GL_FALSE, 0, NULL );
163
+    unsigned int a = gl::GetAttribLocation( program, name.c_str() );
164
+    gl::EnableVertexAttribArray( a );
165
+    gl::BindBuffer( gl::ARRAY_BUFFER, buffer );
166
+    gl::VertexAttribPointer( a, stepsize, gl::FLOAT, false, 0, NULL );
167 167
     activeAttributes.push_back( a );
168 168
 }
169 169
 
170 170
 void slop::Shader::unbind() {
171 171
     for ( unsigned int i=0; i<activeAttributes.size(); i++ ) {
172
-        glDisableVertexAttribArray( activeAttributes[i] );
172
+        gl::DisableVertexAttribArray( activeAttributes[i] );
173 173
     }
174 174
     activeAttributes.clear();
175
-    glUseProgram( 0 );
175
+    gl::UseProgram( 0 );
176 176
 }

+ 1
- 1
src/shader.hpp Bestand weergeven

@@ -26,7 +26,7 @@
26 26
 #include <string>
27 27
 #include <exception>
28 28
 
29
-#include "gl_core_3_0.h"
29
+#include "gl_core_3_0.hpp"
30 30
 #include <glm/glm.hpp>
31 31
 #include <glm/gtc/type_ptr.hpp>
32 32
 #include <EGL/egl.h>

+ 21
- 21
src/slop.cpp Bestand weergeven

@@ -217,8 +217,8 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
217 217
         // Then we draw our junk to a framebuffer.
218 218
         window->framebuffer->setShader( textured );
219 219
         window->framebuffer->bind();
220
-        glClearColor (0.0, 0.0, 0.0, 0.0);
221
-        glClear (GL_COLOR_BUFFER_BIT);
220
+        gl::ClearColor (0.0, 0.0, 0.0, 0.0);
221
+        gl::Clear (gl::COLOR_BUFFER_BIT);
222 222
         memory->draw( window->camera );
223 223
         window->framebuffer->unbind();
224 224
 
@@ -226,32 +226,32 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
226 226
         
227 227
         int i;
228 228
         // We have our clean buffer, now to slather it with some juicy shader chains.
229
-        glEnable( GL_BLEND );
230
-        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
229
+        gl::Enable( gl::BLEND );
230
+        gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
231 231
         for (i=0;i<=(int)shaders.size()-2;i+=2) {
232 232
             pingpong->bind();
233
-            glClearColor (0.0, 0.0, 0.0, 0.0);
234
-            glClear (GL_COLOR_BUFFER_BIT);
233
+            gl::ClearColor (0.0, 0.0, 0.0, 0.0);
234
+            gl::Clear (gl::COLOR_BUFFER_BIT);
235 235
             window->framebuffer->setShader( shaders[i] );
236 236
             window->framebuffer->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
237 237
             pingpong->unbind();
238 238
 
239 239
             window->framebuffer->bind();
240
-            glClearColor (0.0, 0.0, 0.0, 0.0);
241
-            glClear (GL_COLOR_BUFFER_BIT);
240
+            gl::ClearColor (0.0, 0.0, 0.0, 0.0);
241
+            gl::Clear (gl::COLOR_BUFFER_BIT);
242 242
             pingpong->setShader( shaders[i+1] );
243 243
             pingpong->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
244 244
             window->framebuffer->unbind();
245 245
         }
246 246
         for (;i<shaders.size();i++) {
247 247
             pingpong->bind();
248
-            glClearColor (0.0, 0.0, 0.0, 0.0);
249
-            glClear (GL_COLOR_BUFFER_BIT);
248
+            gl::ClearColor (0.0, 0.0, 0.0, 0.0);
249
+            gl::Clear (gl::COLOR_BUFFER_BIT);
250 250
             window->framebuffer->setShader( shaders[i] );
251 251
             window->framebuffer->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
252 252
             pingpong->unbind();
253 253
         }
254
-        glDisable( GL_BLEND );
254
+        gl::Disable( gl::BLEND );
255 255
         if ( i%2 != 0 ) {
256 256
             window->framebuffer->draw(slop::mouse->getMousePos(), elapsed.count()/1000.f, glm::vec4( options->r, options->g, options->b, options->a ) );
257 257
         } else {
@@ -261,15 +261,15 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
261 261
         window->display();
262 262
         // Here we sleep just to prevent our CPU usage from going to 100%.
263 263
         std::this_thread::sleep_for(std::chrono::milliseconds(10));
264
-        GLenum err = glGetError();
265
-        if ( err != GL_NO_ERROR ) {
264
+        GLenum err = gl::GetError();
265
+        if ( err != gl::NO_ERROR_ ) {
266 266
             std::string error;
267 267
             switch(err) {
268
-                case GL_INVALID_OPERATION: error="INVALID_OPERATION"; break;
269
-                case GL_INVALID_ENUM: error="INVALID_ENUM"; break;
270
-                case GL_INVALID_VALUE: error="INVALID_VALUE"; break;
271
-                case GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break;
272
-                case GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break;
268
+		case gl::INVALID_OPERATION: error="INVALID_OPERATION"; break;
269
+		case gl::INVALID_ENUM: error="INVALID_ENUM"; break;
270
+		case gl::INVALID_VALUE: error="INVALID_VALUE"; break;
271
+		case gl::OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break;
272
+		case gl::INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break;
273 273
             }
274 274
             throw new std::runtime_error( "OpenGL threw an error: " + error );
275 275
         }
@@ -288,10 +288,10 @@ slop::SlopSelection slop::GLSlopSelect( slop::SlopOptions* options, bool* cancel
288 288
 
289 289
     // Lets now clear both front and back buffers before closing.
290 290
     // hopefully it'll be completely transparent while closing!
291
-    glClearColor (0.0, 0.0, 0.0, 0.0);
292
-    glClear (GL_COLOR_BUFFER_BIT);
291
+    gl::ClearColor (0.0, 0.0, 0.0, 0.0);
292
+    gl::Clear (gl::COLOR_BUFFER_BIT);
293 293
     window->display();
294
-    glClear (GL_COLOR_BUFFER_BIT);
294
+    gl::Clear (gl::COLOR_BUFFER_BIT);
295 295
     window->display();
296 296
     // Then we clean up.
297 297
     for( int i=0;i<shaders.size();i++ ) {

+ 7
- 6
src/window.cpp Bestand weergeven

@@ -101,13 +101,14 @@ slop::SlopWindow::SlopWindow() {
101 101
     }
102 102
     setCurrent();
103 103
     // Finally we grab some OpenGL 3.3 stuffs.
104
-    if(ogl_LoadFunctions() == ogl_LOAD_FAILED)
104
+    gl::exts::LoadTest didLoad = gl::sys::LoadFunctions();
105
+    if(!didLoad)
105 106
     {
106 107
         throw new std::runtime_error("Failed to load function pointers for OpenGL.");
107 108
     }
108 109
     framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
109 110
 
110
-    glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
111
+    gl::Viewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
111 112
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
112 113
 
113 114
     // Last, we actually display the window <:o)
@@ -117,11 +118,11 @@ slop::SlopWindow::SlopWindow() {
117 118
 slop::SlopWindow::~SlopWindow() {
118 119
     delete framebuffer;
119 120
     // Try to erase the window before destroying it.
120
-    glClearColor( 0, 0, 0, 0 );
121
-    glClear( GL_COLOR_BUFFER_BIT );
121
+    gl::ClearColor( 0, 0, 0, 0 );
122
+    gl::Clear( gl::COLOR_BUFFER_BIT );
122 123
     display();
123
-    glClearColor( 0, 0, 0, 0 );
124
-    glClear( GL_COLOR_BUFFER_BIT );
124
+    gl::ClearColor( 0, 0, 0, 0 );
125
+    gl::Clear( gl::COLOR_BUFFER_BIT );
125 126
     display();
126 127
     glXDestroyContext( x11->display, context );
127 128
     XUnmapWindow( x11->display, window );

+ 1
- 1
src/window.hpp Bestand weergeven

@@ -25,7 +25,7 @@
25 25
 #include <exception>
26 26
 
27 27
 #include <iostream>
28
-#include "gl_core_3_0.h"
28
+#include "gl_core_3_0.hpp"
29 29
 #include <GL/gl.h>
30 30
 #define GL_GLEXT_PROTOTYPES
31 31
 #define GLX_GLXEXT_PROTOTYPES