Created
March 10, 2022 14:40
-
-
Save GWRon/fbdb8586d8c885a2249d8195bf02afb4 to your computer and use it in GitHub Desktop.
render2texture_example2.bmx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SuperStrict | |
Framework Brl.StandardIO | |
Import Brl.RandomDefault | |
'Import Brl.GLMax2D | |
'Import Brl.D3D9Max2D | |
'Import SDL.D3D9SDLMax2D | |
Import Sdl.GLSDLMax2D | |
'Import SDL.GL2SDLMax2D | |
'Import Sdl.SDLRenderMax2D | |
import brl.PNGLoader | |
Graphics(800, 600) | |
SetBlend AlphaBlend | |
Local gradientRT:TRenderImage = CreateRenderImage(2, 100, False) | |
SetRenderImage(gradientRT) | |
For local i:int = 0 until 100 | |
Local c:int = Max(0, sin((i)*1.8) * 255) | |
Local a:Float = Max(0, sin(i*8 - 20)) | |
if i > 75 then continue | |
SetAlpha a | |
SetColor c,c,c | |
Plot(0,i) | |
Plot(1,i) | |
Next | |
SetRenderImage(Null) | |
SetImageHandle(gradientRT, 0, 100) | |
SetAlpha 1.0 | |
SetColor 255,255,255 | |
Local circlePieceRT:TRenderImage = CreateRenderImage(100, 100, False) | |
SetRenderImage(circlePieceRT) | |
For local i:int = 0 until 90 | |
Local a:Float = Min(0.9, Max(0, sin(i*2.0 + 00))) | |
SetRotation(i) | |
SetAlpha(a) | |
DrawImage(gradientRT, 0, 100) | |
Next | |
SetRenderImage(Null) | |
SetImageHandle(circlePieceRT, 0, 100) | |
SetAlpha 1.0 | |
SetColor 255,255,255 | |
SetRotation(0) | |
SetColor 255,255,255 | |
Local circleRT:TRenderImage = CreateRenderImage(200,200, FILTEREDIMAGE) | |
Local img:TImage = LoadImage("logo.png") | |
Local rt:TRenderImage = CreateRenderImage(img.width*2, img.height*2, False) | |
Local rtSnapshot:TImage | |
SetColor 255,255,255 | |
SetClsColor 40, 80, 160 | |
While Not KeyDown(KEY_ESCAPE) | |
Cls | |
SetColor 255,255,255 | |
DrawText("Renderer:" + GetGraphicsDriver().ToString(), 0, 0) | |
SetRenderImage(circleRT) | |
Cls | |
For local i:int = 0 until 18 | |
Select i mod 6 | |
case 0 SetColor 255,0,0 | |
case 1 SetColor 255,165,0 | |
case 2 SetColor 255,255,0 | |
case 3 SetColor 0,255,0 | |
case 4 SetColor 0,0,255 | |
case 5 SetColor 165,0,255 | |
EndSelect | |
SetAlpha(float(0.2 + 0.8 * sin(Millisecs()*0.1 + 10 * i))) | |
SetRotation(20*i + Millisecs()*(0.4 + 0.6 * float(sin(i)))) | |
DrawImage(circlePieceRT, 100,100) | |
Next | |
SetAlpha(1.0) | |
SetColor 255,255,255 | |
SetRotation(0) | |
SetRenderImage(Null) | |
SetImageHandle(circleRT, 100,100) | |
Local s:Float = 0.9 + 0.3 * sin(Millisecs() * 0.1) | |
SetScale(s,s) | |
DrawImage(circleRT, 600, 270) | |
SetScale(1,1) | |
Local distanceMod:Float = 0.5 + 0.5 * float(sin(Millisecs()/10)) | |
'update our render2texture image | |
SetRenderImage(rt) | |
SetClsColor(0,0,0,0) | |
cls() | |
DrawImage(img, distanceMod * 0.5 * img.width , 0.5 * img.height) | |
DrawImage(img, (1.0 - distanceMod * 0.5) * img.width, 0.5 * img.height) | |
DrawImage(img, 0.5 * img.width, distanceMod * 0.5 * img.height) | |
DrawImage(img, 0.5 * img.width, (1.0 - distanceMod * 0.5) * img.height) | |
DrawImage(img, 0.5 * img.width, 0.5 * img.height) | |
SetScale 1.0, 1.0 | |
If KeyHit(KEY_SPACE) | |
'GrabImage(rtSnapshot,0,0) | |
rtSnapShot = LoadImage(GrabPixmap(0,0,800,600)) | |
endIf | |
SetRenderImage(Null) | |
SetClsColor 40, 80, 160 | |
'render our r2t | |
SetAlpha(0.5 + 0.5 * float(sin(Millisecs()/10))) | |
DrawImage(rt, 0, 100) | |
SetAlpha(1.0) | |
if rtSnapshot | |
DrawImage(rtSnapshot, 0, 300) | |
endif | |
Flip | |
Wend | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment