Utilities | Arrays | Imaging | Shaders | POGL | GLUT | OpenGL | GLU |

OpenGL::Shader (OGS) objects provide an abstracted interface to ARB, Cg and GLSL shaders.

POGL 0.56 adds support for

  • GL_ARB_shader_objects
  • GL_ARB_vertex_shader
  • GL_ARB_fragment_shader
  • GL_ARB_shading_language_100
  • GL_EXT_Cg_shader

...in addition to its existing GL_ARB_vertex_program and GL_ARB_fragment_program extensions.

OpenGL::Shader provides an object class that abstracts these APIs - simplifying the loading and use of alternate shaders, based on platform support.

Google Bookmarks Google
  
Stumble Upon It! Stumbled on It!
  
del.icio.us del.icio.us
  


Sample Code



Enumerating Installed/Supported Shading Languages
Note: these APIs require a current GL context

my $shaders = OpenGL::Shader::GetTypes();

    Returns a hashref of available shader types. The hash keys are shading language names; hash values are their version.

my $ok = OpenGL::Image::HasType('Cg');

    Tests whether a particular shading language (and optionally minimum version) is supported.



Instantiate an explicit shader

my $shdr = new OpenGL::Shader('GLSL');

    Create an OGS object for GLSL.

Instantiate an available shader by priority

my $shdr = new OpenGL::Shader('GLSL','Cg','ARB');

Instantiate any available shader

my $shdr = new OpenGL::Shader();

    Defaults to 'GLSL','Cg','ARB' order.

Determine instantiated shader type and version

my $type = $shdr->GetType();
my $ver = $shdr->GetVersion();

Load shaders as strings

my $stat = $shdr->Load($fragment_prog,$vertex_prog);

Load shaders by files

my $stat = $shdr->LoadFiles($fragment_file,$vertex_file);

Enable shader

$shdr->Enable();

Get vertex attribute ID

my $attr_id = $self->MapAttr($attr_name);
glVertexAttrib4fARB($attr_id,$x,$y,$z,$w);

Get uniform variable ID

my $var_id = $self->Map($var_name);

Set float4 vector variable

$stat = $self->SetVector($var_name,$x,$y,$z,$w);

Set float4x4 matrix via OGA

$stat = $self->SetMatrix($var_name,$oga);

Disable shader

$shdr->Disable();