too many experiments until i get it to work, but it happened a little change we need to do.
1) if we replace RGB by MP_ARGB in the MP_LineXY(1, k, k, k, RGB(k,0,k)) it will plot the gradient lines on Texture1. which i have moved outside the main loop. 2) clear the Texture2 with MP_ARGB(0,0,0,0))
Code: Select all
EnableExplicit
;////////////////////////////////////////////////////////////
;// Trying to draw 2D on different textures;
;// Based on.... MP_RenderTotexture.pb - by Michael Paulwitz - 3.11.2010
;// Tested MP3D version 33 with PB 5.40 LTS
;////////////////////////////////////////////////////////////////
MP_Graphics3D (640,480,0,3) : SetWindowTitle(0, "Draw on Texture")
MP_AmbientSetLight (RGB(0,50,128))
; Create Empty Textures and Sprites from them
Global Texture1 = MP_CreateTexture(200, 200)
Global Texture2 = MP_CreateTexture(200, 200)
Global Texture3 = MP_CreateTexture(200, 200)
Global Texture4 = MP_CreateTexture(200, 200)
Global Sprite1 = MP_SpriteFromTexture(Texture1)
Global Sprite2 = MP_SpriteFromTexture(Texture2)
Global Sprite3 = MP_SpriteFromTexture(Texture3)
Global Sprite4 = MP_SpriteFromTexture(Texture4)
;- Draw on Texture 1
MP_Box(0,0,MP_SpriteGetWidth(Sprite1),MP_SpriteGetHeight(Sprite1),$FFFF00,1) ; yellow box
Global k
For k=0 To 200
MP_LineXY(0, k, k, k, MP_ARGB(255,k,0,k)) ; gradient
Next
MP_RenderToTexture(Texture1, MP_ARGB($FF,255,255,0))
;MP_RenderToTexture(Texture1,MP_ARGB($FF,$00,$FF,$FF)) ; to texture with cyan background
;- Draw on Texture 2
MP_Box(0,0,MP_SpriteGetWidth(Sprite2), MP_SpriteGetHeight(Sprite2), RGB($FF,$0,$0), 1) ; <--- red filled box never gets drawn
; MP_DrawText(0,0,"Draw In Texture 2")
MP_LineXY (0,0, MP_SpriteGetWidth(Sprite2), MP_SpriteGetHeight(Sprite2), MP_ARGB($FF,$0,$FF,$0))
MP_LineXY (0, MP_SpriteGetHeight(Sprite2), MP_SpriteGetWidth(Sprite2), 0, MP_ARGB($FF,$0,$FF,$0))
MP_RenderToTexture(Texture2, MP_ARGB(0,0,0,0)) ; to texture (transparent background?)
;- Draw on Texture 3
MP_Box(0,0,200,200,$0F0F0F,1) ; <--- dark grey box never gets drawn
;MP_DrawText(10,20,"Only In Texture 3")
MP_LineXY (0,0, MP_SpriteGetWidth(Sprite3), MP_SpriteGetHeight(Sprite3), MP_ARGB($FF,$FF,0,0))
MP_LineXY (0, MP_SpriteGetHeight(Sprite3), MP_SpriteGetWidth(Sprite3), 0, MP_ARGB($FF,$FF,0,0))
MP_RenderToTexture(Texture3, MP_ARGB($FF,0,0,$FF)) ; to texture with a blue background
;- Draw on Texture 4
MP_Box(0,0,200,200,RGB(127,127,127),0) ; <--- light grey box never gets drawn
;MP_DrawText(10,20,"Only In Texture 3")
MP_LineXY (0,0, MP_SpriteGetWidth(Sprite4), MP_SpriteGetHeight(Sprite4), MP_ARGB($FF,$0,$0,$FF))
MP_LineXY (0, MP_SpriteGetHeight(Sprite4), MP_SpriteGetWidth(Sprite4), 0, MP_ARGB($FF,$0,$0,$FF))
MP_RenderToTexture(Texture4, MP_ARGB($FF,0,$FF,0)) ; to texture with a green background
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
; ^^^ comment this out, and you see the expected contents on the screen at 0,0
; which is a yellow box with a black-purple gradient in half
; when uncommented though, this should be in the Texture1?
; build the display
MP_DrawSprite(Sprite1, 50, 10)
MP_DrawSprite(Sprite2, 300, 10)
MP_DrawSprite(Sprite3, 50, 260)
MP_DrawSprite(Sprite4, 300, 260)
MP_DrawText (550,460,"FPS = "+Str(MP_FPS()))
MP_RenderWorld()
MP_Flip ()
Wend