Portal:OpenGL Shading Language/Core Language

From OpenGL Wiki
Revision as of 04:29, 25 July 2013 by Alfonse (talk | contribs) (Language intro.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The Core Language of GLSL is grammatically very similar to C, with some elements from C++. It contains the same looping and conditional keywords as C/C++. Variables are declared in a fashion very similarly to C/C++, though GLSL has many more qualifiers and built-in types than those languages.

One big difference is that GLSL shaders must start with a version declaration, which tells the compiler what version of the language to compile the rest. A shader that does not begin with a version declaration will be assumed to be the (very ancient) version 1.10.

Another large difference between C/C++ and GLSL is how functions work. The general syntax is similar, but the parameter passing conventions are quite different, allowing functions to have dedicated output parameters without pointers. A more difficult issue is that GLSL does not support recursion at all; a function must never call itself or call another function that calls itself.