Creating Shaders with GLSL

The Starting Point

A shader program, just like a “C” program, starts execution in main(). Every GLSL shader program begins life as follows:

#version 330 corevoid main(){    // Your code goes here}

The // construct is a comment and terminates at the end of the current line, just like in “C”. Additionally, “C”-type, multiline comments—the /* and */ type—are also supported. However, unlike ANSI “C”, main() does not return an integer value; it is declared void. Also, as with “C” and its derivative languages, statements are terminated with a semicolon. While this is a perfectly legal GLSL program that compiles and even runs, its functionality leaves something to be desired. To add a little more excitement to our shaders, ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.