dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
755 stars 299 forks source link

Odd issue with shader attribute binding #98

Open govind-mukundan opened 9 years ago

govind-mukundan commented 9 years ago

Hi,

I'm a beginner with OpenGL so please forgive me if this "issue" is something wrong with my implementation/understanding. I'm building a very simple graph plotter using SharpGL and "modern OpenGL", and I found that the same project was giving two different outputs on two different computers. After some debugging I traced it down to the fact that two of my shader attributes were being assigned to different numbers on the two computers. So if I didn't use shaderProgram.BindAttributeLocation() and just read back the ID from the shader, things were working fine. i.e.

/* Not Working Code */
attribute_vpos = 0;
attribute_vcol = 1;
...
shaderProgram.BindAttributeLocation(gl, attribute_vpos, "vPosition");
shaderProgram.BindAttributeLocation(gl, attribute_vcol, "vColor");
 // Gives expected figure on one PC not on the other
// Replacing the above 2 lines with this works:
attribute_vpos = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vPosition");
attribute_vcol = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vColor");

Checking the attribute IDs on the not-working PC, attribute_vpos was 0 but attribute_vcol was not 1, but some other random (big) integer. So I presume somehow the binding to the shaderProgram.BindAttributeLocation(gl, attribute_vcol, "vColor") was not able to bind the vColor attribute to integer 1.

I'm using SharpGL v2.3.0.1

Govind