0

C++ Code using OpenGL:

vector<RGB> LUT;  //creating a vector3 array
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, 16, 16, 16, 0, GL_RGB,GL_FLOAT, &LUT[0]);

The above C++ code is working fine. &LUT[0] is accepted as it is of type const GLvoid * data

C# Code using SharpGL:

Vector3[] vec3 = new Vector3[2]; //creating a vector3 array
gl.TexImage3D(GL_TEXTURE_3D, 0, GL_RGB, 16, 16, 16, 0, GL_RGB,GL_FLOAT, &LUT[0]);

My problem is, in SharpGL &LUT[0] is not accepting, stating the message that it accepts only IntPtr types. Is there anyway I can resolve this issue?

vallentin
  • 23,478
  • 6
  • 59
  • 81
cona mx
  • 55
  • 6

1 Answers1

0

You can pack float[] into an IntPtr.

float[] data = {
    ...
};
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr dataPtr = handle.AddrOfPinnedObject();
var size = Marshal.SizeOf(typeof(float)) * data.Length;

Remember to free it after having called gl.TexImage3D().

handle.Free();
vallentin
  • 23,478
  • 6
  • 59
  • 81
  • @conamx did you get around to testing it? Did it work? – vallentin Apr 11 '17 at 22:12
  • First of all, thank you. Yes, following your instructions, I was able to initialize **gl.TexImage3D()** function. Program was compiled successfully. However, I'm getting the error **FatalExecutionEngineError** when I run the program. I'm sure this is something to do with SharpGL library so this time I'm trying openTK library – cona mx Apr 17 '17 at 17:04