Hello!
I tried to display some data just like a plot or spectra data.
I thought pixel reuse is unimportant here so I choosed glDrawArrays. But all I get is one pixel at (0,0,0).
As you can probably see I use a .NET base class I found at Nehe to display some OpenGL from within .NET. This works quite well. To be sure that I set up all the initialisation correct I added the 5 lines at the end.
I see the two pixels just as I wanted. The commands at the top only draw 1 pixel at (0,0,0). They do that with the right color (green) but always at the center of my coordinates (0,0,0) - no matter what values data2 contains.
That’s a little bit frustrating. I am not sure if this has something to do with the object array I need for the Nehe implementation of glDrawArrays. Maybe someone else tried this…?
The problem may be that .NET uses managed memory approach, meaning that objects can be freely moved around in the memory. Your data2 variable is converted to a pointer, but this pointer may be not valid some moments later (it also may be that the variable is deleted automatically). You should pin the object address using the GCHandle class (there are examples in MSDN library)
Is the data (object) a float array (or equivalent)? You’re saying that the data are floats (GL_FLOAT) but using sizeof(double), which suggests the data is double?
Still, I would advice you to declare pointer as IntPtr and use GCHandle to pin the object. In a more complex application, you will loose the data very soon.
I will take a look at it. But normally I wouldn’t guess any problems as the rendering routine is a method of my OpenGL component (class). As long as this instance is alive I would not think that any member of it would be a victim of the garbage collector, right?
…
Hmm… but maybe it would be pushed to another adress. Is this what you mean? That would be really bad
Ok, I think I really have to look at this GCHandle stuff.
Thanks.
Originally posted by Frostie:
[b]I should have tried that earlier: I changed the declaration in the Nehe file from an object array to a simple double array :
[DllImport(GL_DLL,EntryPoint =“glVertexPointer”)]
public static extern void glVertexPointer(int size, uint type, int stride, double pointer);[/b]
something seems to be wrong there. glVertexPointer should use a const GLvoid * pointer, not a double pointer.
the type of data in the array is defined by passing GL_FLOAT, GL_DOUBLE, GL_INT or GL_SHORT to glVertexPointer.
It is all about how .NET transforms the data for native calls. Type ‘object’ will be most probably passed as pointer, thus ‘object[]’ will be array of pointers. Declaration like ‘double[]’ will work, because double is a struct type and not an object, hence resulting in a pointer to array of doubles. The best declaration would be ‘IntPtr’ or ‘object’. Actually, if using .NET, it makes much sense to use VBOs.
P.S. object[] data2=new object[] { 0.5, 0.5, 0.0 } will create array of doubles and not floats.
are just vertex arrays which reside permanently in the graphics card memory. they are not transferred via the bus each frame, which results in better performance.