Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GLSL Essentials

You're reading from   GLSL Essentials If you're involved in graphics programming, you need to know about shaders, and this is the book to do it. A hands-on guide to the OpenGL Shading Language, it walks you through the absolute basics to advanced techniques.

Arrow left icon
Product type Paperback
Published in Dec 2013
Publisher Packt
ISBN-13 9781849698009
Length 116 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jacobo Rodriguez Jacobo Rodriguez
Author Profile Icon Jacobo Rodriguez
Jacobo Rodriguez
Arrow right icon
View More author details
Toc

Language basics


Before we begin, I expect you to have a basic understanding and proficiency of C. OpenGL is available in different programming languages such as Java, Python, or C#. However, I will be concentrating on the C/GLSL concepts.

Instructions

The instructions always end with a semicolon, and there could be more than one per line:

c = cross(a, b);
vec4 g; g = vec4(1, 0, 1, 1);

A block of instructions is created by putting them in brackets. All variables declared inside a block will be destroyed when the block finishes. If two variables have the same name—one declared outside the block (also called scope) and another declared inside the block—by default, the inner variable is the one which will be referenced:

float a = 1.0;
float b = 2.0;
{
  float a = 4.0;
  float c = a + 1.0; // c -> 4.0 + 1.0
}
b = b + c; // wrong statement. Variable c does not exist here

Tabulations or whitespaces don't change the semantics of the language. You can use them to format the code at your wish.

Basic types...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime