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!

muratmat

06-22-2006, 01:28 AM

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!

mjkrol

06-22-2006, 05:09 AM

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.

dolf

06-22-2006, 12:08 PM

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!

ionstream

06-22-2006, 12:41 PM

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!