tags:

views:

106

answers:

1

what is the best way to create a gradient for a 2D polygon in OpenGL, (Linear, and Radial)?

Thanks

How can you generate textures for radial gradients on the fly?

+1  A: 

Linear is very easy - you just set different colors to different points like

red ---- red
|        |
|        |
|        |
blue ---- blue

for radial texture might be better option

to generate it on fly create empty texture then fill it with function sqrt((MAXX - x)^2 + (MAXY - y)^2), then add color to it.

Andrey
You could use the first method with several triangles to simulate a radial gradient.
Judge Maygarden
... and I would use the triangle fan primitive to ease the geometry construction for radial gradient.
Luca
@Luca i thought about it, but i think it will not look nice. texture will be certanly better
Andrey