View Single Post
Old 05-07-2006, 01:49 AM   #1 (permalink)
nesvarbu
Registered User
 
Join Date: Aug 2004
Posts: 6
nesvarbu is on a distinguished road
creating 3-dimensional array

I need to create a 3-dimensional array points[n][m][l] in c++. This array is used in OpenGL function to draw nurbs:

gluNurbsSurface( GLUnurbsObj *nurb, GLint uKnotCount, GLfloat *uKnot,
GLint vKnotCount, GLfloat *vKnot, GLint uStride,
GLint vStride, GLfloat *points, GLint uOrder,
GLint vOrder, GLenum type );

Ok I tried several ways to create an array:
1. I just used GLfloat points[7][5][4], I it would be ok, BUT I can't use constants, the size of array depends on other variables, so I tried another way:
2.
Code:
      
GLfloat ***points;

points = new GLfloat**[UKnotCount - UOrder];
for (int i = 0; i < UKnotCount - UOrder; i++)
{
  points[i] = new GLfloat*[VKnotCount - VOrder];
  for (int j = 0; j < VKnotCount - VOrder; j++)
  {
    points[i][j] = new GLfloat[4];
  }
}
Everything would be OK , BUT when I use this array in OpenGL function

Code:
      
gluNurbsSurface( nurbSurface, VKnotCount, VKnots, UKnotCount, UKnots,
              7*4, 4, &points[0][0][0],VOrder,UOrder, GL_MAP2_VERTEX_4 );
It throws an error: "Invalid floating point operation". So I guess this type of array doesn't suit OpenGL function. I don't have much of knowledge in pointers and addresses, so maybe I'm using the pointers incorrect? Or maybe there's another way to create a 3-dimensional array? Any help would be appretiated.
nesvarbu is offline   Reply With Quote