Results 1 to 7 of 7

Thread: opengl bezier surface

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question opengl bezier surface

    Im trying to make a bezier surface. I read points from a file and then use and evaluator to print the surface. I have read some samples (red book or blue book and some links - all use the same sample) that works fine if the points definition is into the main program. But if i want to programm a class with this phylosopy, dont work:

    Qt Code:
    1. class GLWidget : public QGLWidget
    2. {
    3. ...
    4.  
    5. private:
    6. GLuint makeSurf(const GLfloat *reflectance, GLfloat ***points);
    7. GLfloat ***ctrlpoints;
    8. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. GLWidget::GLWidget(QWidget *parent)
    2. : QGLWidget(parent)
    3. {
    4. ...
    5. //ctrlpoints = new (GLfloat **);
    6. GLfloat ctrlpoints[4][4][3]= <- this crash
    7. {
    8. {
    9. {-1.5, -1.5, 4.0},
    10. {-0.5, -1.5, 2.0},
    11. {0.5, -1.5, -1.0},
    12. {1.5, -1.5, 2.0}},
    13. {
    14. {-1.5, -0.5, 1.0},
    15. {-0.5, -0.5, 3.0},
    16. {0.5, -0.5, 0.0},
    17. {1.5, -0.5, -1.0}},
    18. {
    19. {-1.5, 0.5, 4.0},
    20. {-0.5, 0.5, 0.0},
    21. {0.5, 0.5, 3.0},
    22. {1.5, 0.5, 4.0}},
    23. {
    24. {-1.5, 1.5, -2.0},
    25. {-0.5, 1.5, -2.0},
    26. {0.5, 1.5, 0.0},
    27. {1.5, 1.5, -1.0}}
    28. };
    29. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GLWidget::initializeGL()
    2. {
    3. ....
    4. surf1=makeSurf(reflectance3,&ctrlpoints[0][0][0]); <- this crash too
    5. ....
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. GLuint GLWidget::makeSurf(const GLfloat *reflectance, GLfloat ***points)
    2. {
    3. ...
    4. glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &points[0][0][0]);
    5. ...
    To copy to clipboard, switch view to plain text mode 

    The problem is how to define a pointer dinamically with 3 indexes (¿[][][]->***?) in a class...
    I hope you understand me.
    Some help please

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: opengl bezier surface

    I think what you want to do is create the array like this:

    Qt Code:
    1. int ***array;
    2.  
    3. array = (int***) malloc( sizeof( int** ) * X_SIZE );
    4. for( int i = 0 ; i < X_SIZE ; i++ )
    5. {
    6. array[i] = (int**) malloc( sizeof( int* ) * Y_SIZE );
    7.  
    8. for( int j = 0 ; j < Y_SIZE ; j++ )
    9. {
    10. array[i][j] = (int*) malloc( sizeof( int ) * Z_SIZE );
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    This should create your 3-D array in whatever sizes you need assuming the array is:
    Qt Code:
    1. array[X_SIZE][Y_SIZE][Z_SIZE]
    To copy to clipboard, switch view to plain text mode 

    Hope this helps!

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: opengl bezier surface

    Remember that you can always emulate a multidimensional array using a single dimensional array just by manipulating indexes.

    First Z_SIZE indexes will contain values for x=0 && y=0, next Z_SIZE indexes will contain values for x=0 && y=1 and so on...

    First Z_SIZE*Y_SIZE indexes will contain values for x=0, next will contain values for x=1 and so on...

  4. #4
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: opengl bezier surface

    Additionally, use new instead of malloc.
    "If you lie to the compiler, it will get its revenge." - Henry Spencer

  5. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: opengl bezier surface

    Additionally, use new instead of malloc.
    The big thing is to use new with delete or malloc with free. As long as you use one pair you should be fine. What makes new better than malloc besides it is C++ where malloc is more of a C function? I always use new for Qt objects and malloc when dynamically creating arrays.

    If you use the 3-dimensional array make sure to free/delete every pointer and not just the overlying pointer.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: opengl bezier surface

    Quote Originally Posted by ToddAtWSU View Post
    What makes new better than malloc besides it is C++ where malloc is more of a C function?
    The main difference is that new operator invokes objects' constructors, while malloc() doesn't (same for free() vs. delete).

    Also it can throw an exception when allocation fails and you don't need any sizeofs or casts, so the code is cleaner.

  7. The following user says thank you to jacek for this useful post:

    ToddAtWSU (22nd February 2007)

  8. #7
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Talking Re: opengl bezier surface

    Quote Originally Posted by jacek View Post
    The main difference is that new operator invokes objects' constructors, while malloc() doesn't (same for free() vs. delete).

    Also it can throw an exception when allocation fails and you don't need any sizeofs or casts, so the code is cleaner.
    I always wondered what the difference was but never had an opportunity to look it up when I was thinking about it. Thanks!

Similar Threads

  1. Does OpenGL be supported in opensource of Qt-4.1.2?
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 10:46
  2. OpenGl 2d
    By Lele in forum Qt Programming
    Replies: 10
    Last Post: 9th May 2006, 21:37
  3. help on openGL context
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2006, 19:21
  4. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.