Results 1 to 14 of 14

Thread: Curve editor

  1. #1
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299

    Curve editor

    I was wondering if someone has coded a simple curve (X/Y) editor to be used in a LWPanel.
    Probably based on an OPENGLCTL.

    this is what I need:
    - Add/Remove controlpoints.
    - Drag control points
    - Zoom/Pan

    I could write my own but don't have a lot of time.

    creacon

  2. #2
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    Hi again,

    started making one myself.
    One problem I am having is that the OPENGL control doesn't seem to support double buffering, so there is a lot of redrawing/tearing and flickering visible.
    Lightwave crashes when I try to swap the buffers.

    I suppose that it is the same problem with Lightwave's own graph editor? Resizing the window produces the same mess?

    creacon

  3. #3
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,884
    Last edited by Sensei; 04-25-2017 at 09:08 AM.

  4. #4
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    I need to do this in the Callback for an OPENGL_CTL (LW_Panels).
    What you're saying is draw in the buffer first and "blit" in in one go to the control, correct?

    creacon

  5. #5
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,884
    Quote Originally Posted by creacon View Post
    I need to do this in the Callback for an OPENGL_CTL (LW_Panels).
    Yes, I know how to program this control, used it in my TrueArt Previewer/Renderer this way exactly.

    Quote Originally Posted by creacon View Post
    What you're saying is draw in the buffer first and "blit" in in one go to the control, correct?
    Exactly.
    You won't have flickering at least.

  6. #6
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    Another question,

    If I call OpenGL commands in the control's event callback, my curve is drawn.
    If I copy the exact same code to the control's draw callback, I just get a black rectangle.

    Which one of these are you using?

    creacon

  7. #7
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,884
    Code:
    // init
    
       m_Control_OpenGL = OPENGL_CTL( m_PanelFuncs, m_PanelID, NULL, 640, 480 );
       if( m_Control_OpenGL != NULL )
       {
        CON_SETEVENT( m_Control_OpenGL, UserDrawFunc_Forward, (void *) this );
       }
    
    // userdraw (after forwarding)
    
    
    void CLWPreviewWindow::UserDraw(
     DrMode dr_mode )
    {
     if( dr_mode != DR_ERASE )
     {
      if( m_Control_OpenGL != NULL )
      {
       LWValue ival = { LWT_INTEGER };
       int width = CON_W( m_Control_OpenGL );
       int height = CON_H( m_Control_OpenGL );
    
       if( ( width != GetWidth() ) ||
           ( height != GetHeight() ) )
       {
        Resize( width, height );
       }
    
       void *buffer;
       buffer = GetBuffer();
       if( buffer != NULL )
       {
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
    
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
    
        glMatrixMode( GL_TEXTURE );
        glLoadIdentity();
    
        GLdouble pos[ 3 ];
        pos[ 0 ] = -1.0;
        pos[ 1 ] = -1.0;
        pos[ 2 ] = 0.0;
        glRasterPos3dv( pos );
    
    #if 0
        glDrawPixels( GetWidth(), GetHeight(), GL_RGBA, GL_FLOAT, buffer );
    #elif 1
        float *src_buffer = (float *) buffer;
        int buffer_width = GetWidth();
        int buffer_height = GetHeight();
    
        unsigned char *temp_buffer;
        temp_buffer = new unsigned char[ buffer_width * buffer_height * 4 ];
        if( temp_buffer != NULL )
        {
         int offset = 0;
         for( int j = 0; j < buffer_height; j++ )
         {
          for( int i = 0; i < buffer_width; i++ )
          {
           temp_buffer[ offset + 0 ] = iclamp( (int) ( src_buffer[ offset + 0 ] * 255.0 ), 0, 255 );
           temp_buffer[ offset + 1 ] = iclamp( (int) ( src_buffer[ offset + 1 ] * 255.0 ), 0, 255 );
           temp_buffer[ offset + 2 ] = iclamp( (int) ( src_buffer[ offset + 2 ] * 255.0 ), 0, 255 );
           temp_buffer[ offset + 3 ] = iclamp( (int) ( src_buffer[ offset + 3 ] * 255.0 ), 0, 255 );
           offset += 4;
          }
         }
         glDrawPixels( buffer_width, buffer_height, GL_RGBA, GL_UNSIGNED_BYTE, temp_buffer );
         delete [] temp_buffer;
        }
    #endif
    
        glFlush();
       }
      }
     }
    }
    It has been 8 years or so after I wrote it, but if I recall correctly GL_FLOAT was slow or had other issue,
    therefor I changed code to below one, and each time there was refresh, converted manually floats to unsigned bytes.
    Not noticeable difference in speed, or even faster than OpenGL by itself doing this conversion.

    But it was working on LW v9.6.

  8. #8
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    You're using:
    CON_SETEVENT( m_Control_OpenGL, UserDrawFunc_Forward, (void *) this );

    that works for me too, but according to the docs CON_SETDRAW should work and allow me to execute OpenGl commands.
    The Callback is triggered but it doesn't execute OpenGL commands.

    This is what the docs say:
    You can draw in this window using standard OpenGL function calls during your event and draw callbacks for the control.

    creacon

  9. #9
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,884
    For me this method works, because I have timer, which is periodically executed 10 times per second or so, and it's calling panel redraw function.

    It's plausible that I noticed what you're noticing, therefor switched to event call-back.

    What if you have draw and event callbacks empty? Is it still black? Or black is result of glDrawPixels() ?
    Are you using OpenGL initialization as I do prior glDrawPixels() ? glFlush() after?
    Last edited by Sensei; 04-25-2017 at 04:07 PM.

  10. #10
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    Need to check tonight. Also noticed that LW's own graph editor only has the problem while resizing the window, not for the regular redraw (like adding or dragging keys).

    creacon

    Quote Originally Posted by Sensei View Post
    For me this method works, because I have timer, which is periodically executed 10 times per second or so, and it's calling panel redraw function.

    It's plausible that I noticed what you're noticing, therefor switched to event call-back.

    What if you have draw and event callbacks empty? Is it still black? Or black is result of glDrawPixels() ?
    Are you using OpenGL initialization as I do prior glDrawPixels() ? glFlush() after?

  11. #11
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    Oh boy, there IS a curve editor in LW!
    Any chance of having this exposed in the SDK, before I have to reinvent the wheel?

    creacon

    Click image for larger version. 

