Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: glVertexPointer in Tao  (Read 3483 times)

0 Members and 1 Guest are viewing this topic.

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
glVertexPointer in Tao
« on: August 24, 2011, 09:55:14 pm »
I'm trying to use glVertexPointer function from Tao framework without much luck. Following sample draws nothing (commented out lines do draw triangle).

Initialization code:
Code: [Select]
float[] coord = new float[16];
float[] color = new float[16];
// all white
for (int i = 0; i < 16; i++)
    color[i] = 1;

// triangle
coord[0] = 0.5f;
coord[1] = 1;
coord[2] = 0;
coord[3] = 0;
coord[4] = 0;
coord[5] = 0;
coord[6] = 1;
coord[7] = 0;
coord[8] = 0;

Gl.glClearColor(1f, 0f, 0f, 1f);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glOrtho(0, 1, 0, 1, -1, 1);


and then in render loop

Code: [Select]
Gl.glColor3f(0, 1, 0);
// this works
//Gl.glBegin(Gl.GL_TRIANGLES);
//Gl.glVertex3f(0.5f, 1f, 0); Gl.glVertex3f(0, 0, 0); Gl.glVertex3f(1f, 0, 0);
//Gl.glEnd();
               
// this doesn't
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glEnableClientState(Gl.GL_COLOR_ARRAY);
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, coord[0]);
Gl.glColorPointer(3, Gl.GL_FLOAT, 0, color[0]);

Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 3);
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glDisableClientState(Gl.GL_COLOR_ARRAY);


Both arrays have 3 elements per vertex, 0 stride (tightly packed). Debugger shows correct values in memory. I guess it's some glitch in Tao or between managed and unmanaged code... Any advice would be appreciated.

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
glVertexPointer in Tao
« Reply #1 on: August 24, 2011, 10:30:37 pm »
This seems to be a bug in Tao binding: glVertexPointer that takes object as the last parameter incorrectly computes pointer to data. The fix is to use IntPtr version (unsafe code necessary...):
Code: [Select]
fixed (float* ptr1 = &coord[0])
    Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, (IntPtr)ptr1);

 

anything