PDA

View Full Version : Using VBOs



Cinderella
05-28-2010, 10:33 PM
Hallo,

I hope that somebody can help me with my problem. I read and searched for information several days about VBOs but meanwhile I'm totally confused.

I want to show measured data with OpenGL with the help of VBOs.
The data point consists of one X value and one Y value and I have 50000 points.

I created an double array which is in format:

double[] data = new double[] {x0,y0,x1,y1,...,x49999,y49999}

//Create Buffer works
int[] buffers = new int[1];
Gl.glGenBuffers(buffers.Length, buffers);

//Bind Buffer works
Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, buffers[0]);
Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(data.Length * sizeof(double)), data, Gl.GL_STATIC_DRAW);

//Nothing works from here - please help with this
Gl.glVertexPointer(2, Gl.GL_DOUBLE, 0, 0);
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glDrawArrays(Gl.GL_LINE_STRIP, 0, 50000);

//Cleaning everything
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, 0);

I searched and googled and found a lot but I am confused and totally lost. Can smoeone put me on the right way again?

Thanks.

Dave

Cinderella
05-29-2010, 12:23 AM
Maybe writing in this forum helped me to solve my problem. Here are the code fragments that worked for me. On of my problem was probably C#/Tao framework.

int[] buffers = new int[1];
Gl.glGenBuffers(buffers.Length, buffers);

Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, bufferName);
Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(data.Length * sizeof(double)), data, Gl.GL_STATIC_DRAW);

//Most important is the last parameter
//0 is not IntPtr.Zero !!!
Gl.glVertexPointer(2, Gl.GL_DOUBLE, 0, IntPtr.Zero);
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);

Gl.glDrawArrays(Gl.GL_LINES, 0, data.Length/2);

Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, 0);

That's it.

Dave

aqnuep
05-29-2010, 03:45 AM
I would suggest you not to use double floats, but single ones as, except the latest generation of GPUs, it is not supported in hardware.