Esempio n. 1
0
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
            {
                if (this.shaderProgram == null)
                {
                    this.shaderProgram = InitShader(gl, renderMode);
                }
                if (this.vertexArrayObject == null)
                {
                    CreateVertexArrayObject(gl, renderMode);
                }

                BeforeRendering(gl, renderMode);

                if (this.RenderGrid && this.vertexArrayObject != null)
                {
                    gl.Enable(OpenGL.GL_BLEND);
                    gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                    gl.BindVertexArray(this.vertexArrayObject[0]);
                    gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
                    gl.BindVertexArray(0);

                    gl.Disable(OpenGL.GL_BLEND);
                }

                AfterRendering(gl, renderMode);
            }
        }
        public override void Draw(SharpGL.OpenGL gl)
        {
            gl.PushMatrix();
            gl.PushAttrib(AttributeMask.All);
            gl.PushClientAttrib(OpenGL.GL_CLIENT_ALL_ATTRIB_BITS);

            gl.VertexPointer(3, 0, vertexs);
            gl.NormalPointer(OpenGL.GL_FLOAT, 0, normals);
            gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, texCoord);

            gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
            //gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
            gl.EnableClientState(OpenGL.GL_NORMAL_ARRAY);
            gl.EnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);

            gl.Translate(position.x, position.y + sizeY / 2, position.z);

            gl.Color(color.GetInArrWithAlpha());

            if (texture != null)
            {
                gl.Enable(OpenGL.GL_TEXTURE_2D);
                texture.Bind(gl);
            }
            else
            {
                gl.Disable(OpenGL.GL_TEXTURE_2D);
            }

            gl.DrawArrays(OpenGL.GL_QUADS, 0, 24);

            gl.PopClientAttrib();
            gl.PopAttrib();
            gl.PopMatrix();
        }
Esempio n. 3
0
 private void RenderVertices_VertexArray(OpenGL gl)
 {
     gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
     gl.VertexPointer(3, 0, vertexArrayValues);
     gl.DrawArrays(OpenGL.GL_POINTS, 0, 2);//vertices.Length);
     gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
 }
        public void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode)
        {
            gl.BindVertexArray(vao[0]);

            gl.DrawArrays((uint)primitiveMode, 0, vertexCount);

            gl.BindVertexArray(0);
        }
Esempio n. 5
0
        private void DrawSound()
        {
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            float[] spectrum = new float[256];
            float[] wavedata = new float[512];
            Player.getWaveData(ref wavedata, 256, 0);
            Player.getSpectrum(ref spectrum, 256, 0);

            DateTime currentDate = DateTime.Now;
            float    time        = (float)currentDate.Ticks / (float)TimeSpan.TicksPerSecond;

            gl.Uniform1(timeLoc, time);
            gl.Uniform1(sampleLoc, 256, spectrum);

            gl.Uniform1(waveLoc, 256, wavedata);
            gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);

            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 6);
        }
Esempio n. 6
0
        /// <summary>
        /// Draws the scene.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void Draw(OpenGL gl)
        {
            //  Clear the scene.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(gl);

            //  Draw the square.
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 6); 

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(gl);
            shaderProgram.Unbind(gl);
        }
Esempio n. 7
0
        /// <summary>
        /// 渲染此元素。
        /// </summary>
        /// <param name="gl"></param>
        /// <param name="renderMode"></param>
        public virtual void Render(SharpGL.OpenGL gl, SharpGL.SceneGraph.Core.RenderMode renderMode)
        {
            BeforeRendering(gl, renderMode);

            ShaderProgram shader = this.shaderProgram;// GetShader(gl, renderMode);

            shader.Bind(gl);

            // 用VAO+EBO进行渲染。
            //  Bind the out vertex array.
            gl.BindVertexArray(vao[0]);

            gl.DrawArrays(this.primitiveMode, 0, this.primitiveCount);

            //  Unbind our vertex array and shader.
            gl.BindVertexArray(0);

            shader.Unbind(gl);

            AfterRendering(gl, renderMode);
        }
