What is the GLP library ?
Current version is 0.1 and must be used with OpenGL version 1.1
or greater.
Only true rgb mode is supported.
How use the GLP library ?
Examples & tricks
glDepthTest(GL_LESS);
// set projection, modelview matrix...
glEnable(GL_DEPTH_TEST);
glPolygonOffsetEXT(1.0,0.0001);
glEnable(GL_POLYGON_OFFSET_EXT);
glpDrawNoise(scene);
glpFinalize();
// show framebuffer
// define a Display list called scene like in the previous example
float marble[6][5] = {
{0.00, 0.0,0.0,0.0,1.0},
{0.05, 0.8,0.2,0.2,1.0},
{0.50, 1.0,0.5,0.5,1.0},
{0.60, 1.0,1.0,1.0,1.0},
{0.95, 0.6,0.0,0.0,1.0},
{1.00, 0.0,0.0,0.0,1.0}};
glpSetColormap(256,4,GLP_NORM,6,(float*)marble);
glpSetParameteri(GLP_COMPONENT,GLP_MODE_L);
glpSetParameterf(GLP_NOISE_AMP,0.25);
glpSetParameterf(GLP_FUN_AMP,0.75);
// set projection, modelview matrix...
// draw the noise at 0.25 scale :
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.2,0.2,0.2);
glEnable(GL_DEPTH_TEST);
glPolygonOffsetEXT(1.0,0.0001);
glEnable(GL_POLYGON_OFFSET_EXT);
glpDrawNoise(scene);
// blend gradient function
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.2,0.2,0.2);
glTranslatef(0.5,0.5,0.5);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
glpDrawPattern(scene,GLP_FUNC_GRADIENT);
// do colormap & finish :
glDisable(GL_BLEND);
glpDoColormap();
glpFinalize();
// shows the framebuffer
In the marble example, we used a colormap which maped black to black, so the black background was not affected by glpDoColormap. This time, the background will not be mapped to black and we use stencil buffer to restrict color mapping to the pixel of the scene leaving the background unaffected.
First, initialization :
// define a Display list called scene like in the previous example
float wood[][4] = {
{0.000, 1.00, 1.00, 1.00 },
{0.120, 0.70, 0.41, 0.11 },
{0.231, 0.70, 0.46, 0.11 },
{0.496, 1.00, 1.00, 1.00 },
{0.701, 1.00, 1.00, 1.00 },
{0.829, 0.70, 0.46, 0.11 },
{1.000, 1.00, 1.00, 1.00 }
};
glpSetColormap(256,4,GLP_NORM,7,(float*)wood);
glpSetParameteri(GLP_COMPONENT,GLP_MODE_RGB);
glpSetParameterf(GLP_NOISE_AMP,0.25);
glpSetParameterf(GLP_FUN_AMP,0.75);
glpSetParameterf(GLP_FUN_MODE,GLP_TRIANGULAR);
// set projection, modelview matrix...
// Set to 1 in the stencil buffer pixels drawn
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
// draw the noise
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.25,0.25,0.25);
glEnable(GL_DEPTH_TEST);
glPolygonOffsetEXT(1.0,0.0001);
glEnable(GL_POLYGON_OFFSET_EXT);
glpDrawNoise(scene);
// blend gradient function
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.3,0.3,0.3);
glTranslatef(0.5,0.5,0.5);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
glpDrawPattern(scene,GLP_FUNC_CYLINDER);
// do colormap & finish :
glStencilFunc(GL_EQUAL,1,0xffffffff);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glDisable(GL_BLEND);
glpDoColormap();
glpFinalize();
// shows the framebuffer
Light position can be added in the initalisation :
GLfloat light_pos[4] = { 1.0, 1.0, 1.0, 0.0};
GLfloat light_color[4] = { 0.6, 0.8, 1.0, 1.0};
GLfloat ambiant_color[4] = { 1.0, 1.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0,GL_POSITION,light_pos);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_color);
glLightfv(GL_LIGHT0,GL_SPECULAR,light_color);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambiant_color);
glEnable(GL_LIGHT0)
// don't forget the glpFinalize before the lighting pass
GLfloat white[] = {1.0, 1.0, 1.0, 1.0};
GLfloat black[] = {0.0, 0.0, 0.0, 1.0};
// diffuse lighting :
glEnable(GL_LIGHTING);
glBlendFunc(GL_DST_COLOR,GL_ZERO);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_DIFFUSE, white);
glMaterialfv(GL_FRONT, GL_SPECULAR, black);
glCallList(scene);
// specular lighting
glBlendFunc(GL_ONE,GL_ONE);
glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
glMaterialfv(GL_FRONT, GL_SPECULAR, white);
glCallList(scene);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glShadeModel(GL_FLAT);
// show the framebuffer
GLP Errors
GLP Rendering functions
void glpDrawNoise(GLuint list)
list must not provide any color, lighting, material or texturing
information.
Texturing is supposed disabled, polygon offset values s supposed to
be correctly set.
Texturing, texture environement function, texture coordinate generation
and blending state are changed.
Texturing, blending, texture coordinate generation, z-buffer writing
and polygon offset are disabled ... but only if octave>=1 (octave=0 means
nothing at all is done, so OpenGL state is not changed).
Pixel transfert scale and bias are changed but restored before return.
see also
Any color look-up table mechanism enabled ( GL_MAP_COLOR in pixel transfer parameter or GL_xxx_COLOR_TABLE_SGI extensions) is disabled before returning; depth test is disabled.
warning
Different available pattern functions are :
SGI_color_matrix extension is needed for GLP_FUNC_CYLINDER and GLP_FUNC_SPHERE, otherwise a GLP_NOT_SUPPORTED error will be raised.
GLP_FUN_MODE and GLP_FUN_SIZE parameters control how x,y,z are computed first in order to fit into [0,1].
scene must not provide any color, material or texturing information.Texturing
is supposed disabled; color mask is supposed to be all GL_TRUE,
polygon offset values are supposed to be correctly set.
Texturing, texture coordinate generation, blending, z-buffer state
and color matrix and changed.
Texturing, texture coordinate generation, blending, color matrix, depth
test, z-buffer writing and polygon offset are disabled; color mask is reset
to all GL_TRUE.
see also
GLP state functions
see also
see also
SGI_color_table extension may be needed. If it is needed and not present, this with result in a GLP_NOT_SUPPORTED error.
warning
see also
see also
GLP miscenaleous functions
see also
GLP parameters
Noise parameters
If EXT_texture3D extension is not supported by OpenGL, setting
GLP_DIMENSION to GLP_MODE_3D will result in a GLP_NOT_SUPPORTED
error.
Turbulence is a sum of pseudo-periodic noise function at different frequencies
and amplitude.
Frequencies of successive layer are multiplicated by this value.
The pseudo-periodic noise function values are in [0,GLP_NOISE_AMP]
, with GLP_NOISE_AMP<=1.
Turbulence is a sum of this pseudo-periodic function, so it's amplitude
is given by
GLP_NOISE_AMP*(1+1/GLP_AMP_DIV+1/(GLP_AMP_DIV^2)+...+1/(GLP_AMP_DIV^GLP_OCTAVE)).
Turbulence is a sum of pseudo-periodic noise function at different frequencies
and amplitude.
Amplitude of successive layer are divided by this value as frequency
is multiplied by GLP_FREQ_MULT.
Because the noise function has values in [0,GLP_NOISE_AMP],
you must set GLP_NOISE_AMP in order to have GLP_NOISE_AMP*(1+1/GLP_AMP_DIV+1/(GLP_AMP_DIV^2)+...+1/(GLP_AMP_DIV^GLP_OCTAVE))<1,
ortherwise the turbulence function will be clamped to [0,1].
Turbulence is a sum of pseudo-periodic function at different frequencies
and amplitude.
Octave is the number of noisy layers used to compute turbulence.
A vgalue of 1 means no turbulence, just a noise at the pseudo-frequency
1. A value of 0 results in nothing drown at all.
After noise function are summed, a chi function is applied.
It maps [0,GLP_NOISE_BEGIN] to 0, [GLP_NOISE_BEGIN,GLP_NOISE_END]
to [0,1] and [GLP_NOISE_END,1] to 1.
GLP_NOISE_BEGIN<GLP_NOISE_END is invalid.
After noise function are summed, a chi function is applied.
It maps [0,GLP_NOISE_BEGIN] to 0, [GLP_NOISE_BEGIN,GLP_NOISE_END]
to [0,1] and [GLP_NOISE_END,1] to 1.
GLP_NOISE_BEGIN<GLP_NOISE_END is invalid.
The pseudo periodic function used to draw noise is a completly random
3D texture magnified with OpenGL linear filtering.
This parameter controls the size of the random texture (16x16x16 by
default), it must be a power of 2.
Higher values may make the noise a little less periodic.
Patterns compute at each pixel of the framebuffer a function r,g,b of
it's coordinates x,y,z in the scene and then computes a pattern function
of these r,g,b.
This parameter controls how x,y,z coordinates are transformed into
three values in [0,GLP_FUN_AMP] before
the pattern function is applied.
![]() |
![]() |
|
|
|
|
Ths controls the amplitude of the function used to map x,y,z into r,g,b
before applying the pattern function.
It is usefull to have GLP_FUN_AMP<1.0 if the r,g,b calculated
from x,y,z have to be blent with a previous image (for example a noise
function) before the pattern function because all calculus are clamped
to [0,1].
x,y,z pixel coordinates of each pixel in the framebuffer is transformed
in r,g,b values in [0,GLP_FUN_AMP]
(before the pattern's function is applied) using texture mapping.
This parameters controls the size of the textures, ie the sampling
of the function mapping x,y,z to r,g,b.
Higher values gives better results but it is limited by the amount
of texture memory.