Fast 2D gradients?
BlitzMax Forums/OpenGL Module/Fast 2D gradients?
| ||
Is there a really fast GL way to draw 2D gradients? Nothing fancy, just left-right or up-down. |
| ||
Graphics 640,480,0,0 Repeat x:Float = rnd(0,GraphicsWidth()) y:Float = rnd(0,GraphicsHeight()) w:Float = rnd(1,GraphicsWidth()) h:Float = rnd(1,GraphicsHeight()) r0:Float = rnd(0,255) g0:Float = rnd(0,255) b0:Float = rnd(0,255) r1:Float = rnd(0,255) g1:Float = rnd(0,255) b1:Float = rnd(0,255) direction:Int = Rand(0,1) DrawGradient(x,y,w,h,r0,g0,b0,r1,g1,b1,direction) Flip Until KeyHit(KEY_ESCAPE) End Function DrawGradient(x:Float,y:Float,w:Float,h:Float,r0:Float=255.0,g0:Float=0.0,b0:Float=0.0,r1:Float=255.0,g1:Float=255.0,b1:Float=0.0,direction:Int=0) r0 = r0/255.0 g0 = g0/255.0 b0 = b0/255.0 r1 = r1/255.0 g1 = g1/255.0 b1 = b1/255.0 glBegin GL_QUADS glColor3f r0,g0,b0 glVertex2f x,y If direction = 0 glColor3f r0,g0,b0 Else glColor3f r1,g1,b1 EndIf glVertex2f x+w,y glColor3f r1,g1,b1 glVertex2f x+w,y+h If direction = 0 glColor3f r1,g1,b1 Else glColor3f r0,g0,b0 EndIf glVertex2f x,y+h glEnd EndFunction |
| ||
*hugs fredborg* |
| ||
Also just: glBegin glColor3b $FF,$FF,$FF glVertex2i(50,50) glVertex2i(100,50) glColor3b $0,$0,$0 glVertex2i(100,200) glVertex2i(50,200) glEnd Should draw a gradient. |