View Full Version : Basic Question
11-13-2010, 08:57 AM
Currently I am reading the book 'OpenGL Shading Language [Third Edition]'. My Problem is that I don't know how I can obtain the Vertex data within a Vertex Shader. In the book it says that I have to declare a 'in' variable for example:
// Vertex Shader
in vec4 vertex
How does OpenGL know that I want the Vertex position in my variable 'vertex'.
There's something about Generic Vertex Attributes.
I should bind 'vertex' to an index but what's about the index???
Can anyone help me please?
11-13-2010, 10:27 AM
Search down to glBindAttribLocation and then skip up a paragraph or two. And for examples, search for the same symbol in one or both of these for examples:
Another option is to specify the indices in the shader source, ala:
layout ( location = 0 ) in vec3 my_Vertex;
layout ( location = 2 ) in vec3 my_Normal;
though I think this requires GLSL 3.3 (GL 3.3) or newer.
Another option is to let the GLSL linker determine the indices, you query what it decided to use, and bind attributes to those indices. Often avoided because you end up switching which indices are which attributes between different shaders.
11-13-2010, 02:30 PM
This question confirms my claim that the Orange Book is REALLY GREAT (this is not a sarcasm), but it is simply not for the beginners.
The answer to your question can be found in the Orange Book, but in chapter 7 (or more precisely in section 7.7, pg. 217-226.)
For the first time, I suggest you to use the oldest, and for the beginners the most obvious way - to let linker choose where to put attributes (in fact, how to order them) and then query their addresses (IDs) with glGetAttribLocation(). Assigning IDs to generic vertex attributes in the program(glBindAttribLocation), or inside the shaders (layout location) would be useful later, when the significant number of shaders should be incorporated into application.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.