Name:	Curve.jpg 
Views:	148 
Size:	50.4 KB 
ID:	136642

  12. #12
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,884
    Make custom Node Editor...

  13. #13
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    The thing is that I want to use a curve editor to map the density of the particles in a particle buffer to particle size.
    So even if I put this in a custom node editor I still wouldn't be able to use the LW Curve node.

    Quote Originally Posted by Sensei View Post
    Make custom Node Editor...

  14. #14
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,299
    In the meantime I started reinventing the wheel anyway, what can you do if LW3DG developers only visit this subforum twice a year ;-)
    I have the basic functionality (adding, deleting, moving) working and wanted to check against the built in graph editors (THE graph editor and the curve editor node).

    And this is where it gets funny to the point where it gets sad...
    Both editors use an underlying VParm, that's the good part, but:

    Graph editor: when you mouse over a keyframe there is an infobox in overlay that appears.
    Curve editor:when you mouse over a keyframe it gets highlighted, same goes for the controlpoints

    Graph editor:keyframe editing is restricted to horizontal or vertical
    Curve editor:keyframe editing is unrestriced
    Graph editor: Line antialiasing
    Curve editor: Line antialiasing + "high quality line" options

    Graph editor: detailed grid
    Curve editor: Rough grid

    Graph editor: you're in add mode or in move mode
    Curve editor: you're in add mode when you're not in move mode

    And so on….

    So far, pretty funny that they have made 2 different curve editors, while one curve editor should just be a variation of the other. Could be that the curve editor was developed by a third party without access to the LW codebase, but anyway. As a consequence this also means that the tweaks that Matt did to the colors in the graph editor weren't done for the curve editor, etc.

    All this is a waste, but now the part where it isn't funny anymore:

    Graph editor: 1 undo
    Curve editor: unlimited undo (or at least a lot for as far as I tested)

    Users have been asking for unlimited undos for ages, and then this?

    Seriously?

    creacon

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
  •