OpenGL VRML W3D            
  Home Tutorials Books Applications Tools Docs Models Textures  

 

              Bugs

GLSL Tutorial   

  GLSL Tutorial

Index
Introduction

The Graphics Pipeline
Pipeline Overview
Vertex Processor
Fragment Processor

OpenGL Setup for GLSL
Overview
Creating a Shader
Creating a Program
Source Code
Trouble Shooting: the InfoLog
Cleaning Up

Comm. OpenGL=> GLSL
Comm. Introduction
Uniform Variables
Attribute Variables

Shader Basics
Data Types and Variables
Statments and Functions
Varying Variables

Shader Examples
Shader Examples List

GLSL Hello World

Color Shader

Flatten Shader

Toon Shader
Toon Shader - Version I
Toon Shader - Version II
Toon Shader - Version III

Lighting
OpenGL Directional Light I
OpenGL Directional Light II
Directional Light per Pixel
Point Light Per Pixel
Spot Light Per Pixel

Simple Texture
Combine Texture + Fragment
Multitexturing

Notes
The gl_NormalMatrix
Normalization Issues


Google

OpenGLTutorials @ Lighthouse3d.com

Led Shader
View Frustum Culling
GLSL Tutorial
Maths Tutorial
Billboarding Tutorial
Picking Tutorial
Terrain Tutorial
Display Lists Tutorial
GLUT Tutorial



   
[Previous: Overview] [Next: Creating a Program]

GLSL Tutorial


OpenGL Setup for GLSL - Creating a Shader


The following figure shows the necessary steps to create a shader.


The first step is creating an object which will act as a shader container. The function available for this purpose returns a handle for the container.

The OpenGL 2.0 syntax for this function is as follows:


GLuint glCreateShader(GLenum shaderType);

Parameter:

shaderType - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.

The ARB extensions syntax for this function is as follows:


GLhandleARB glCreateShaderObjectARB(GLenum shaderType);

Parameter:

shaderType - GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB.

You can create as many shaders as you want to add to a program, but remember that there can only be a main function for the set of vertex shaders and one main function for the set of fragment shaders in each single program.

The following step is to add some source code. The source code for a shader is a string array, although you can use a pointer to a single string.

The syntax of the function to set the source code, in OpenGL 2.0 syntax, for a shader is:


void glShaderSource(GLuint shader, int numOfStrings, const char **strings, int *lenOfStrings);

Parameters:

shader - the handler to the shader.
numOfStrings - the number of strings in the array.
strings - the array of strings.
lenOfStrings - an array with the length of each string, or NULL, meaning that the strings are NULL terminated.

And using the ARB extensions:


void glShaderSourceARB(GLhandleARB shader, int numOfStrings, const char **strings, int *lenOfStrings);

Parameters:

shader - the handler to the shader.
numOfStrings - the number of strings in the array.
strings - the array of strings.
lenOfStrings - an array with the length of each string, or NULL, meaning that the strings are NULL terminated.

Finally, the shader must be compiled. The function to achieve this using OpenGL 2.0 is:


void glCompileShader(GLuint shader);

Parameters:

shader - the handler to the shader.

And using the ARB extensions:


void glCompileShaderARB(GLhandleARB shader);

Parameters:

shader - the handler to the shader.

[Previous: Overview] [Next: Creating a Program]

       


Site designed and maintained by António Ramires Fernandes
Your comments, suggestions and references to further material are welcome!

Lighthouse 3D privacy statement