From Ohm

OpenGL GLSL Shader Example

To compile a GLSL shader we use the glVertex frame work.

In this frame work the two vertex and fragment shaders are concatenated with the “---“ separating token. So the compiliation of the previous example GLSL shader is achieved as follows:

#include <glvertex.h>

const char shader[] =
 "#version 120\n"
 "attribute vec4 vertex_position;\n"
 "attribute vec4 vertex_color;\n"
 "uniform mat4 mvp;\n"
 "varying vec4 frag_color;\n"
 "void main()\n"
 "{\n"
 "   frag_color = vertex_color;\n"
 "   gl_Position = mvp * vertex_position;\n"
 "}\n"
 "---\n"
 "#version 120\n"
 "varying vec4 frag_color;\n"
 "void main()\n"
 "{\n"
 "   gl_FragColor = frag_color;\n"
 "}\n";

GLuint id = lglCompileGLSLProgram(shader);
lglUseProgram(id);

Note: due to changes of the OpenGL 3.2 standard over OpenGL 2.1, the input registers gl_Vertex, gl_Color etc. are replaced by attribute vectors within the glVertex frame work. The following uniforms and attributes are available:

To try the above GLSL example, open the GLSL shader editor of the frame work:

./myqtapp --glsleditor

Retrieved from http://schorsch.efi.fh-nuernberg.de/roettger/index.php/MedicalVisualization/OpenGLGLSLShaderExample

Page last modified on November 28, 2016, at 10:41 AM