0

Im trying to use FBO/VBO in OpenGL with SharpGL. Using for this WPF app. The problem is, example triangle dont render.

Adding component is with this code:

glControl = new OpenGLControl();
glControl.RenderContextType = RenderContextType.FBO;
glControl.DrawFPS = true;
glControl.OpenGLDraw += OpenGLControl_OnOpenGLDrawNew;

And code for render and init:

private void OpenGLControl_OnOpenGLDrawNew(object sender, OpenGLEventArgs args)
{
OpenGL gl = args.OpenGL;
ShaderProgram shaderProgram = new ShaderProgram();

uint[] id = new uint[1];

gl.GenVertexArrays(1, id);
gl.BindVertexArray(id[0]);

gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();

float[] vertex_data = new[]
{
    -1.0f, -1.0f, 0.0f,
    1.0f, -1.0f, 0.0f,
    0.0f, 1.0f, 0.0f,
};

uint[] vertexBuffer = new uint[1];
gl.GenBuffers(1, vertexBuffer);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer[0]);
IntPtr ptr1 = GCHandle.Alloc(vertex_data, GCHandleType.Pinned).AddrOfPinnedObject();
gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertex_data.Length * sizeof(float), ptr1, OpenGL.GL_STATIC_DRAW);


// loop? when its in do{} while(true) loop, program stop respond
gl.EnableVertexAttribArray(0);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer[0]);
gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, 0, new IntPtr());
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
gl.DisableVertexAttribArray(0);
}

And I'm not sure what wrong im doing? Appear only black window with stats of FPS and draw time. Pls dont send C++/C tuts becouse already try it (lots of it) and its a little different in this in C#. Was trying follow this tut: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-2-the-first-triangle/

Rhonin
  • 474
  • 4
  • 20

1 Answers1

0

SharpGL (at least on my setup) does not support VBO's on the GPU. I would try enclosing the statements in try{} catch{}, and you should get an exception with a message to this effect. SharpGL does support non-gpu side DrawArrays (VertexPointer()).