public OpenTK_AssimpModel()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // add "built-in" meshs
            _model_names[_name_trefoil_knot] = _name_trefoil_knot;

            // get wavefront files
            List <string> names = new List <string>();

            //Assembly assembly = Assembly.GetExecutingAssembly();
            //names = new List<string>(assembly.GetManifestResourceNames());

            string working_directory = Directory.GetCurrentDirectory();

            if (Directory.Exists(working_directory))
            {
                names = new List <string>(Directory.GetFiles(working_directory, "*.obj", SearchOption.AllDirectories));
            }

            // add wavefront models
            foreach (var name in new List <string>(names))
            {
                if (name.EndsWith(".obj"))
                {
                    var user_name = name.Substring(0, name.Length - 4);
                    var pos       = user_name.LastIndexOfAny(new char[] { '.', '\\' });
                    user_name = user_name.Substring(pos + 1, user_name.Length - pos - 1);
                    _model_names[user_name] = name;
                }
            }
        }
Example #2
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // Create shader program

            string vert_shader = @"#version 460

            layout (location = 0) in vec2 in_pos;
            layout (location = 1) in vec2 in_uv;

            out vec2 vUV;

            layout (location = 0) uniform mat4 model;
            layout (location = 1) uniform mat4 projection;
            
            void main()
            {
                vUV         = in_uv.xy;
		        gl_Position = projection * model * vec4(in_pos.xy, 0.0, 1.0);
            }";

            string frag_shader = @"#version 460

            in vec2 vUV;

            layout (binding=0) uniform sampler2D u_texture;

             layout (location = 2) uniform vec3 textColor;

            out vec4 fragColor;

            void main()
            {
                vec2 uv = vUV.xy;
                float text = texture(u_texture, uv).r;
                fragColor = vec4(textColor.rgb*text, text);
            }";

            this._text_prog = openGLFactory.VertexAndFragmentShaderProgram(vert_shader, frag_shader);
            this._text_prog.Generate();
            this._text_prog.Use();

            // load font
            _font = new FreeTypeFont(32);

            base.OnLoad();
        }
 private void ExtensionDetached(object sender, WiimoteExtensionEventArgs args)
 {
     Gtk.Application.Invoke(delegate
     {
         GtkAlignment2.Remove(_ExtensionInformation.Widget);
         _ExtensionInformation = null;
     });
 }
Example #4
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            // [...]

            // Create shader program

            // [...]

            // framebuffers

            _fbos = new List <IFramebuffer>();
            _fbos.Add(openGLFactory.NewFramebuffer());
            _fbos[0].Create(_image_cx, _image_cy, IFramebuffer.Kind.texture, IFramebuffer.Format.RGBA_F32, true, false);
            _fbos[0].Clear();
            _fbos.Add(openGLFactory.NewFramebuffer());
            _fbos[1].Create(_image_cx, _image_cy, IFramebuffer.Kind.texture, IFramebuffer.Format.RGBA_F32, true, false);
            _fbos[1].Clear();
            _fbos.Add(openGLFactory.NewFramebuffer());
            _fbos[2].Create(_image_cx, _image_cy, IFramebuffer.Kind.texture, IFramebuffer.Format.RGBA_F32, true, false);
            _fbos[2].Clear();

            // create generators
            this._generators = new List <TextureGenerator>();
            this._generators.Add(new TextureGenerator(openGLFactory, TextureGenerator.TType.texture_test1, new ITexture[] { _fbos[0].Textures[0] }));
            this._generators.Add(new TextureGenerator(openGLFactory, TextureGenerator.TType.heightmap_test1, new ITexture[] { _fbos[1].Textures[0] }));
            this._generators.Add(new TextureGenerator(openGLFactory, TextureGenerator.TType.cone_step_map, new ITexture[] { _fbos[2].Textures[0] }, new ITexture[] { _fbos[1].Textures[0] }));

            foreach (var generator in this._generators)
            {
                generator.GenetateProgram();
            }

            // states

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        }
 private void ExtensionAttached(object sender, WiimoteExtensionEventArgs args)
 {
     Gtk.Application.Invoke(delegate {
         if (_Wiimote.Extension is NunchukExtension)
         {
             _ExtensionInformation = new NunchukInformation((NunchukExtension)_Wiimote.Extension);
             GtkAlignment2.Add(_ExtensionInformation.Widget);
         }
         else if (_Wiimote.Extension is GuitarExtension)
         {
             _ExtensionInformation = new GuitarInformation((GuitarExtension)_Wiimote.Extension);
             GtkAlignment2.Add(_ExtensionInformation.Widget);
         }
         else if (_Wiimote.Extension is ClassicControllerExtension)
         {
             _ExtensionInformation = new ClassicControllerInformation((ClassicControllerExtension)_Wiimote.Extension);
             GtkAlignment2.Add(_ExtensionInformation.Widget);
         }
     });
 }
Example #6
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            float[] vquad =
            {
                // x      y     z      r     g     b     a
                -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f,  -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f,   1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
                -1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f
            };

            uint[] iquad = { 0, 1, 2, 0, 2, 3 };

            TVertexFormat[] format =
            {
                new TVertexFormat(0, 0, 3, 0, false),
                new TVertexFormat(0, 1, 4, 3, false),
            };

            int vao = GL.GenVertexArray();

            GL.BindVertexArray(vao);

            // Create shader program

            string vert_shader = @"
            #version 460 core

            layout(std430, binding = 0) buffer TVertex
            {
               vec4 vertex[]; 
            };

            uniform mat4  u_mvp;
            uniform vec2  u_resolution;
            uniform float u_thickness;
            
            void main()
            {
                int line_i = gl_VertexID / 6;
                int tri_i  = gl_VertexID % 6;
                vec4 va[4];
                for (int i=0; i<4; ++i)
                {
                    va[i] = u_mvp * vertex[line_i+i];
                    va[i].xyz /= va[i].w;
                    va[i].xy = (va[i].xy + 1.0) * 0.5 * u_resolution;
                }
                vec2 v_line  = normalize(va[2].xy - va[1].xy);
                vec2 nv_line = vec2(-v_line.y, v_line.x);
    
                vec4 pos;
                if (tri_i == 0 || tri_i == 1 || tri_i == 3)
                {
                    vec2 v_pred  = normalize(va[1].xy - va[0].xy);
                    vec2 v_miter = normalize(nv_line + vec2(-v_pred.y, v_pred.x));
                    pos = va[1];
                    pos.xy += v_miter * u_thickness * (tri_i == 1 ? -0.5 : 0.5) / dot(v_miter, nv_line);
                }
                else
                {
                    vec2 v_succ  = normalize(va[3].xy - va[2].xy);
                    vec2 v_miter = normalize(nv_line + vec2(-v_succ.y, v_succ.x));
                    pos = va[2];
                    pos.xy += v_miter * u_thickness * (tri_i == 5 ? 0.5 : -0.5) / dot(v_miter, nv_line);
                }
                pos.xy = pos.xy / u_resolution * 2.0 - 1.0;
                pos.xyz *= pos.w;
                gl_Position = pos;
            }";

            string frag_shader = @"
            #version 460 core
            
            out vec4 fragColor;
            uniform vec4 u_color;
            
            void main()
            {
                fragColor = u_color;
            }";

            _test_prog = openGLFactory.VertexAndFragmentShaderProgram(vert_shader, frag_shader);
            _test_prog.Generate();

            mvpLocation        = GL.GetUniformLocation(this._test_prog.Object, "u_mvp");
            resolutionLocation = GL.GetUniformLocation(this._test_prog.Object, "u_resolution");
            thicknessLocation  = GL.GetUniformLocation(this._test_prog.Object, "u_thickness");
            colorLocation      = GL.GetUniformLocation(this._test_prog.Object, "u_color");
            _test_prog.Use();

            float[] p0    = { -1.0f, -1.0f, 0.0f, 1.0f };
            float[] p1    = { 1.0f, -1.0f, 0.0f, 1.0f };
            float[] p2    = { 1.0f, 1.0f, 0.0f, 1.0f };
            float[] p3    = { -1.0f, 1.0f, 0.0f, 1.0f };
            float[] line1 = p3.Concat(p0).Concat(p1).Concat(p2).Concat(p3).Concat(p0).Concat(p1).ToArray();
            _lineBuffer1 = openGLFactory.NewStorageBuffer();
            _lineBuffer1.Create(line1);
            _no_vertices_1 = line1.Length / 4;

            var ll2 = new List <float>();

            for (int u = -8; u <= 368; u += 8)
            {
                double a = u * Math.PI / 180.0;
                double c = Math.Cos(a), s = Math.Sin(a);
                ll2.AddRange(new float[] { (float)c, (float)s, 0.0f, 1.0f });
            }
            float[] line2 = ll2.ToArray();
            _lineBuffer2 = openGLFactory.NewStorageBuffer();
            _lineBuffer2.Create(line2);
            _no_vertices_2 = line2.Length / 4;

            // states

            GL.ClearColor(0.8f, 0.9f, 1.0f, 1.0f);

            base.OnLoad();
        }
Example #7
0
 public Rubiks()
 {
     _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
     _extensions     = openGLFactory.NewExtensionInformation();
     _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);
 }
Example #8
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            float[] vquad =
            {
                // x      y     z      r     g     b     a
                -1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
                1.0f,  -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f,   1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
                -1.0f,  1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f
            };

            uint [] iquad = { 0, 1, 2, 0, 2, 3 };

            TVertexFormat[] format =
            {
                new TVertexFormat(0, 0, 3, 0, false),
                new TVertexFormat(0, 1, 4, 3, false),
            };

            _test_vao = openGLFactory.NewVertexArrayObject();
            _test_vao.AppendVertexBuffer(0, 7, vquad);
            _test_vao.Create(format, iquad);

            // Create shader program

            string vert_shader = @"#version 460 core
            layout (location = 0) in vec4 a_pos;
            layout (location = 1) in vec4 a_color;
      
            out vec4 v_color;
            uniform mat4 u_transform;

            void main()
            {
                v_color     = a_color;
                gl_Position = u_transform * a_pos; 
            }";

            string frag_shader = @"#version 460 core
            out vec4 frag_color;
            in  vec4 v_color;
      
            void main()
            {
                frag_color = v_color; 
            }";

            this._test_prog = openGLFactory.VertexAndFragmentShaderProgram(vert_shader, frag_shader);
            this._test_prog.Generate();

            this._test_prog.Use();

            // states

            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);

            base.OnLoad();
        }
Example #9
0
 public LoaderExtension(Assembly assembly, Type start, IExtensionInformation info)
 {
     this.Assembly    = assembly;
     this.Start       = start;
     this.Information = info;
 }
Example #10
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            // ...

            // Create shader program

            string compute_shader =
                @"#version 460

            layout(local_size_x = 1, local_size_y = 1) in;
            layout(rgba32f, binding = 1) writeonly uniform image2D img_output;

            layout(location = 1) uniform vec4  u_color;
            layout(location = 2) uniform float u_margin;
            layout(location = 3) uniform float u_random; 

            layout(std430, binding = 1) buffer TCoord1
            {
                vec4 pos;
            } coord_inout;

            vec4[7] constants = vec4[7](
                vec4(0.0,  0.85,  0.2,   -0.15),  
                vec4(0.0,  0.04, -0.26,   0.28),  
                vec4(0.0, -0.04,  0.23,   0.26),  
                vec4(0.16, 0.85,  0.22,   0.24),  
                vec4(0.0,  0.0,   0.0,    0.0 ),  
                vec4(0.0,  1.6,   1.6,    0.44),  
                vec4(1.0, 86.0,  93.0,  100.0 ));  

            void main() {
  
                  vec2 dims = vec2(imageSize(img_output)); // fetch image dimensions

                  int i = 0; 
                  for (; i < 4; ++i)
                  {
                      if (u_random*100.0 < constants[6][i])
                          break;
                  }
                  i = min(i, 3);

                  vec2 fern = vec2(
                      constants[0][i] * coord_inout.pos.x + constants[1][i] * coord_inout.pos.y + constants[4][i],
                      constants[2][i] * coord_inout.pos.x + constants[3][i] * coord_inout.pos.y + constants[5][i]);
                  coord_inout.pos.xy = fern;
                  
                  vec2 pixel_coords = vec2(
                      (fern.x + 2.1820 + u_margin) * dims.x / (2.1820 + 2.6558 + 2.0 * u_margin),  
                      dims.y - (-fern.y + 9.9983 + u_margin) * dims.y / (9.9983 + 2.0 * u_margin));
                  
                  // output to a specific pixel in the image
                  imageStore(img_output, ivec2(pixel_coords), u_color);
            }";

            this._compute_prog = openGLFactory.ComputeShaderProgram(compute_shader);
            this._compute_prog.Generate();

            // Model view projection shader storage block objects and buffers
            _coord_ssbo = openGLFactory.NewStorageBuffer();
            TCoordinate coord_data = new TCoordinate(Vector2.Zero);

            this._coord_ssbo.Create(ref coord_data, IStorageBuffer.Usage.ReadWrite);
            this._coord_ssbo.Bind(1);

            // framebuffers

            _fbo = openGLFactory.NewFramebuffer();
            _fbo.Create(_image_cx, _image_cy, IFramebuffer.Kind.texture, IFramebuffer.Format.RGBA_F32, true, false);
            _fbo.Clear(new Color4(0.2f, 0.1f, 0.0f, 1.0f));

            // states

            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);

            base.OnLoad();
        }
Example #11
0
 public Extension(IExtensionRequiem ext, IExtensionInformation info, string[] dependencies)
 {
     this.Start        = ext;
     this.Information  = info;
     this.Dependencies = dependencies;
 }
Example #12
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            (float[] attributes, uint[] indices) = new TrefoilKnot(256, 16).Create();
            TVertexFormat[] format =
            {
                new TVertexFormat(0, 0, 3, 0, false),
                new TVertexFormat(0, 1, 3, 3, false),
                //new TVertexFormat(0, ?, 2, 6, false),
                new TVertexFormat(0, 2, 4, 8, false),
            };

            _test_vao = openGLFactory.NewVertexArrayObject();
            _test_vao.AppendVertexBuffer(0, 12, attributes);
            _test_vao.Create(format, indices);
            _test_vao.Bind();

            // Create shader program

            string vert_shader = @"#version 460 core
            layout (location = 0) in vec4 a_pos;
            layout (location = 1) in vec3 a_nv;
            layout (location = 2) in vec4 a_color;
      
            layout (location = 0) out TVertexData
            {
                vec3 pos;
                vec3 nv;
                vec4 col;
            } outData;

            layout(std430, binding = 1) buffer MVP
            {
                mat4 proj;
                mat4 view;
                mat4 model;
            } mvp;

            void main()
            {
                mat4 mv_mat     = mvp.view * mvp.model;
                mat3 normal_mat = inverse(transpose(mat3(mv_mat))); 

                outData.nv   = normalize(normal_mat * a_nv);
                outData.col  = a_color;
                vec4 viewPos = mv_mat * a_pos;
                outData.pos  = viewPos.xyz / viewPos.w;
                gl_Position  = mvp.proj * viewPos;
            }";

            string frag_shader = @"#version 460 core
            out vec4 frag_color;
            
            layout (location = 0) in TVertexData
            {
                vec3 pos;
                vec3 nv;
                vec4 col;
            } inData;

            layout(std430, binding = 2) buffer TLight
            {
                vec4  u_lightDir;
                float u_ambient;
                float u_diffuse;
                float u_specular;
                float u_shininess;
            } light_data;
      
            void main()
            {
                vec3 color = inData.col.rgb;

                // ambient part
                vec3 lightCol = light_data.u_ambient * color;
                vec3 normalV  = normalize( inData.nv );
                vec3 eyeV     = normalize( -inData.pos );
                vec3 lightV   = normalize( -light_data.u_lightDir.xyz );

                // diffuse part
                float NdotL   = max( 0.0, dot( normalV, lightV ) );
                lightCol     += NdotL * light_data.u_diffuse * color;

                // specular part
                vec3  halfV     = normalize( eyeV + lightV );
                float NdotH     = max( 0.0, dot( normalV, halfV ) );
                float kSpecular = ( light_data.u_shininess + 2.0 ) * pow( NdotH, light_data.u_shininess ) / ( 2.0 * 3.14159265 );
                lightCol       += kSpecular * light_data.u_specular * color;

                frag_color = vec4( lightCol.rgb, inData.col.a );
            }";

            this._test_prog = openGLFactory.VertexAndFragmentShaderProgram(vert_shader, frag_shader);
            this._test_prog.Generate();

            // Model view projection shader storage block objects and buffers
            TMVP mvp = new TMVP(Matrix4.Identity, Matrix4.Identity, Matrix4.Identity);

            this._mvp_ssbo = openGLFactory.NewStorageBuffer();
            this._mvp_ssbo.Create(ref mvp);
            this._mvp_ssbo.Bind(1);

            TLightSource light_source = new TLightSource(new Vector4(-1.0f, -0.5f, -2.0f, 0.0f), 0.2f, 0.8f, 0.8f, 10.0f);

            this._light_ssbo = openGLFactory.NewStorageBuffer();
            this._light_ssbo.Create(ref light_source);
            this._light_ssbo.Bind(2);

            // states

            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);

            // matrices and controller

            this._view = Matrix4.LookAt(0.0f, 0.0f, 1.5f, 0, 0, 0, 0, 1, 0);

            var spin = new ModelSpinningControls(
                () => { return(this._period); },
                () => { return(new float[] { 0, 0, (float)this.Size.X, (float)this.Size.Y }); },
                () => { return(this._view); }
                );

            spin.SetAttenuation(1.0f, 0.05f, 0.0f);
            this._controls = spin;

            base.OnLoad();
        }
Example #13
0
        //! On load window (once)
        protected override void OnLoad()
        {
            _version        = openGLFactory.NewVersionInformation(Console.WriteLine);
            _extensions     = openGLFactory.NewExtensionInformation();
            _debug_callback = openGLFactory.NewDebugCallback(Console.WriteLine);

            // Version strings
            _version.Retrieve();

            // Get OpenGL extensions
            _extensions.Retrieve();

            // Debug callback
            _debug_callback.Init();

            // create Vertex Array Object, Array Buffer Object and Element Array Buffer Object

            float[] vquad =
            {
                // x      y     z      u     v
                -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
                0.5f,  -0.5f, 0.0f, 1.0f, 1.0f,
                0.5f,   0.5f, 0.0f, 1.0f, 0.0f,
                -0.5f,  0.5f, 0.0f, 0.0f, 0.0f
            };

            uint[] iquad = { 0, 1, 2, 0, 2, 3 };

            TVertexFormat[] format =
            {
                new TVertexFormat(0, 0, 3, 0, false),
                new TVertexFormat(0, 1, 2, 3, false),
            };

            _test_vao = openGLFactory.NewVertexArrayObject();
            _test_vao.AppendVertexBuffer(0, 5, vquad);
            _test_vao.Create(format, iquad);

            // Create texture

            Assembly assembly = Assembly.GetExecutingAssembly();

            string[] names           = assembly.GetManifestResourceNames();
            Stream   resource_stream = assembly.GetManifestResourceStream("OpenTK_example_3.Resource.background.jpg");

            _test_texture = openGLFactory.NewTexture();
            _test_texture.Create2D(new Bitmap(resource_stream));

            // Create shader program

            string vert_shader = @"#version 460 core
            layout (location = 0) in vec4 a_pos;
            layout (location = 1) in vec2 a_uv;
      
            out vec2 v_uv;

            void main()
            {
                v_uv        = a_uv;
                gl_Position = a_pos; 
            }";

            string frag_shader = @"#version 460 core
            out vec4 frag_color;
            in  vec2 v_uv;
            layout(binding = 7) uniform sampler2D u_texture; 
      
            void main()
            {
                frag_color = texture(u_texture, v_uv).rgba; 
            }";

            this._test_prog = openGLFactory.VertexAndFragmentShaderProgram(vert_shader, frag_shader);
            this._test_prog.Generate();

            this._test_prog.Use();

            // states

            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);

            base.OnLoad();
        }