Skip to content

Minor tutorial issues (opentk.net/learn) #99

@MV10

Description

@MV10

I am using VS2022, OpenTK 4, and .NET 6. Here are a few notes on minor issues I've found in the tutorials (opentk.net/learn). If I have time later on, I'll PR the fixes myself, but I thought I'd note them in an Issue as I run through the tutorial myself. (I know shader programming, but new to OpenTK, and also my wife wants to learn this stuff, so I thought I'd preview the material.)

In Shaders it is necessary to mark the shader.vert and shader.frag files as content to copy to the output directory, otherwise the File.ReadAllText calls in the Shader class constructor will fail. This is done by altering the Copy to Output Directory file property to Copy always:

image

In Compiling the Shaders, you can't use out int success twice within the same method; I used out int vertOk and out int fragOk (and similarly, later on, out int linkOk):

GL.GetShader(VertexShader, ShaderParameter.CompileStatus, out int success);
// snip
GL.GetShader(FragmentShader, ShaderParameter.CompileStatus, out int success);

In Linking Vertex Attributes it may be useful to note that the reader shouldn't add any of the code to their program. How to add that to the program is covered in the following Vertex Array Object section.

In Element Buffer Objects the reader is told, "in OnLoad, below where you initialize the VertexBufferObject, we initialize the ElementBufferObject" however, per the highlighted note which follows (element array buffer can only be bound if there is a VAO bound), that code should actually be added after the VertexArrayObject initialization, not the VertexBufferObject. If the code is written as instructed, the program throws a System.AccessViolation exception.

In Uniforms, the _shader field name is inconsistent with earlier sections; it should be shader without the leading underscore. Additionally earlier sections defined the Handle field in the Shader class as int Handle; which defaults to private scoping; it needs to be explicitly declared as public. Finally, it may be helpful to explicitly instruct the reader to add a new class-level field as Stopwatch timer = new(); and it is then necessary to call timer.Start(); in the constructor, otherwise the elapsed time is always zero and the color will not change.

If I notice anything else when I have time to get back to this, I'll add more posts.

Overall, very clear though!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions