add Program.get_uniform_location()

This commit is contained in:
Josh Holtrop 2015-06-11 20:16:39 -04:00
parent 5d1351fc66
commit 3d531ace23
4 changed files with 10 additions and 13 deletions

View File

@ -54,6 +54,11 @@ namespace glcxx
bind_attributes(args...);
}
GLint get_uniform_location(const char * uniform_name)
{
return glGetUniformLocation(m_id, uniform_name);
}
protected:
void allocate();

View File

@ -49,16 +49,4 @@ namespace glcxx
throw Error(message);
}
}
#if 0
for (;;)
{
const char *uniform_name = va_arg(va, const char *);
if (uniform_name == NULL)
break;
GLint loc = glGetUniformLocation(m_id, uniform_name);
m_uniform_locations.push_back(loc);
m_uniform_location_names[uniform_name] = loc;
}
#endif
}

View File

@ -1,4 +1,6 @@
uniform vec4 color;
void main(void)
{
gl_FragColor = vec4(0.5, 0.1, 0.9, 1.0);
gl_FragColor = color;
}

View File

@ -48,6 +48,8 @@ void display(SDL_Window * window)
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), NULL);
program->use();
GLint uniform_location = program->get_uniform_location("color");
glUniform4f(uniform_location, 1.0, 0.6, 0.2, 1.0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
SDL_GL_SwapWindow(window);
}