Results 1 to 2 of 2

Thread: What's wrong with this code?

  1. #1

    What's wrong with this code?

    Hi there.

    I've tried to use the linear gradients with the reference implementation, but somehow I don't get them working.

    The strange thing is: As soon as I comment out the vgSetParameterfv (paint, VG_PAINT_COLOR_RAMP_STOPS call I have valid results using the default ramp, but if I try to define my own I either get completely wrong output or nothing at all (depends on the spread mode).


    Could someone please have a look? (code assumes no mask/scissoring or other things modified from the context creation defaults)


    Code :
    void gradient_test (void)
    {
      VGfloat color[4] = 
      { 
        1,1,1,1 // opaque white
      };
     
      VGfloat stops[10] = 
      {
        0, 1, 0, 0, 0, // opaque red at start
        1, 1, 1, 1, 1, // opaque white at end
      };
     
     
      VGfloat gradient[4] =  
      { 
        100, 100, 200, 200, 
      };
     
      VGImage img = vgCreateImage (VG_sL_8, 256, 256, VG_IMAGE_QUALITY_NONANTIALIASED);
      vgSetfv (VG_CLEAR_COLOR, 4, color);
      vgClearImage (img, 0,0,256,256);
     
      VGPaint paint = vgCreatePaint();
      vgSetPaint        (paint, VG_FILL_PATH);
      vgSetParameteri   (paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
      vgSetParameteri   (paint, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_REPEAT);
      vgSetParameterfv  (paint, VG_PAINT_COLOR_RAMP_STOPS, 10, stops);
      vgSetParameterfv  (paint, VG_PAINT_LINEAR_GRADIENT,  4, gradient);
     
      vgSeti (VG_BLEND_MODE,  VG_BLEND_SRC_OVER);
      vgSeti (VG_IMAGE_MODE,  VG_DRAW_IMAGE_MULTIPLY);
     
      vgSeti (VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
      vgLoadIdentity();
      vgTranslate    (10,10);
     
      vgDrawImage    (img);
      vgDestroyImage (img);
      vgDestroyPaint (paint);
    }

  2. #2
    nevermind - I found it - my rampstop-definition wasn't correct.

Similar Threads

  1. What is wrong with this code?
    By Wolftein in forum Developers Coding:Advanced
    Replies: 0
    Last Post: 06-17-2012, 10:38 PM
  2. Replies: 1
    Last Post: 12-06-2010, 10:39 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
  •