Boder's picture

GLSL Example

Thanks for this example. 2 things.

Here, I don't believe you need all the if() conditionals

public override void OnUnload(EventArgs e)
            if (shader_program != 0)
            if (fragment_shader_object != 0)
            if (vertex_shader_object != 0)
            if (vertex_buffer_object != 0)
                GL.DeleteBuffers(1, ref vertex_buffer_object);
            if (element_buffer_object != 0)
                GL.DeleteBuffers(1, ref element_buffer_object);

And can I use a fragment program without writing a vertex program?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Inertia's picture

I believe these have been added in the spirit that we discussed that the examples shipped with OpenTK should contain better error checking. Many C tutorials for OpenGL don't do proper checks, in order to keep the code as convenient as possible for the reader. This can lead to obscure bugs, because every GL driver handles errors differently.

You can replace only parts of the fixed-function pipeline, but I've read that Ati cards don't work well with that when passing uniforms. (Info might be outdated and fixed in recent drivers, it's been a while) The vertex shader is the easy bit if you do lighting in the fragment shader, my recommendation is replacing both pipeline stages with shaders if you decide to use GLSL.

the Fiddler's picture

The ifs are important actually: if the load event is interrupted by an exception, some objects will be 0. If you try to delete those, the program will crash with an AccessViolation (depends on the drivers) - so, yes, the checks are necessary. :)

teichgraf's picture


Can I use pixel shaders without vertex shaders, and vice versa?

Most definitely. It's entirely up to you. If you don't use a shader, the fixed-function processing will be used instead for that part for the pipeline. In addition, you can express your shaders either in a higher-level language or with assembly code.