git.haldean.org ana / 646650a
don't need these any more Haldean Brown 1 year, 9 months ago
3 changed file(s) with 1 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
1414 src/node.cpp
1515 src/shaders.cpp
1616 src/ui.cpp
17 lib/wbogl/shader_utils.cpp)
17 )
1818
1919 target_link_libraries(ana glm SDL2 GLEW GL)
+0
-55
lib/wbogl/shader_utils.cpp less more
0 /**
1 * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/OpenGL_Programming
2 * This file is in the public domain.
3 * Contributors: Sylvain Beucler
4 */
5
6 #include <iostream>
7 using namespace std;
8
9 #include <SDL2/SDL.h>
10 #include <GL/glew.h>
11
12 /**
13 * Display compilation errors from the OpenGL shader compiler
14 */
15 void print_log(GLuint object) {
16 GLint log_length = 0;
17 if (glIsShader(object)) {
18 glGetShaderiv(object, GL_INFO_LOG_LENGTH, &log_length);
19 } else if (glIsProgram(object)) {
20 glGetProgramiv(object, GL_INFO_LOG_LENGTH, &log_length);
21 } else {
22 SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR,
23 "printlog: Not a shader or a program");
24 return;
25 }
26
27 char* log = (char*)malloc(log_length);
28
29 if (glIsShader(object))
30 glGetShaderInfoLog(object, log_length, NULL, log);
31 else if (glIsProgram(object))
32 glGetProgramInfoLog(object, log_length, NULL, log);
33
34 SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "%s\n", log);
35 free(log);
36 }
37
38 GLuint create_shader_from_string(const std::string &src, GLenum type) {
39 GLuint res = glCreateShader(type);
40 const GLchar *csrc = src.c_str();
41 GLint len = src.length();
42 glShaderSource(res, 1, &csrc, &len);
43 glCompileShader(res);
44
45 GLint compile_ok = GL_FALSE;
46 glGetShaderiv(res, GL_COMPILE_STATUS, &compile_ok);
47 if (compile_ok == GL_FALSE) {
48 SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "error loading shader:");
49 print_log(res);
50 glDeleteShader(res);
51 return 0;
52 }
53 return res;
54 }
+0
-18
lib/wbogl/shader_utils.hpp less more
0 /**
1 * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/OpenGL_Programming
2 * This file is in the public domain.
3 * Contributors: Sylvain Beucler
4 */
5 #pragma once
6 #include <GL/glew.h>
7 #include <string>
8
9 extern char* file_read(const char* filename, int* size);
10 extern void print_log(GLuint object);
11 extern GLuint create_shader(const char* filename, GLenum type);
12 extern GLuint create_shader_from_string(const std::string &src, GLenum type);
13 extern GLuint create_program(const char* vertexfile, const char *fragmentfile);
14 extern GLuint create_gs_program(const char* vertexfile, const char *geometryfile, const char *fragmentfile, GLint input, GLint output, GLint vertices);
15 extern GLint get_attrib(GLuint program, const char *name);
16 extern GLint get_uniform(GLuint program, const char *name);
17 extern void print_opengl_info();