
Shaders with openTk.
Posted Sunday, 18 November, 2007 - 15:22 by Axelill inHello everyone,
I'dl like to create a shader using opentk but I have a small problem. My shader is in a c# Strinag and opentk accept only a string[] (like the c++ version but it easy to play with pointer in c++)
string _shader = "void main() { gl_Position = ftransform();}" GL.ShaderSource(m_shader_handle, 1, _shader, null);
this piece of code does not work. Do I need to split my string per lines? or there is something more efficient?
Axel.


Comments
try string[] _shader = new
try
string[] _shader = new string[] { {"void main() { gl_Position = ftransform();}"} };
this will give you a array of string with one element.
djk
The latest version (0.3.13)
The latest version (0.3.13) contains a new GL.ShaderSource overload that takes a single string:
It automatically takes care of unnecessary details, and there is no need for the string to be null terminated.
This overload also works well with shaders stored in files:
Yep, true and it works
Yep, true and it works perfectly.
Thanks. ;)
Re: Shaders with openTk.
Hello to all. I'm newbie in GL and OpenTk. What means m_shader_handle and where should I get this value? Little example if anybody can.. Please!
Re: Shaders with openTk.
Welcome.
To use a shader, you must first create it with
GL.CreateShader, i.e:Then, you have to:
GL.ShaderSource)GL.CompileShader)GL.CreateProgram)GL.AttachShader)GL.LinkProgram)GL.UseProgram)It's simpler than it sounds :)
If you wish to see this in action, check the source code of the first GLSL example (currently located at Source/Examples/Tutorial/T10_GLSL_Cube.cs).
Re: Shaders with openTk.
I tried to Create Shader but have runtime error:
"Unable to find an entry point named 'glCreateShader' in DLL 'opengl32.dll'"
I use videocard
nVIDIA GeForce4 Ti 4200 with AGP8X
I tried to check GL.SupportsExtension("VERSION_2_0") (same in example); And it returns false!
(In examples too, of course). Maybe my card does't support this extensions. But why I can't create shader..?
What's wrong?
Re: Shaders with openTk.
Geforce 4s don't support Shader v2, you'll need a newer graphics card.
Take a look at: http://en.wikipedia.org/wiki/Pixel_shader
You'll note you need at least a Geforce FX or Radeon X700 for shader 2.0.
Re: Shaders with openTk.
Your video card is too old and does not support GLSL shaders. GLSL is only supported by GeForce FX or Radeon 9500 and newer cards.
Your card does have programmable hardware which is exposed in the form of low-level ARB vertex and fragment programs. The syntax is closer to assembly (while GLSL is closer to C), but the language is quite simple.
Your other option is to download and build Mesa3d, which is a software implementation of OpenGL with GLSL support (this is what I use when developing OpenTK).
Edit: beaten. One note: R300 cards (Radeon 9500-9800) support GLSL just fine, no need for R400 (Radeon x600-x850)
Re: Shaders with openTk.
Ah, yes, my mistake.
I tend to stick to nvidia cards so didn't really follow the Radeon line closely and put the card that supported 2.0b down instead.
Re: Shaders with openTk.
Thanks a lot!
One more question. I tried to write some affine convertion with GLSL. For shader creation I used function CreateShader so far and it's call from example Source/Examples/Tutorial/T10_GLSL_Cube.cs
which I placed at the and of Form_Load event code (I'm using WinForms)
Me shaders:
fragment shader preobr.frag
vertex:
Where MatrixPreobr may be some conversion. But it don't give effect. (Me Surface leave in the same position with various matix). What's wrong?