aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/OpenGL/GLBackend/Shader (copier).cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-10-21 22:00:20 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-10-21 22:00:20 +0200
commit8099f1775b6d9083e04b2f39700c2e90a0724aca (patch)
treea145c7f1ec8aeb4aade2ffae4e2c50771ef9ec86 /src/OpenGL/GLBackend/Shader (copier).cs
parentf31ffd683210c50b777dce4e76d0d9912ca925a8 (diff)
glbackend tests, copy first try from hg reposglbackend
Diffstat (limited to 'src/OpenGL/GLBackend/Shader (copier).cs')
-rw-r--r--src/OpenGL/GLBackend/Shader (copier).cs135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/OpenGL/GLBackend/Shader (copier).cs b/src/OpenGL/GLBackend/Shader (copier).cs
new file mode 100644
index 00000000..3f719eef
--- /dev/null
+++ b/src/OpenGL/GLBackend/Shader (copier).cs
@@ -0,0 +1,135 @@
+using System;
+using OpenTK.Graphics.OpenGL;
+using System.Diagnostics;
+using OpenTK;
+
+namespace go.GLBackend
+{
+ public class TestShader
+ {
+ string vertexShaderSource = @"
+ #version 130
+
+ //precision highp float;
+
+ uniform float lw;
+ uniform mat4 projection_matrix;
+ uniform mat4 modelview_matrix;
+
+ in vec2 in_position;
+ in vec2 in_tex;
+
+ out vec2 texcoord;
+
+ void main(void)
+ {
+ texcoord = in_tex;
+ gl_Position = projection_matrix * modelview_matrix * vec4(in_position,0, 1);
+ }";
+
+ string fragmentShaderSource = @"
+ #version 130
+
+ //precision highp float;
+ uniform float lw;
+ uniform vec4 color;
+
+ in vec2 texcoord;
+ out vec4 out_frag_color;
+
+ void main(void)
+ {
+// float smoothWidth = 1.0 / lineWidth;
+//
+// if (texcoord.y < smoothWidth)
+// out_frag_color = vec4(color,texcoord.y/smoothWidth);
+// else if (texcoord.y > 1.0 - smoothWidth)
+// out_frag_color = vec4(color,(1.0-texcoord.y)/smoothWidth);
+// else
+// out_frag_color = vec4(color,1.0);
+ out_frag_color = color;
+ }";
+
+ int vertexShaderHandle,
+ fragmentShaderHandle,
+ shaderProgramHandle,
+ modelviewMatrixLocation,
+ projectionMatrixLocation,
+ colorLocation,
+ lineWidthLocation;
+
+ Matrix4 projectionMatrix,
+ modelviewMatrix;
+
+ double lineWidth = 1.0;
+
+ public TestShader ()
+ {
+ vertexShaderHandle = GL.CreateShader(ShaderType.VertexShader);
+ fragmentShaderHandle = GL.CreateShader(ShaderType.FragmentShader);
+
+ GL.ShaderSource(vertexShaderHandle, vertexShaderSource);
+ GL.ShaderSource(fragmentShaderHandle, fragmentShaderSource);
+
+ GL.CompileShader(vertexShaderHandle);
+ GL.CompileShader(fragmentShaderHandle);
+
+ Debug.WriteLine(GL.GetShaderInfoLog(vertexShaderHandle));
+ Debug.WriteLine(GL.GetShaderInfoLog(fragmentShaderHandle));
+
+ // Create program
+ shaderProgramHandle = GL.CreateProgram();
+
+ GL.AttachShader(shaderProgramHandle, vertexShaderHandle);
+ GL.AttachShader(shaderProgramHandle, fragmentShaderHandle);
+
+ GL.BindAttribLocation(shaderProgramHandle, 0, "in_position");
+ GL.BindAttribLocation(shaderProgramHandle, 1, "in_tex");
+
+ GL.LinkProgram(shaderProgramHandle);
+ Debug.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle));
+ GL.UseProgram(shaderProgramHandle);
+
+
+ lineWidthLocation = GL.GetUniformLocation (shaderProgramHandle, "lw");
+ projectionMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "projection_matrix");
+ modelviewMatrixLocation = GL.GetUniformLocation(shaderProgramHandle, "modelview_matrix");
+ colorLocation = GL.GetUniformLocation (shaderProgramHandle, "color");
+
+ }
+
+ int savedPgm = 0;
+ public virtual void Enable(){
+ GL.GetInteger (GetPName.CurrentProgram, out savedPgm);
+ GL.UseProgram (shaderProgramHandle);
+ }
+ public virtual void Disable(){
+ GL.UseProgram (savedPgm);
+ }
+
+ public Matrix4 ProjectionMatrix{
+ set {
+ projectionMatrix = value;
+ GL.UniformMatrix4(projectionMatrixLocation, false, ref projectionMatrix);
+ }
+ }
+ public Matrix4 ModelViewMatrix {
+ set {
+ modelviewMatrix = value;
+ GL.UniformMatrix4 (modelviewMatrixLocation, false, ref modelviewMatrix);
+ }
+ }
+ public double LineWidth {
+ set {
+ lineWidth = value;
+ GL.Uniform1 (lineWidthLocation, (float)lineWidth);
+ }
+ }
+ public Vector4 Color {
+ set {
+ GL.Uniform4 (colorLocation, value);
+ }
+ }
+ }
+}
+