Results 1 to 4 of 4

Thread: C++ Vectors problem in GLU NURBS interface??

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Hyderabad, India
    Posts
    3

    C++ Vectors problem in GLU NURBS interface??

    Hi,
    I am trying to write a program to interactively model and manipulate the NURBS surfaces. For this i am using the GLU NURBS interface. The interface requires control points to be given in a 3D array. But in order to extend the surface dynamically i need to change the no. of control points during execution.

    But the command is not excepting dynamically allocated arrays, ( with new or malloc). It does not even take in C++ vector class variables.

    Does anybody know a way to work around this problem?

    Thank you,
    pramod.
    -- pramod

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

    Re: C++ Vectors problem in GLU NURBS interface??

    Post some code. You are probably using the gluNurbs methods wrong as they should have no knowledge of whether they are statically allocated or dynamically allocated arrays.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Hyderabad, India
    Posts
    3

    Re: C++ Vectors problem in GLU NURBS interface??

    I initialized NURBS object using

    code:
    --------------------------------------
    theNurb = gluNewNurbsRenderer();
    gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 50.0);
    gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
    --------------------------------------

    Then i called the drawing function,

    -----------------------------------
    gluBeginSurface(theNurb);

    gluNurbsSurface(theNurb,
    8, &UKnots[0],8,&VKnots[0],
    UKnots.size() - Degree - 1) * 4,4,
    &ControlPoints[0][0][0],
    4, 4,GL_MAP2_VERTEX_4);

    gluEndSurface(theNurb);
    -----------------------------------

    This drawing function is working only when the ControlPoints array is statically allocated to the exact no. of control points. It does not seem to be working when i dynamically allocate the array and then fill it with data. I could not understand why ? Same is the case with the use of C++ vectors.

    Thank you.
    -- pramod

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

    Re: C++ Vectors problem in GLU NURBS interface??

    Ok. I notice you have a 3 dimensional array. Am I correct in assuming you are probably doing something like so when trying to allocate it dynamically?

    Code :
    float ***ControlPoints;
     
    ControlPoints = new float**[size];
     
    for (x=0;x<size;x++)
    {
        ControlPoints[x] = new float*[size2];
        for (y=0;y<size2;y++)
        {
             ControlPoints[x][y] = news float[size3];
        }
    }
    If that's the case, you are NOT setting memory correctly. What you need is one contiguous range of memory. When you setup a static multi-dimensional array, it will make the memory contiguous for you.

    Doing it like above however, starting at the location pointed to by ControlPoints, you are actually pointing at a pointer which points to another pointer, which points to one row of data. See why that won't work, yet?

    You should be allocating your memory like so.

    float *ControlPoints = new float[size1*size2*size3];

    One other thing. Not a major thing, but I thought I'd mention it.

    Using &UKnots[0] is identical to just using UKnots. Arrays are always represented as a pointer to the first element when you don't dereference a specific element. Just thought I'd mention it as I tend to find just UKnots more readable.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. Problem with keyboard interface - freeglut
    By thor36 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-06-2014, 08:41 PM
  2. Problem with materials, normal vectors ?
    By Whilibarj in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-29-2004, 05:58 PM
  3. Problem with materials, normal vectors ?
    By Whilibarj in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-29-2004, 09:43 AM
  4. 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
  5. Using Vectors with GLU NURBS interface
    By pramod_49 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-11-2002, 08:46 AM

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