Ejemplo n.º 1
0
        /// <summary>
        /// Initialises the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="width">The width of the screen.</param>
        /// <param name="height">The height of the screen.</param>
        public void Initialise(OpenGL gl, float width, float height)
        {
            //  Set a blue clear colour.
            gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);

            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            shaderProgram = new ShaderProgram();
            shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
            shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
            shaderProgram.AssertValid(gl);

            //  Create a perspective projection matrix.
            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
            projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);

            //  Create a view matrix to move us back a bit.
            viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));

            //  Create a model matrix to make the model a little bigger.
            modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));

            //  Now create the geometry for the square.
            CreateVerticesForSquare(gl);
        }
Ejemplo n.º 2
0
 private ShaderProgram InitShader(OpenGL gl, RenderMode renderMode)
 {
     String vertexShaderSource = ManifestResourceLoader.LoadTextFile(@"Grids.HexahedronGrid.vert");
     String fragmentShaderSource = ManifestResourceLoader.LoadTextFile(@"Grids.HexahedronGrid.frag");
     ShaderProgram shaderProgram = new ShaderProgram();
     shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
     //shaderProgram.BindAttributeLocation(gl, ATTRIB_INDEX_POSITION, in_position);
     //shaderProgram.BindAttributeLocation(gl, ATTRIB_INDEX_COLOUR, in_uv);
     {
         int location = shaderProgram.GetAttributeLocation(gl, in_Position);
         if (location < 0) { throw new ArgumentException(); }
         this.ATTRIB_INDEX_POSITION = (uint)location;
     }
     {
         int location = shaderProgram.GetAttributeLocation(gl, in_uv);
         if (location < 0) { throw new ArgumentException(); }
         this.ATTRIB_INDEX_UV = (uint)location;
     }
     shaderProgram.AssertValid(gl);
     return shaderProgram;
 }
        private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
        {
            //  TODO: Initialise OpenGL here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            gl.PointSize(10);

            string vertex = File.ReadAllText("Shaders//Vertex//default.vert");
            string frag = File.ReadAllText("Shaders//Fragment//default.frag");
            mShaderProgram = new ShaderProgram();
            mShaderProgram.Create(gl, vertex, frag, null);
            mShaderProgram.BindAttributeLocation(gl, mPositionHandle, "in_Position");
            mShaderProgram.AssertValid(gl);

            var vertices = new float[18];
            var colors = new float[18]; // Colors for our vertices
            vertices[0] = -0.5f; vertices[1] = -0.5f; vertices[2] = 0.0f; // Bottom left corner
            colors[0] = 1.0f; colors[1] = 1.0f; colors[2] = 1.0f; // Bottom left corner
            vertices[3] = -0.5f; vertices[4] = 0.5f; vertices[5] = 0.0f; // Top left corner
            colors[3] = 1.0f; colors[4] = 0.0f; colors[5] = 0.0f; // Top left corner
            vertices[6] = 0.5f; vertices[7] = 0.5f; vertices[8] = 0.0f; // Top Right corner
            colors[6] = 0.0f; colors[7] = 1.0f; colors[8] = 0.0f; // Top Right corner
            vertices[9] = 0.5f; vertices[10] = -0.5f; vertices[11] = 0.0f; // Bottom right corner
            colors[9] = 0.0f; colors[10] = 0.0f; colors[11] = 1.0f; // Bottom right corner
            vertices[12] = -0.5f; vertices[13] = -0.5f; vertices[14] = 0.0f; // Bottom left corner
            colors[12] = 1.0f; colors[13] = 1.0f; colors[14] = 1.0f; // Bottom left corner
            vertices[15] = 0.5f; vertices[16] = 0.5f; vertices[17] = 0.0f; // Top Right corner
            colors[15] = 0.0f; colors[16] = 1.0f; colors[17] = 0.0f; // Top Right corner

            //mDrawable = new Drawable(new Verticies(vertices, 3, 6, 3),mShaderProgram,gl);

            mClient.run(this, mShaderProgram, gl);

            //  Set the clear color.
            gl.ClearColor(0, 0.3f, 1, 1);
        }
Ejemplo n.º 4
0
    private async void MapLoad(object sender, EventArgs e)
    {
      var shapelayerText = FileLoader.LoadTextFile("config/shapelayers.json");
      var shapelayers = JsonConvert.DeserializeObject<List<Shapelayer>>(shapelayerText);
      var stationText = FileLoader.LoadTextFile("config/stations.json");
      var stations = JsonConvert.DeserializeObject<NexradStationFile>(stationText);

      var us_stations = stations.stationtable.station.Where(x => x.co == "US");
      var states = us_stations.GroupBy(x => x.st).OrderBy(x => x.Key);
      var list = new ListView();
      list.Columns.Add(new ColumnHeader() { Width = list.Width - 10 });
      list.HeaderStyle = ColumnHeaderStyle.None; 
      list.Alignment = ListViewAlignment.Left;
      list.AutoArrange = false;
      list.CheckBoxes = true;
      list.Margin = new Padding(30);
      list.Height = 500;
      list.Width = 250;
      list.ShowGroups = true;
      list.View = View.Details;
   
      foreach (var shapelayer in shapelayers)
      {
        if (list.Groups[shapelayer.category] == null)
        {
          list.Groups.Add(shapelayer.category, shapelayer.category);
        }
        var cur_renderable = new ShapeData(shapelayer.file, shapelayer.r, shapelayer.g, shapelayer.b, shapelayer.category, shapelayer.description);
        all_renderables.Add(cur_renderable);
        var item = list.Items.Add(shapelayer.description);
        item.Group = list.Groups[shapelayer.category];
        item.Checked = shapelayer.enabled;
        if (item.Checked)
        {
          load_renderables.Add(cur_renderable);
        }
      }

      for (int i = 0; i < states.Count(); i++)
      {
        var grp = list.Groups.Add(states.ElementAt(i).Key, states.ElementAt(i).Key);   
      }
      foreach(var station in us_stations){
        var cur_renderable = new RadarScan("K" + station.id, station.st);
        all_renderables.Add(cur_renderable);
        var item = list.Items.Add("K" + station.id + " " + station.name);
        item.Group = list.Groups[station.st];
        item.Checked = station.enabled;
        if (item.Checked)
        {
          load_renderables.Add(cur_renderable);
        }
      }

      list.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
      panel1.Controls.Add(list);
      list.ItemChecked += list_ItemChecked;


      loadThread = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread.Start();
      loadThread2 = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread2.Start();
      loadThread3 = new Thread(new ThreadStart(loaderThreadFunc));
      loadThread3.Start();

      overlayControl.OpenGLDraw += overlayControl_Draw;
      overlayControl.Resized += overlayControl_Resized;

      var gl = overlayControl.OpenGL;
      gl.Enable(OpenGL.GL_BLEND);
      gl.BlendFunc(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
      var vertexShaderSource = FileLoader.LoadTextFile("Shader.vert");
      var fragmentShaderSource = FileLoader.LoadTextFile("Shader.frag");
      shaderProgram = new ShaderProgram();
      shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
      shaderProgram.BindAttributeLocation(gl, 0, "in_Position");
      shaderProgram.BindAttributeLocation(gl, 1, "in_Color");
      shaderProgram.AssertValid(gl);

      overlayControl_Resized(null, null);

      overlayControl.Click += overlayControl_Click;
      overlayControl.MouseMove += OnMouseMove;
      overlayControl.MouseDown += OnMouseDown;
      overlayControl.MouseUp += OnMouseUp;
      overlayControl.MouseWheel += overlayControl_MouseWheel;
    }
 /// <summary>
 /// Handles the OpenGLInitialized event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     //  TODO: Initialise OpenGL here.
     //  Get the OpenGL object.
     OpenGL gl = openGLControl.OpenGL;
     gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);
     //  Set a blue clear colour.
     gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);
     gl.ClearColor(0f, 0f, 0f, 0.0f);
     //  Create the shader program.
     var vertexShaderSource = ManifestResourceLoader.LoadTextFile("vertex_shader.glsl");
     var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("fragment_shader.glsl");
     shaderProgram = new ShaderProgram();
     shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
     attribute_vpos = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vPosition");
     attribute_vcol = (uint)gl.GetAttribLocation(shaderProgram.ShaderProgramObject, "vColor");
     shaderProgram.AssertValid(gl);
     InitializeFixedBufferContents();
 }
        private void CreateShader(SharpGL.OpenGL gl)
        {
            //  Create the shader program.
            var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
            var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
            m_shaderProgram = new ShaderProgram();
            m_shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            m_shaderProgram.BindAttributeLocation(gl, AttributeIndexPosition, "in_Position");
            m_shaderProgram.BindAttributeLocation(gl, AttributeIndexColour, "in_Color");
            m_shaderProgram.AssertValid(gl);

            m_shader = new ShaderWrapper(m_shaderProgram, gl);
        }