Neomex's picture

Shaders

What is the simpliest way to use shaders in OpenTK? Is it possibile to use only pixel shader?
What I want to do, is drawing lot of pixels on screen ( only in 2D ).


Comments

Comment viewing options

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

I havent even foind out how to draw many pixels with OGL in a performant way but it is possible to use only pixel shader. In there, yout have to write a pixel shader and compile it with at least an empty (so default) fragment shader. To get a shader working, you need to do following steps:

//Create Shader
GL.CreateShader(type);
//Set Source
GL.ShaderSource(shader,sourceLength, source, rowLengths[]);
//Compile Shader
GL.CompileShader(shader);
//Get Success or Errors
GL.GetShaderiv(shader, CompileStatus, status);

This you do with each of these programs

//FragmentShader
   void main(void)
   {
      //Do pixel stuff here
   }
 
//VertexShader
   void main(void)
   {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   }

And last step create the program

//Create Program
GL.CreateProgram();
//Attach Shader
GL.AttachShader(program,shader1);
GL.AttachShader(program,shader2);
//Activate Program
GL.LinkProgram(program);
GL.UseProgram(program);
//Done