Esempio n. 8
0
        public void Render(SharpGL.OpenGL gl, RenderMode renderMode)
        {
            if (this._colorVertexes.Size <= 0)
            {
                return;
            }

            unsafe
            {
                gl.Enable(OpenGL.GL_DEPTH_TEST);
                gl.Enable(0X8861);

                gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
                gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);

                gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, (IntPtr)this._colorVertexes.Centers);
                gl.ColorPointer(3, OpenGL.GL_BYTE, 0, (IntPtr)this._colorVertexes.Colors);

                gl.DrawArrays(OpenGL.GL_POINTS, 0, this._colorVertexes.Size);

                gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
                gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
            }
        }
Esempio n. 9
0
        private void runGlThread(object args)
        {
            var inputs = (Tuple<CancellationToken>) args;

            var cancelToken = inputs.Item1;
            var gl = new OpenGL();

            int localRenderWidth = 1;
            int localRenderHeight = 1;
            if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
            {
            //TODO better error handling here
            Console.WriteLine("*** Unable to create OpenGL Render Context");
            return;
            }

            uint activeVaoHandle;
            uint activeGlProgramHandle;
            initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);

            ActiveProgramValues localActiveProgramValues = null;
            while (!cancelToken.IsCancellationRequested)
            {
            bool resizeRenderContext;
            lock (this)
            {
                if (!ReferenceEquals(localActiveProgramValues, activeProgramValues))
                {
                    localActiveProgramValues = activeProgramValues;
                    if (localActiveProgramValues.Valid)
                    {
                        linkProgram(gl, localActiveProgramValues, activeGlProgramHandle);
                    } else
                    {
                        // Leave the old program running. This prevents the user from seeing
                        // a black screen while they are in the process of modifying a shader.
                    }
                }

                resizeRenderContext = localRenderWidth != renderWidth || localRenderHeight != renderHeight;
                localRenderWidth = renderWidth;
                localRenderHeight = renderHeight;
            }

            if (resizeRenderContext)
            {
                localActiveProgramValues = null;
                deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
                if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
                {
            //TODO better error handling here
                    Console.WriteLine("*** Unable to resize OpenGL Render Context");
                    return;
                }
                initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
            }

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);
            gl.BindVertexArray(activeVaoHandle);
            gl.UseProgram(activeGlProgramHandle);
            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);

            // do some other stuff while the image is rendering, to give it a chance to finish
            ShaderCompiler.ValidateShaders(gl);

            var provider = gl.RenderContextProvider as FBORenderContextProvider;
            Debug.Assert(provider != null, "Render context provider is not an FBO renderer");
            //TODO this call to blit will probably block. Find a better way to copy the image to CPU memory.
            gl.Blit(IntPtr.Zero);
            var hBitmap = provider.InternalDIBSection.HBitmap;

            if (hBitmap != IntPtr.Zero)
            {
                var bitmap = GetFormattedBitmapSource(hBitmap);
                // the bitmap needs to be frozen in order to share it between threads
                bitmap.Freeze();
                ImageRendered(bitmap);
            }
            }

            deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
        }
        void CreateAndPlotData(OpenGL GL, float[] raw_data, int figureID)
        {
            if (_dataTail[figureID] + raw_data.Length >= C_SAMPLES_PER_FRAME)
            {
                _dataTail[figureID] = 0; // Clear the buffer
            }
            AddVerticesToFigure(figureID, raw_data, _dataTail[figureID]);

            //  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(GL);
            vertexBufferArray.Bind(GL);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(GL);
            vertexDataBuffer.Bind(GL);
            vertexDataBuffer.SetData(GL, attribute_vpos, _data[figureID], false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();
            colourDataBuffer.Create(GL);
            colourDataBuffer.Bind(GL);
            colourDataBuffer.SetData(GL, attribute_vcol, _dataColor[figureID], false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(GL);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(GL);
            //shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            //shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(GL, "modelMatrix", mviewdata.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(GL);

            //  Draw the square.
            GL.DrawArrays(OpenGL.GL_LINE_STRIP, 0, _dataTail[figureID]);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(GL);
            shaderProgram.Unbind(GL);
        }
        void CreateAndDrawGrid(OpenGL GL)
        {
            // Debug.WriteLine("Painting Begins..");

            // Create vertices for 4 lines that will split the figure into 3 equal sections
            xgrid = new vec3[(C_NUM_Y_DIV + 1) * 2];
            for (int i = 0; i < (C_NUM_Y_DIV + 1) * 2; i = i + 2)
            {
                xgrid[i].x = -1f; xgrid[i + 1].x = 1f;
                xgrid[i].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2; xgrid[i + 1].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2;
                xgrid[i].z = 0f; xgrid[i + 1].z = 0f;
            }

            coldata = new vec3[] {
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White),
                GL.Color(DR.Color.White)
            };

            mviewdata = new mat4(1.0f);

            // --------------- Implementation WITH VERTEX ARRAY OBJECTS --------------------
            ////  Create the vertex array object.
            vertexBufferArray = new VertexBufferArray();
            vertexBufferArray.Create(GL);
            vertexBufferArray.Bind(GL);

            //  Create a vertex buffer for the vertex data.
            var vertexDataBuffer = new VertexBuffer();
            vertexDataBuffer.Create(GL);
            vertexDataBuffer.Bind(GL);
            vertexDataBuffer.SetData(GL, attribute_vpos, xgrid, false, 3);

            //  Now do the same for the colour data.
            var colourDataBuffer = new VertexBuffer();
            colourDataBuffer.Create(GL);
            colourDataBuffer.Bind(GL);
            colourDataBuffer.SetData(GL, attribute_vcol, coldata, false, 3);

            //  Unbind the vertex array, we've finished specifying data for it.
            vertexBufferArray.Unbind(GL);

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(GL);
            //shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            //shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(GL, "modelview", mviewdata.to_array());

            //  Bind the out vertex array.
            vertexBufferArray.Bind(GL);

            GL.DrawArrays(OpenGL.GL_LINES, 0, 8);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(GL);
            shaderProgram.Unbind(GL);

            // --------------- Implementation WITH VERTEX ARRAY OBJECTS END --------------------
        }
Esempio n. 12
0
        /// <summary>
        /// 渲染基质
        /// </summary>
        /// <param name="gl"></param>
        /// <param name="renderMode"></param>
        private void DoRenderMatrix(OpenGL gl, RenderMode renderMode)
        {
            if (this.positionBuffer == null || this.colorBuffer == null) { return; }

            if (this.RenderGrid && this.matrixVertexArrayObject != null)
            {
                shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);
                shaderProgram.SetUniform1(gl, "opacity", this.Opacity);

                gl.Enable(OpenGL.GL_POLYGON_OFFSET_FILL);
                gl.PolygonOffset(1.0f, 1.0f);

                gl.Enable(OpenGL.GL_BLEND);
                gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                gl.BindVertexArray(matrixVertexArrayObject[0]);

                switch (this.MatrixType)
                {
                    case MatrixFormat.Triangle:
                        gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
                        break;
                    case MatrixFormat.Tetrahedron:
                        gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                        gl.PrimitiveRestartIndex(uint.MaxValue);

                        gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
                        gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                        gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
                        break;
                    case MatrixFormat.TriangularPrism:
                        // 先渲染三棱柱的上下三角形
                        gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount);
                        // 再渲染三棱柱的三个侧面
                        gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                        gl.PrimitiveRestartIndex(uint.MaxValue);
                        gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
                        gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                        gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
                        break;
                    default:
                        break;
                }
                gl.BindVertexArray(0);
                gl.Disable(OpenGL.GL_BLEND);

                gl.Disable(OpenGL.GL_POLYGON_OFFSET_FILL);
            }

            if (this.RenderGridWireframe && this.matrixVertexArrayObject != null)
            {
                shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);
                shaderProgram.SetUniform1(gl, "opacity", this.Opacity);
                gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);

                gl.Enable(OpenGL.GL_BLEND);
                gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);

                gl.BindVertexArray(matrixVertexArrayObject[0]);
                switch (this.MatrixType)
                {
                    case MatrixFormat.Triangle:
                        gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
                        break;
                    case MatrixFormat.Tetrahedron:
                        gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                        gl.PrimitiveRestartIndex(uint.MaxValue);
                        gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
                        gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                        gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
                        break;
                    case MatrixFormat.TriangularPrism:
                        // 先渲染三棱柱的上下三角形
                        gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount / 9 * 6);
                        // 再渲染三棱柱的三个侧面
                        gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
                        gl.PrimitiveRestartIndex(uint.MaxValue);
                        gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
                        gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                        gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
                        break;
                    default:
                        break;
                }
                gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
                gl.BindVertexArray(0);

                gl.Disable(OpenGL.GL_BLEND);
            }
        }
Esempio n. 13
0
        private void DoRenderFraction(OpenGL gl, RenderMode renderMode)
        {
            if (this.fractionPositionBuffer == null || this.fractionUVBuffer == null) { return; }

            if (this.RenderFraction && this.fractionVertexArrayObject != null)
            {
                shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);

                gl.Enable(OpenGL.GL_POLYGON_OFFSET_FILL);
                gl.PolygonOffset(1.0f, 1.0f);

                gl.BindVertexArray(fractionVertexArrayObject[0]);

                switch (this.FractionType)
                {
                    case FractureFormat.Line:
                        float[] originalWidth = new float[1];
                        gl.GetFloat(SharpGL.Enumerations.GetTarget.LineWidth, originalWidth);

                        gl.LineWidth(this.FractionLineWidth);
                        gl.DrawArrays(OpenGL.GL_LINES, 0, this.FractionVertexCount);

                        gl.LineWidth(originalWidth[0]);
                        break;
                    case FractureFormat.Triange:
                        gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.FractionVertexCount);
                        break;
                    case FractureFormat.Quad:
                        gl.DrawArrays(OpenGL.GL_QUADS, 0, this.FractionVertexCount);
                        break;
                    default:
                        throw new NotImplementedException();
                    //break;
                }

                gl.BindVertexArray(0);

                gl.Disable(OpenGL.GL_POLYGON_OFFSET_FILL);
            }

            if (this.renderFractionWireframe && this.fractionVertexArrayObject != null)
            {
                shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);

                gl.BindVertexArray(fractionVertexArrayObject[0]);
                {
                    gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);

                    switch (this.FractionType)
                    {
                        case FractureFormat.Line:
                            gl.DrawArrays(OpenGL.GL_LINES, 0, this.FractionVertexCount);
                            break;
                        case FractureFormat.Triange:
                            gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.FractionVertexCount);
                            break;
                        case FractureFormat.Quad:
                            gl.DrawArrays(OpenGL.GL_QUADS, 0, this.FractionVertexCount);
                            break;
                        default:
                            break;
                    }

                    gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
                }
                gl.BindVertexArray(0);
            }
        }
