From Ohm

OpenGL GLSL Shader Documentation

The GLSL shader language definition is available online at

The glVertex frame work provides easy access to GLSL as follows:

To compile a GLSL shader:

GLuint id = lglCompileGLSLProgram("#version 120\n ...");

To load a GLSL shader from a file:

GLuint id = lglLoadGLSLProgram(filename);

The simplest shader possible is:

#version 120
attribute vec4 vertex_position;
uniform mat4 mvp;
void main()
   gl_Position = mvp * vertex_position;
#version 120
uniform vec4 color;
void main()
   gl_FragColor = color;

To use a GLSL shader:


Given a uniform float “v” in the GLSL shader, we pass a value to the variable in shader as follows:

lglUniformf("v", ...);

Given a uniform vec4 “v” in the GLSL shader, we pass a vector value to the variable in the shader as follows:

lglUniformfv("v", vec4(...));

Texture objects can be created with the lglCreateTexmap functions of the frame work:

GLuint texid2D = lglCreateTexmap2D(width, height, type, data);
GLuint texid3D = lglCreateTexmap3D(width, height, depth, type, data);

Then the texture objects can be enabled (meaning that texture color is modulating vertex colors):


The returned texture object ids can be passed to GLSL by means of a so called uniform sampler:

lglSampler2D("tex2D", texid2D);
lglSampler3D("tex3D", texid3D);

Then the texture objects can be accessed with the sampler “tex2D” resp. “tex3D” in the GLSL fragment shader:

uniform sampler2D tex2D;
vec4 texcol = texture2D(tex2D, texcoords);

More details and examples are available in the glVertex documentation [1].



Retrieved from

Page last modified on December 19, 2017, at 12:18 PM