Sign in to follow this  
digitalerr0r

Need help with GLU NURBs / array

Recommended Posts

digitalerr0r    122
Hello, I have a problem rendering NURBs using the NURB functionality in GLU. If I define a control point array like this GLfloat cp[4][4][3] = {..}; and render like this, it works fine:
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb, 
             8, knots,
             8, knots,
             (maxDim+1) * 3,
             3,
             &cp[0][0][0], 
	     sizeGrideX, sizeGrideY,
             GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
My issue is that I'm creating a NURBs editor, and want to be able to dynamically allocate this array of controlpoints so I can add or edit control points. I got a vector with all controlpoints that I convert to fill the cp[][][] array. But if I define the array like this: #define MAX_CP 100 GLfloat cp[MAX_CP][MAX_CP][3] = { same data as in the first example }; then It wont render correctly. The only difference is that I set the array to be larger than what it's really using. It seems that the GLU NURB function uses the whole array. Is it a way to specify its range so it will f.eks only use the 4 first elements in the array? I can also dynamicaly create the array, but it's still not showing correctly:
cpN = (GLfloat ***)malloc(sizeof(GLfloat **) * maxDim);
for(int i = 0; i < 4; i++)
{
	cpN[i] = (GLfloat **)malloc(sizeof(GLfloat*) * mP);
	for(int j = 0; j < 4; j++)
	{
		cpN[i][j] = (GLfloat *)malloc(sizeof(GLfloat) * 3);
		for(int k = 0; k < 3; k++)
		{
			cpN[i][j][k] = ctrlptsNURB[i][j][k];
		}
	}
}

gluBeginSurface(theNurb);
gluNurbsSurface(theNurb, 
             8, knots,
             8, knots,
             (maxDim+1) * 3,
             3,
             &cpN[0][0][0], 
	     sizeGrideX, sizeGrideY,
             GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
and then use cpN when rendering the NURB. Do I have any mistakes in how I convert the array to a 3D array? Is it any other ways to do this? Best regards, digitalerr0r

Share this post


Link to post
Share on other sites
digitalerr0r    122
Is it possible to specify the range on how many elements the array will use? Or does it automatically use the whole array when setting a pointer to the array( 3D array ) I would like to use as controllpoints?

Solved this by converting everything into one long 1D array and using it in the NURB renderer, in case anyone else are on this issue.

[Edited by - digitalerr0r on August 18, 2008 4:11:08 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this