Esempio n. 14
0
        public void BindAll(OpenGL gl)
        {
            //return;
            UseProgram(gl, () =>
            {
                // Update uniforms.
                foreach (var action in ChangedUniforms)
                {
                    action.Invoke(gl);
                }
                ChangedUniforms.Clear();

                foreach (var group in BufferGroups)
                {
                    group.BindVAO(gl);

                    gl.LineWidth(group.LineWidth);

                    // Use draw elements if an index buffer is defined. Else use draw arrays.
                    if (group.IndicesCount > 0)
                        gl.DrawElements(OpenGL.GL_LINES, group.IndicesCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
                    else
                        gl.DrawArrays(OpenGL.GL_LINES, 0, group.VerticesCount);
                }
            });
        }
Esempio n. 15
0
        /// <summary>
        /// Renders the scene in retained mode.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        public void RenderRetainedMode(OpenGL gl)
        {
            //  Use the shader program.
            shaderPerPixel.Bind(gl);

            //  Set the light position.
            shaderPerPixel.SetUniform3(gl, "LightPosition", 0.25f, 0.25f, 10f);

            //  Set the matrices.
            shaderPerPixel.SetUniformMatrix4(gl, "Projection", projectionMatrix.to_array());
            shaderPerPixel.SetUniformMatrix4(gl, "Modelview", modelviewMatrix.to_array());
            shaderPerPixel.SetUniformMatrix3(gl, "NormalMatrix", normalMatrix.to_array());

            //  Go through each mesh and render the vertex buffer array.
            foreach(var mesh in meshes)
            {
                //  Set the variables for the shader program.
                shaderPerPixel.SetUniform3(gl, "DiffuseMaterial", mesh.material.Diffuse.r, mesh.material.Diffuse.g, mesh.material.Diffuse.b);
                shaderPerPixel.SetUniform3(gl, "AmbientMaterial", mesh.material.Ambient.r, mesh.material.Ambient.g, mesh.material.Ambient.b);
                shaderPerPixel.SetUniform3(gl, "SpecularMaterial", mesh.material.Specular.r, mesh.material.Specular.g, mesh.material.Specular.b);
                shaderPerPixel.SetUniform1(gl, "Shininess", mesh.material.Shininess);

                var vertexBufferArray = meshVertexBufferArrays[mesh];
                vertexBufferArray.Bind(gl);

                //  IMPORTANT: This is interesting. If you use OpenGL 2.1, you can use quads. If you move to 3.0 or onwards,
                //  you can only draw the triangle types - cause 3.0 onwards deprecates other types.
                //  see: http://stackoverflow.com/questions/8041361/simple-opengl-clarification
                //  this shows that the OpenGL mode selection works - if I choose 2.1 I can draw quads, otherwise I can't.
                //  There's a good article on tesselating quads to triangles here:
                //  http://prideout.net/blog/?p=49
                //  This should be a sample!

                uint mode = OpenGL.GL_TRIANGLES;
                if (mesh.indicesPerFace == 4)
                    mode = OpenGL.GL_QUADS;
                else if (mesh.indicesPerFace > 4)
                    mode = OpenGL.GL_POLYGON;

                gl.DrawArrays(mode, 0, mesh.vertices.Length);
            }

            //  Unbind the shader.
            shaderPerPixel.Unbind(gl);
        }
Esempio n. 16
0
 public override void Draw(OpenGL gl)
 {
   this.vertexBufferArray.Bind(gl);
   gl.DrawArrays(OpenGL.GL_LINES, 0, this.lineCount*2);
   this.vertexBufferArray.Unbind(gl);
 }
Esempio n. 17
0
 public override void Draw(OpenGL gl)
 {
   this.vertexBufferArray.Bind(gl);
   gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.cells.Count * 6); //cells.Count * 4);
   this.vertexBufferArray.Unbind(gl);
 }
Esempio n. 18
-29
 /// <summary>
 /// Function to draw the model
 /// </summary>
 private void drawModel(OpenGL gl) 
 {
     if(l_vboId != null)
     {
         gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
         // itering over each list of points
         for(int k = 0; k < l_vboId.Count; k++)
         {
             gl.PushMatrix();
                 //transformations
                 gl.Scale(1.0f / f_scale, 1.0f / f_scale, 1.0f / f_scale);
                 gl.Translate(-v_center.X, -v_center.Y, -v_center.Z);
                 //vertexes
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][0]);
                 gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //color
                 gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][1]);
                 gl.ColorPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
                 //draw l_sizes[k] points
                 gl.DrawArrays(OpenGL.GL_POINTS, 0, l_sizes[k]);
             gl.PopMatrix();
         }
         gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
         gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
         gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
     }
 }