Closed luk22 closed 6 years ago
This is source:
SuperStrict
Import "Render2Texture\renderimage.bmx"
Global gc:TGraphics = Graphics(1280, 720, 0, 60, GRAPHICS_BACKBUFFER)
Local rt:TRenderImage = CreateRenderImage(gc, 640, 360)
Global imgFow:TImage = LoadImage("black_square.png")
While Not KeyHit(KEY_ESCAPE)
' render into the texture
SetRenderImage(rt)
SetTransform
SetAlpha 1
SetClsColor(0, 0, 0)
Cls
SetBlend ALPHABLEND
DrawImage(imgFow, 400, 200)
SetRenderImage(Null)
SetAlpha 1
SetClsColor(134,23,33)
Cls
SetBlend ALPHABLEND
SetAlpha 1
DrawImage(rt, 0, 0)
Flip 1
Wend
On OpenGL I have the same results so maybe this is how Alphablending equation works? Also I'm still loosing RederImage after Alt+Tab on DX9. On OpenGL all is fine.
You should be able to Cls a renderimage in the normal way that you would Cls the backbuffer. Could you provide a link with the image that you use here? It is more than likely the alpha blend mode causing the effect but I'd prefer to confirm it.
For Dx9 are you also using the modified d3d9graphics.bmx file in the dxgraphics module folder? You'll need to build the module for it to take effect.
Yes, I used modified d3d9graphics.bmx and rebuild dxgraphics module.
After running app:
After Alt+TAB:
Here is black_square.png
I've just tested that loosing texture issue do not affect full-screen mode (what for me is fully satisfying)
About CLS: when you using Cls, alpha is always 255. I need 0-alpha clearing for TRenderImage
Hiya, I believe I've fixed the alt-tab issue and committed an update if you would like to try it.
I'm not exactly 100% sure what results you're expecting with respect to the alpha issue. When you are rendering to your render target you would draw everything as you normally expect with various alphas etc. When rendering the render target to the back buffer you would render it as a solid image with no alpha applied to 'blit' the rendered image to the back buffer - in which case this would work :-
`
' render into the texture
SetRenderImage(rt)
SetTransform
SetAlpha 1
SetClsColor(0, 0, 0)
Cls
SetBlend ALPHABLEND
DrawImage(imgFow, 400, 200)
SetRenderImage(Null)
SetClsColor(134,23,33)
Cls
SetBlend SOLIDBLEND
DrawImage(rt, 0, 0)
Flip 1`
But like I say I'm not 100% sure on the effect that you're looking to achieve so there could still be an error somewhere.
EDITED for clarity
Hello I tested and It works! Thanks again :) About initial alphablneding effect everything seems to be OK. I checked DirectX blending equations and it is just how it works: when you alphablend transparent image onto solid image, result will be slightly transparent.
Thank you for finding the bug! I'm glad the alpha is working as expected too.
To avoid such misconceptions I use "software rendering" for custom blend modes (multiply, add, difference, ...).
I also assumed that drawing a semitransparent image onto a solid one should add, not multiply alpha values. For me it is as if you have two layers of foil you paint on. Then you lay over two foils and check the resulting colors.
For alpha blending I believe you do add. Blending seems to get complicated quickly when done on the gpu as you can also have a source and destination blend factor that is multiplied by the source and destination before them adding to get your result.
BTW. Do you know any 2d shaders module or script for Bmx Vanilla? I need 2d-water effect.
Most of the ones Ive seen are gl only. I was toying with the idea of doing a shader module that will use the same syntax for all of the Max 2D graphics drivers but havent got around to it just yet.
I you would be eventually intersted in making some shaders code for me (paid job) drop me your email at luke@cogwheelsoftware.com
Also I have one more question about Render2Textres: are there any limitations or cons if I use TRenderImage instead of normal TImage for all images in my game? Will it be slower or more VRAM consumig? Will it have some side effects?
Providing that the system works as expected I doubt you will see any side effects, or any memory requirement differences. Most of code is about telling the gpu that a texture can be used for rendering to. I wouldn't be surprised if that information is just a bunch of flag bits in the gpu driver related code somewhere.
Generic Shaders (OGL, DX) would be something cool - and a nice addition to the now already "generic" R2T-feature... ok, except for SDL/BMX-NG (would be nice to have it there too - talking about RasPI and the likes). Once it truly "works" on the (NG-)supported platforms I would more than just be willed to use it - as it allows for "standard" animations (like easing-in scales of a whole widget-set - like "Ingame menus" or inventories). Also R2T allows for easier "alpha"-effects (draw everything on a texture and set alpha ... this does not work with drawing a background with that alpha and afterwards the foreground with that alpha - it is an absolutely different effect).
But even yet it is absolutely cool to have it kind of unified (compared to the independend solutions for DX and OGL). It is one of the features I would like to see in the official module list for BlitzMax - so similar to brl.mod and pub.mod entries
GWRon: you know any DX-dedicated shaders for Blitzmax?
I am linux user...and for now I only needed a shader once (and failed). Needed a water shader for a top down view...
So I have no shaders....but have a look at NG as it uses simple shaders to display stuff
Yes, I'm observing NG but at the moment my game is total mess when run on NG :)
Which version of Dx are you targetting?
DX 9.0c
On my windows10-machine with Intel IGP I get "opaque" render2texture-images. So a transparent image (a newly created one) is black plus the opaque pixels drawn by the textures/images/draw-command.
Using OGL the images are transparent as intented.
Same happens when running the app via "wine" on my nvidia-gpu-based-linux. So It has to do something with the implementation (the code here ;-))
Ok... found the culprit for the black images: I had an "cls()" in - and on OGL it kept the images "transparent" while on DX it turned them "black".
Assumed I had to "clean" it similar to a freshly created image via CreateImage()
(might contain pixel garbage until you did a LockImage(...).ClearPixels(0)
.
Hello, at first thank you very very much for this extension which gives so much new possibilities for 2d lighting generation.
Here is what I did:
Created RenderImage and with it:
I drew that rendered image to screen filled with non-black color. If I'm getting it properly I should get just black rectangle because black blended on black is black. But I get this:
It looks like the red "ring" is transparent. Why?
Another question: How can I Cls RenderImage with ARGB 0,0,0,0 ?