Talk:OpenGL Programming/Modern OpenGL Tutorial 03

= Attribute location =

77.236.6.134 wrote:
 * Note2: integers we use for storing locations of attribute or uniform variables, retrieved by glGet*Location are not some location pointers, they are just numbered in the same order as variables defined in shader code. So if you memorize your shader code and remember how many variables of what type you declared, you can easily guess "coord3d" will be attribute 0, "v_color" is attribute 1, "fade" is uniform 0, and so on. This way you don't need to call glGet*Location at all in our simple example.

I suspect this is dependent on the compiler, so not necessarily true on all cards/drivers. Do you have info (specs, external reference) stating that this is true for all cards/drivers? Beuc (discuss • contribs) 20:21, 28 May 2012 (UTC)

I found a couple errors in this one. 1 - When you put vertex and color data in a single buffer, you need to include a call to glBindBuffer;

glEnableVertexAttribArray(attribute_coord2d); glEnableVertexAttribArray(attribute_v_color); glBindBuffer(GL_ARRAY_BUFFER, vbo_triangle); glVertexAttribPointer( ...

because you have unbound GL_ARRAY_BUFFER in the initialization code. You should then unbind it after the display code as well;

glDisableVertexAttribArray(attribute_coord2d); glDisableVertexAttribArray(attribute_v_color); glBindBuffer(GL_ARRAY_BUFFER, 0);

2 - When you add the uniform, you need to define a global variable to hold its name;

GLint uniform_fade;

If someone needs to talk to me about this, I am JBB@JeromeBerryhill.com.
 * 1. I sync'd with the reference source code (see links at the bottom of our pages) - added the missing glBindBuffer, and removes glBindBuffer(..., 0) calls, they are not necessary at this point. Thanks for pointing this out!
 * 2. Well, it is declared, look for "GLint uniform_fade" in the page :)
 * Beuc (discuss • contribs) 16:58, 20 October 2012 (UTC)

Regarding the "alternative for sport", would struct/array packing come into play at some point?