Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Drawing a gradient fill in 2D vector based objects

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    9

    Drawing a gradient fill in 2D vector based objects

    Hello! I'm trying to make an OpenGL based vector drawing library, similar to Cairo or Antigrain. Since I have a limited knowledge of scanlines and rasterization and the like, but a good knowledge of OpenGL, I've decided to use that to create my library. Since a good vector library needs gradient fill support, I will need to implement this. The problem is that I don't know exactly how to go about doing this. I could create a texture that contains the gradient texture, but this will limit the quality of the gradient fill for large objects (mipmapping can only do so much). Another problem with that is that generating the gradient texture may be very slow, especially for radial gradients. Does anyone have any suggestions as to how to fill objects with a gradient? Thanks for your help!

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2005
    Posts
    15

    Re: Drawing a gradient fill in 2D vector based objects

    Hi ionstream, if you are interested in accelerated 2D vector graphics, you can't miss Amanith ( http://www.amanith.org ); it does all nice things you are looking for, in pure OpenGL.
    Cya!

  3. #3
    Intern Newbie
    Join Date
    Nov 2005
    Location
    Poland
    Posts
    33

    Re: Drawing a gradient fill in 2D vector based objects

    I am not sure I understand you, ionstream.
    OpenGL does linear interpolation of colors, so you get gradients for free if you set different colors for vertices.
    If complex linear gradients are needed, just tesselate your 2D geometry.
    Non-linear gradients (like your radial gradient) can be achieved with fragment shaders (see GL_ARB_fragment_shader and GL_ARB_fragment_program specs). Or, if fragment shaders are not supported, tesselate the geometry even more.

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2005
    Posts
    24

    Re: Drawing a gradient fill in 2D vector based objects

    Linear gradients are trivial. Generate a 1D texture, and assign 1d texcoords to all your mesh vertices increasing linearly along the progression direction of the gradient.

    All other gradient types (talking about those in GIMP e.g.) require an inner point coinciding with the vortex/center of the gradient. 1D textures suffice too. Again, texcoords for each vector are assigned as the gradient direction increases. Spirals and conical gradients require that the center point gets rendered multiple times, once for each edge that emanates from the center.

    I'll leave the texcoord generation as a puzzle for you. Write to adolf_mathias@web.de for a spoiler.

    Just did a quick check in Blender to verify what I wrote. Looks nice!

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    9

    Re: Drawing a gradient fill in 2D vector based objects

    Hi ionstream, if you are interested in accelerated 2D vector graphics, you can't miss Amanith ( http://www.amanith.org ); it does all nice things you are looking for, in pure OpenGL.
    Cya!
    Thanks for the link, but I don't like LGPL'd stuff because of the licensing restrictions. Not that I'm using it for commercial purposes anyways, but I feel I should be free to .

    I think I'm going to take the fragment shader route, as mjkrol suggested, but I am going to look into these fabled 1D textures. Thanks for all your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •