Gradients?

BlitzMax Forums/BlitzMax Programming/Gradients?

Thareh(Posted 2009) [#1]
Hi,
Anyone knows why Fredborgs old Gradient sample doesn't work anymore?
Or, Does anyone have a better way of doing gradients in Max2D using OpenGL? ^^



Thanks :)


Thareh(Posted 2009) [#2]
Oh, Using the correct GraphicsDriver could be good :P
Now I have another issue though, Using DrawText in the same loop as this function has some strange effects, the Gradient just disappears..
Any thoughts on why? :S




ImaginaryHuman(Posted 2009) [#3]
Drawing text probably enables texturemapping which `hides` the smooth shading that you'd see in the quads you're drawing. glDisable GL_TEXTURE_2D ?

Trying to use some gl commands mixed with Max2d is in many cases a conflict of interests.


Thareh(Posted 2009) [#4]
I came up with a better way of doing Gradients now I think :P
Just create an image 1x2 pixels, One white and one Black or Dark Grey, Load the image and use DrawImageRect() and OpenGL with smooth the image to a Gradient :P (And the best thing is that you can just use SetColor before to get the color you want if you just want a fading color)
I wonder how fast this is though..


ImaginaryHuman(Posted 2009) [#5]
That's a good way to do it. It does use more computation because each pixel still has to do a texture lookup, but the texture is very small and there are caches which help speedup accesses which surely will be helping in this case. You don't really need the texture to do such a gradient but it's probably not much slower.


daaan(Posted 2009) [#6]
[EDIT] I'm a dork and need to read.


Why not just use OpenGL commands?

Something like:

glBegin(GL_QUAD)

glColor4f(1.0, 0.0, 0.0, 1.0)
glVertex2f(0.0, 0.0)

glColor4f(0.0, 1.0, 0.0, 1.0)
glVertex2f(0.0, GraphicsHeight())

glColor4f(0,0, 0.0, 1.0, 1.0)
glVertex2f(GraphicsWidth(), GraphicsHeight())

glColor4f(1.0, 1.0, 1.0, 1.0)
glVertex2f(GraphicsWidth(), 0.0)

glEnd()