problem with vbo!

Apr 17, 2014 at 1:33 PM
i wanna use gl.drawelemnts with vbo. but is no thing is drawn!
my code:
private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            
            OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);  
            gl.LoadIdentity();                  // Reset The View
            gl.LookAt(4, 0, 1, 0, 0, 0, 0, 1, 0);
           // gl.Color(1.0f, 1.0f, 1.0f);
           // gl.FontBitmaps.DrawText(gl, 0, 0, "Arial", "Argh");
            float[] vertex ={ 0.0f, 1.0f, 0.0f,
                            -1.0f, -1.0f, 1.0f,
                            1.0f, -1.0f, 1.0f,
                            1.0f,1.0f,1.0f,
                            0.0f, 1.0f, 0.0f,
                            1.0f, -1.0f, -1.0f
                            };
            uint[] indices = { 
                0, 1, 2, // left bottom triangle
                2, 3, 0, // left top triangle
            };
            // used for storing the id of the vbo
            uint[] vertexBufferObjectIds = new uint[2];
            gl.GenBuffers(2, vertexBufferObjectIds);
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBufferObjectIds[0]);
            gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertex, OpenGL.GL_STATIC_DRAW);

            //IntPtr pointer = GCHandle.Alloc(indices, GCHandleType.Pinned).AddrOfPinnedObject();
            //gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, vertexBufferObjectIds[1]);
            //gl.BufferData(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indices.Length * sizeof(uint), pointer, OpenGL.GL_STATIC_DRAW);

            //gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBufferObjectIds[0]);

            gl.EnableVertexAttribArray(0);    //We like submitting vertices on stream 0 for no special reason
            gl.VertexAttribPointer(0,4,OpenGL.GL_FLOAT,false,vertex.Length*sizeof(float),IntPtr.Zero);
            gl.Color(0.0f, 1.0f, 0.0f, 1.0f);
            //gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, vertexBufferObjectIds[1]);
            //gl.Color(0.0f, 1.0f, 0.0f,1.0f);
            //gl.DrawElements(OpenGL.GL_TRIANGLES, indices.Length, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
            gl.DrawElements(OpenGL.GL_LINES, indices.Length, indices);
gl.flush();
}
but this code is work:
private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e)
        {
            rtri += 3.0f;// 0.2f;                       // Increase The Rotation Variable For The Triangle 
            
            OpenGL gl = this.openGLControl1.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);  // Clear The Screen And The Depth Buffer
            gl.LoadIdentity();                  // Reset The View
            gl.LookAt(4, 0, 1, 0, 0, 0, 0, 1, 0);
           
           
            gl.Color(0.0f, 1.0f, 0.0f, 1.0f);
           
           
            gl.Begin(OpenGL.GL_TRIANGLES);                  // Start Drawing The Pyramid
            
            gl.Vertex(0.0f, 1.0f, 0.0f);            // Top Of Triangle (Front)
            
            gl.Vertex(-1.0f, -1.0f, 1.0f);          // Left Of Triangle (Front)
            
            gl.Vertex(1.0f, -1.0f, 1.0f);           // Right Of Triangle (Front)

            
            gl.Vertex(0.0f, 1.0f, 0.0f);            // Top Of Triangle (Right)
            
            gl.Vertex(1.0f, -1.0f, 1.0f);           // Left Of Triangle (Right)
            
            gl.Vertex(1.0f, -1.0f, -1.0f);
            gl.End();
            gl.Flush();
}
Coordinator
Apr 24, 2014 at 9:27 AM
As a test you could try using the VertexBuffer object from the SharpGL library which wraps a lot of this functionality for you - there's an example in the CelShadingSample