File: Shader.pod

package info (click to toggle)
libopengl-perl 0.7004%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,088 kB
  • sloc: perl: 9,701; ansic: 8,090; makefile: 110
file content (76 lines) | stat: -rw-r--r-- 1,827 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
=head1 NAME

OpenGL::Shader - abstraction for managing OpenGL shaders

=head1 SYNOPSIS

  ##########
  # Load and manage a shader
  use OpenGL(':all');
  use OpenGL::Shader;
  # Note: these APIs/methods requires a current GL context/window
  glutInit();
  glutInitDisplayMode(GLUT_RGBA);
  glutInitWindowSize($w,$h);
  my $Window_ID = glutCreateWindow( "OpenGL::Shader test" );

=head1 DESCRIPTION

This module provides an extensible abstraction for managing OpenGL shaders.
As of 1.02 it is included with the L<OpenGL> distribution.

Example usage:

  # Get a hashref of shader types
  my $shaders = $OpenGL::Shader::GetTypes();

  # Test for shader support
  my $ok = OpenGL::Shader::HasType('Cg');

  # Instantiate a shader - list acceptable shaders by priority
  my $shdr = new OpenGL::Shader('GLSL','ARB');

  # Get shader type and version
  my $type = $shdr->GetType();
  my $ver = $shdr->GetVersion();

  # Load shader by strings
  my $stat = $shdr->Load($fragment,$vertex);

  # Load shader by file
  my $stat = $shdr->LoadFiles($fragment_file,$vertex_file);

  # Enable
  $shdr->Enable();

  # Get vertex attribute ID
  # returns undef if not supported or not found
  my $attr_id = $self->MapAttr($attr_name);
  glVertexAttrib4fARB($attr_id,$x,$y,$z,$w);

  # Get Global Variable ID (uniform/local)
  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);

  # Do GL rendering

  # Disable
  $shdr->Disable();

  # Done
  glutDestroyWindow($Window_ID);

=head1 AUTHOR

Bob "grafman" Free - grafman@graphcomp.com.
Copyright 2007 Graphcomp - ALL RIGHTS RESERVED.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut