Render to Texture: Read on.....
BlitzMax Forums/BlitzMax Programming/Render to Texture: Read on.....
| ||
*It does not require any tweaking of any official modules* And yes it works in DirectX and OpenGL (Win/OSX and probably Linux). *** NOW WITH GREYSCALE RENDER : http://www.blitzbasic.com/Community/posts.php?topic=56099 What does it do? It lets you create images that can be used as render targets. Basically anything you can draw to screen you can now draw to an image. If you don't know what to use it for then you don't need it. So what do you want to do? 1) Moan about some feature that it does not support? 2) Let me post the module and get on with my business? Your choice... Email me if you want a copy of the module. |
| ||
Post the mod :) |
| ||
+1 |
| ||
Post mod, ignore moaning, do bugfixes if a nasty one is found. And thank you verry much! :) |
| ||
I'll release it tomorrow, I got too much going on right now. The following example code creates an empty image, when you click the mouse it renders a white square and a Purple Circle to the image and attaches it to the mouse. Strict Import Indiepath.Render2Texture Graphics 640,480 tRender.Initialise() Local myImage:TImage = tRender.Create(128,128) While Not KeyHit(KEY_ESCAPE) Cls If MouseHit(1) tRender.TextureRender_Begin(myImage) Cls SetColor 255,255,255 DrawRect 0,0,40,40 SetColor 255,0,255 DrawOval 10,10,20,20 tRender.TextureRender_End() EndIf SetColor 255,255,255 tRender.BackBufferRender_Begin() DrawImage myImage,MouseX(),MouseY() tRender.BackBufferRender_End() Flip Wend EndGraphics() |
| ||
Nice, how much faster is it than grabbing a pixmap? |
| ||
Imagine you just learned how to run... |
| ||
great, i was hoping someone would do something like this. cheers : ) |
| ||
hmmm, what uses are there? |
| ||
Oh Mr Cummings, you of all people should know - I suspect you are taking the Michael. For the people who are actually interested : The benefit of Render to Texture is that everything stays in Video Mem, no more copying from the back buffer to an image buffer (in memory) back to the backbuffer. With Render to Texture you can do fullscreen realtime effects such as:- - Fullscreen blurs - Feedback effects - Bloom filters - TV-Style Scene Transitions - motion blur - Real time depth of field for you parallax scrollers - Combining render-to-texture and bump mapping to do heat shimmer or refraction effects. |
| ||
Sounds cool. Please release. :) |
| ||
Sounds good... bet it's well slow though - I await the amazing demo :) |
| ||
Excellent and very handy for lots of purposes. Looking forward to it, thanks for the hard work. |
| ||
ROFL - Me, demo, amazing, LOL! |
| ||
Great, I've waited for something like that =) Just one question: What system-minimum is able to render to a texture? |
| ||
That are great news indiespath :-) |
| ||
I just did some tests on speed and I think you'd be interested in the results. The code below gave these results (i've commented them) : Render 1 Million Random Blocks to Backbuffer and Flip (Cycle1): 2739 Millisecs (DirectX) 1887 (OpengGL) Render 1 Million Blocks to Texture then Draw Image to Backbuffer and Flip (Cycle1) : 2721 Millisecs (DirectX) 1867 (OpenGL) Render 1 Million Random Blocks to Backbuffer and Flip (Cycle2): 2667 Millisecs (DirectX) 1867 (OpenGL) Render 1 Million Blocks to Texture then Draw Image to Backbuffer and Flip (Cycle2) : 2670 Millisecs(DirectX) 1868 (OpenGL) Now unless I've made some stupid error in my test code I reckon that's pretty damn fast don't you Mr Cummings.. |
| ||
Thats really great. That if we would render straight to backbuffer just with the aditional use of an "effect image" we could missuse for other things :-) |
| ||
I've made a few changes, the BlitzMax DirectX "SetViewport" command does not actually set the Viewport, it sets clip-planes. I've added a *REAL* viewport command. Just doing the docs and I'll upload it. Maybe :) |
| ||
Made another change the the OpenGL View port, the Y axis WAS flipped. Email me if you want a copy of the module. Bye... |
| ||
Damn that sounds plenty quick. Don't understand why copyrect is slow in Blitz3d? |
| ||
Problem with CopyRect, from my understanding, is that its pulling the data from the VideoMemory to System Memory and then back again when you convert the image to a texture. What this is doing is creating a texture in Videomemory and rendering directly to it. I do have one question : Say I rendered a screen to the Texture and the background is black, How do I make the black stuff transparent? |
| ||
I'll do a bloom filter example when I've picked my daughter up from school... |
| ||
I can definitely see a lot of uses for this. I have emailed you Mr Indie for the module ;-) |
| ||
Hey, does this mean you can have an effective `backbuffer` (well, a texture) which is bigger than the screen resolution? THAT is a useful feature! Does it only support RGBA8888 textures btw? |
| ||
Yes RGBA8888 Pixel Format. MipMaps and Filtered flags don't work yet in DirectX neither does MipMap display selection. |
| ||
Sounds excellent! You've made some great modules. Thank you! |
| ||
I've already asked but didn't get an answer: What system-minimum do I need to support "Render2Texture"? It won't run on old graphiccards, will it? :/ |
| ||
If your card supports DX7 then it should support Render To Texture. Cards released prior to DX7 will probably not support it. You could always use OpenGL as the fallback... Do a device caps to see if your card does indeed support it. |
| ||
Here is a small example : http://indiepath.com/public/Example1.rar Here is the code for the example Strict Import Indiepath.Render2Texture HideMouse() 'SetGraphicsDriver GLMax2DDriver() Graphics 640,480,32 tRender.Initialise() AutoMidHandle(1) Local logo:Timage = LoadImage("bmax160_2.png",MIPMAPPEDIMAGE|FILTEREDIMAGE) Local myImage:TImage = tRender.Create(256,128,MIPMAPPEDIMAGE|FILTEREDIMAGE) tRender.TextureRender_Begin(myImage) Cls tRender.TextureRender_End() SetBlend(ALPHABLEND) Local ii:Float = 0 While Not KeyHit(KEY_ESCAPE) SetBlend(ALPHABLEND) SetAlpha(1) tRender.TextureRender_Begin(myImage) Cls SetRotation(ii) Local sc:Float = (Sin(MilliSecs()/10))+1.5 SetScale(sc,sc) DrawImage logo,320,240 tRender.TextureRender_End() tRender.BackBufferRender_Begin() SetRotation(ii) DrawImage logo,320,240 SetBlend(ALPHABLEND) SetMaskColor(0,0,0) SetRotation(0) Local ap# = 0.2 SetScale(1,1) For Local a:Int = 1 To 10 Local Xoffset:Int = a * 60 Local yoffset:Int = a * 40 SetAlpha(ap#) DrawImageRect(myImage,-Xoffset,-Yoffset,640+(XOffset*2),480+(yOffset*2)) ap:-0.01 Next tRender.BackBufferRender_End() If MouseHit(1) tRender.SetMipMap(myImage,1) Flip ii:+1 Wend |
| ||
Can I strech the texture? Can I change the color? Can I... This for me looks like it must be part of the poly.mod. |
| ||
@Haramanai Do what you want, it's treated just as a normal image. You can even render your rendered texture to another texture if you so desire! This will not be part of the Poly mod because it's got nothing to do with the Poly module :) |
| ||
Anyway I gotta go I got a big press announcement to make re: igLoader :D |
| ||
Now uses MipMapped, Filtered and other TExture flags... Also has Manual MipMap level selection for effects such as 3D accelerated fullscreen blur. |
| ||
I think this is a great module but if I recall, mark said he didn't use Render to Texture for a very good reason, and that was it was really slow on some cards? I would be very cautious about releasing a casual game with render to texture but enthusiastic for more hardcore titles. |
| ||
With Render to Texture you can do fullscreen realtime effects such as:- Hmmmm. very interesting -- I wonder if my fade-to-black&white routine would see any speed increase with this. Sounds like it should. |
| ||
@Rob, I've build it some error checking so your application will know if the client machine is compatible. I've had to rebuilt the Image creation routines as the offical module was unable to build textures with the required caps. Maybe that is why Mark did not include it. Have a look at this article and try to remember it's 7 years old! : http://www.gamasutra.com/features/19991112/pallister_pfv.htm |
| ||
where was the mod posted? |
| ||
I emailed for the mod, no sign of it :? |
| ||
no email :( |
| ||
Will you post the module here or will I have to send a mail too? |
| ||
No email no Module... |
| ||
...why? ôo But well, okay, I'll mail. Just interested why you don't just post it. |
| ||
Hi, I tried out the module today and think its brilliant, the only thing I have a problem with ( which i think you mentioned above ) is the ability to mask colours out. For example the code below: Import indiepath.render2texture Graphics 800, 600 trender.initialise () img:timage = trender.create ( 400, 400,, 0, 0, 0 ) trender.texturerender_begin ( img ) SetClsColor ( 0, 0, 0 ) Cls SetColor ( 200, 100, 300 ) DrawRect ( 10, 10, 150, 150 ) trender.texturerender_end () Repeat trender.backbufferrender_begin () Cls SetColor ( 200, 0, 255 ) DrawRect ( 10, 10, 500, 500 ) DrawImage ( img, 100, 100 ) trender.backbufferrender_end () Flip Until AppTerminate () = 1 On my machine there is no transparency where the black pixels are, which is a problem for me. Is there something im missing? Or is it not possible to do what I want? |
| ||
I did send an email but apparently you didn't get it, oh well |
| ||
@jamesmintram: You forgot to set the the blend mode to mask |
| ||
Ok, thanks man. I will try that out when I get back to my cabin. |
| ||
@AngelDaniel, emailed ya. @Dreamora, oh is that how you do it :) @James, You really should try and keep your texture sizes ^2 like 256x256 or 512x512 or even 512x256. If you don't do this you just end up wasting video memory. |
| ||
Received, thanks |
| ||
Tim, I've sent two emails now - have you recieved them? Which email address is the best to contact you with? ?? |
| ||
I tried what Dreamora suggested to no avail, heres the code I ran.Import indiepath.render2texture Graphics 800, 600 trender.initialise () setblend ( MASKBLEND ) img:timage = trender.create ( 400, 400,, 0, 0, 0 ) trender.texturerender_begin ( img ) SetClsColor ( 0, 0, 0 ) Cls SetColor ( 200, 100, 300 ) DrawRect ( 10, 10, 150, 150 ) trender.texturerender_end () Repeat trender.backbufferrender_begin () Cls SetColor ( 200, 0, 255 ) DrawRect ( 10, 10, 700, 700 ) DrawImage ( img, 100, 100 ) trender.backbufferrender_end () Flip Until AppTerminate () = 1 |
| ||
does this work on mac yet? cheers charlie |
| ||
It's always worked in the Mac, I've sent copies to those Mac users that have requested it. |
| ||
@jamesmintram: And what is the actual problem? (beside that, color range is 0-255 not 300 ;)) the image is drawn correctly. As you haven't changed the mask color for it, it will only see black as mask color which you haven't used at any point on the texture |
| ||
The 300 should be a 200, typo, but it still seemd to work on my system. Anyway there is black in img, i create it, clear it all to black and then draw a rect onto a section of it. When img is drawn further on there are is no transparency where the black pixels are in the image. Maybe im not seeing something here, if you could post and example which works on your system, i could then see if its me or if its an issue with my machine. Cheers |
| ||
Seems like there is definitely an error in it, so I'm for missinforming. Normally the setblend maskblend should work and as example 3 shows, for alpha it even seems to work.Strict Import indiepath.render2texture Graphics 800, 600 trender.initialise () SetMaskColor(200,200,200) Local img:TImage = trender.Create ( 400, 400, MASKEDIMAGE, 200, 200, 200 ) trender.texturerender_begin ( img ) SetClsColor ( 200, 200, 200 ) Cls SetColor ( 200, 100, 200 ) DrawRect ( 10, 10, 150, 150 ) trender.texturerender_end () SetBlend ( MASKBLEND ) Repeat trender.backbufferrender_begin () Cls SetColor ( 200, 0, 255 ) DrawRect ( 10, 10, 700, 700 ) SetColor ( 255, 255, 255) DrawImage ( img, 100, 100 ) trender.backbufferrender_end () Flip Until AppTerminate () = 1 As you see, even using BMs internal setmaskcolor does not help to get around this. |
| ||
I've looked into this further and it from what I can see BMAX sets the MaskColor when it loads/creates the image - it's not dynamic. I'm trying to find a dynamic way of doing it without reading every damn texel and changing it. |
| ||
the irrlicht module allows for rendering to textures and it works very well, indiepath you should check it out. |
| ||
Does it allow for alpha masking? |
| ||
I believe so, the only problem being is the fact you would not be able to use max2d commands with it as it is a complete 3d engine based on opengl/directx. Which defeats the point of your mod (im guessing). |
| ||
The problem is the same as loading a .BMP file and using that as a sprite with alpha. Someone must know how to change the blend mode so that black becomes Alpha, and I don't mean light blend. |
| ||
Apologies to those who have emailed me and have not received the module yet. I've got a lot of work on at the moment and I will get something out to you all soon. Tim. |
| ||
Sorted the problem!!!! I've introduced a new cls command that allows the ClsColor to have alpha!!! |
| ||
OSX compiled, will send out later. |
| ||
Sorry to bump an old thread but any chance of a copy of the module? |
| ||
modules.indiepath.com |
| ||
Found the forum ok but no download area. Have I missed something? Earlier in the thread you've asked people to email you but there's no email address in you profile which makes that a tad difficult.. :) |
| ||
@Rik, then do some research, I have many sites and many ways to contact me. |
| ||
http://www.indiepath.com/contact.php |
| ||
Err, thanks Grey. @ indiepath, err, thanks... I think? Did I do/say something to offend somehow? Just asking as I'd only asked a question. Didn't think that deserved such a curt or sarcastic response, especially when the links in your sig are either broken or just a holding page.. Wouldn't it have been easier to just poste the link to where I could contact you as Grey Alien kindly did? Hey, I was just trying to support your module thats all.. :( |
| ||
Hmm... so it seems Indiepath's module is not an option then.. Has anyone else got a (OpenGL) Render to Texture solution? It's only for my own noodlings at home but I wouldn't mind paying a sensible amount for a decent solution that works. |
| ||
. |
| ||
Hmm... so it seems Indiepath's module is not an option then.. What was the reply when you contacted Indiepath? Did you post anything on his forums? There was a Highgfx module from Diablo but it went 'wrong' and was removed. I got something working myself but the changes made in 1.24 meant I would have to start again and life is too short. What is it you want it for again? Maybe there is an alternative solution. |
| ||
can't you do this with minib3d? or is that different? Cheers Charlie |
| ||
What was the reply when you contacted Indiepath? I mailed via the link grey found but didn't get a reply. Did you post anything on his forums? I'd love to but having registered it requires admin approval prior to posting. Interestingly there are users who registered *after* me that did get approved but for some reason I didn't, further fuelling my paranoia stated above... What is it you want it for again? Maybe there is an alternative solution. Just noodling with some feedback type effects really, and to allow me to draw to off-screen render targets to use for some message displays etc. |
| ||
If you can find HighGfx then it might help the OGL side and still work. It's well documented that there is a lot of interest in getting RTT included in the official code but Mark isn't interested. |
| ||
He's probably getting married or on honeymoon around now...or just hiding ;-) |
| ||
tonyg: Thanks, Found the original thread but unfortunately the D/L link is dead. Anyone happen to have a copy floating around anywhere? |
| ||
I have a version here i could send you RiK. Is that your moniker on yakyak too, i could send you a pm if it is. Cheers Charlie |
| ||
Thanks Charlie.. Yup, same RiK. email is rik[AT]olpin[DOT]net |
| ||
Is there a new (eg. working) render-to-texture module available for BlitzMax? @JKrankie: I've sent you an e-mail :) |
| ||
Still trying to track down a solution here, no luck so far... |