Polytonic / Glitter

Dead Simple OpenGL
http://polytonic.github.io/Glitter/
2.46k stars 416 forks source link

Sample shader improvements #84

Open dante1130 opened 5 months ago

dante1130 commented 5 months ago

Problem

Example shader class interface is error-prone

The example code for the shader class is very error-prone to use for users. This is from experience from some of my mates using this as a template for their project. This is because the public interface of the shader class has methods that are meant to be used in private implementations.

E.g. Someone with some knowledge of setting up OpenGL shaders, will know they have to first create the shader before attaching them. As such, they will call the method in this order:

Shader shader;
shader.create("vert.glsl");
shader.attach("vert.glsl");
...

However, the correct use of this is to actually just use the attach method.

The example for the shader class in the README omitted the step to link the shaders

There is a step missing from the example code given for the sample shader class, which is that the user has to call link to link the shaders to the shader program.

Someone, knowing no better, will be confused and trust the example code instead, while trying to fix seemingly non-existing bugs.

Solution

Testing