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: Fragment Processor] [Next: Creating a Shader]

GLSL Tutorial


OpenGL Setup for GLSL - Overview


This section, OpenGL Setup for GLSL, assumes you've got a pair of shaders, a vertex shader and a fragment shader, and you want to use them in an OpenGL application. If you're not ready yet to write your own shaders there are plenty of places to get shaders from the internet. Try the site from the Orange Book. The tools for shader development, namely Shader Designer or Render Monkey, all have a lot of shader examples.

As far as OpenGL goes, setting your application is similar to the workflow of writing a C program. Each shader is like a C module, and it must be compiled separately, as in C. The set of compiled shaders, is then linked into a program, exactly as in C.

Both the ARB extensions and OpenGL2.0 are being used in here. If you are new to extensions or using OpenGL above version 1.1 (as supported by Microsoft) I suggest you take a look at GLEW. GLEW simplifies the usage of extensions and newer versions of OpenGL to a great deal since the new functions can be used right away.

If relying on extensions, because you have no support for OpenGL 2.0 yet, then two extensions are required:

GL_ARB_fragment_shader
GL_ARB_vertex_shader
A small example of a GLUT program using GLEW to check the extensions could be as shown below:
	#include <GL/glew.h>
	#include <GL/glut.h>
	
	void main(int argc, char **argv) {
	
		glutInit(&argc, argv);
		
		...
		
		glewInit();
		if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)
			printf("Ready for GLSL\n");
		else {
			printf("Not totally ready :( \n");
			exit(1);
		}
	
		setShaders();
	
		glutMainLoop();
	}

To check for OpenGL 2.0 availability you could try something like this


	#include <GL/glew.h>
	#include <GL/glut.h>
	
	void main(int argc, char **argv) {
	
		glutInit(&argc, argv);
		
		...
		
		glewInit();
		if (glewIsSupported("GL_VERSION_2_0"))
			printf("Ready for OpenGL 2.0\n");
		else {
			printf("OpenGL 2.0 not supported\n");
			exit(1);
		}
	
		setShaders();
	
		glutMainLoop();
	}

The figure bellow shows the necessary steps (in OpenGL 2.0 syntax) to create the shaders, the functions used will be detailed in latter sections.


In the next subsections the steps to create a program are detailed.

[Previous: Fragment Processor] [Next: Creating a Shader]

       


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

Lighthouse 3D privacy statement