Results 1 to 2 of 2

Thread: Nurbs Surface in OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    10

    Nurbs Surface in OpenGL

    I have a program that receives from the user control points of two B-Spline curves (de Boor points) and draws the surface with these curves as edges, connecting in a straight line between each two control points in different curves (ruled surface).
    My problem is the gluNurbsSurface method doesn't work correctly when the control points array is dynamically allocated (two or three dimentions array), where it works correctly when it is statically allocated. i didn't find how to operate it right.

    I would be grateful for any help anyone can give me with this.
    Thanks

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Nurbs Surface in OpenGL

    The memory needs to be contiguous and it's not for dynamically-allocated, multi-dimensional arrays.

    Consider this for example.

    Code :
    float **ppValues = new float*[someValue];
     
    for (int c=0;c<someValue;c++)
    {
       ppValues[c] = new float[someOtherValue];
    }
    At this point you now have an array of pointers. ppValues itself doesn't point to any of your values. It points to a list of memory addresses. Each of those memory addresses points to a separate set of values. There is no guarantee that the memory allocated for any of the given float arrays directly follows the previously allocated float array.

    To do this right, you should allocate the memory as a single large float array.

    Code :
    float *pValues = new float[someValue * someOtherValue];
    Now, to calculate the indices you just use a formula like so...

    Code :
    index = y * width + x;
    You can also use other tricks like so...

    Code :
    float *pValues;
    float **ppValues;
     
    pValues = new float[width * height];
     
    for (int y=0;y<height;y++)
    {
        ppValues = &amp;pValues[y*width];
    }

    If you are using a multidimensional array for something like an array of x,y,z coordinates you can also do something like so...

    Code :
    struct Vector3
    {
       float x, y, z;
    }
     
    Vector3 *pValues = new Vector3[someValue];
    Hope that helps.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. NURBS surface using OpenGL and glut
    By hadichko in forum OpenGL: Windows
    Replies: 0
    Last Post: 08-16-2017, 07:34 AM
  2. about NURBS surface
    By Mary in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 03-09-2004, 04:27 PM
  3. Last one on nurbs... sweeping a nurbs curve to draw a nurbs surface?
    By BigShooter in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-04-2003, 09:54 AM
  4. Nurbs Surface in OpenGL
    By snupinokio in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 07-17-2003, 11:57 PM
  5. animating a NURBS surface
    By dnstapes in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-21-2000, 02:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean