Images and buffers

BlitzMax Forums/BlitzMax Beginners Area/Images and buffers

Gillissie(Posted 2008) [#1]
I'm from Blitz3D, so I am stumped on how to draw to an image. I don't see any commands for setting the current buffer (such as SetBuffer() in B3D). Basically, I want to create an image, draw some stuff to it, including text, than save the image as a file. It can't be that hard, but I can't figure it out.

Thanks for the help!


Jesse(Posted 2008) [#2]
you are not able to draw to an image as in b3d BB, everything is drawn to the backbuffer and displayed when you flip. Draw anything to the back buffer and grab it with grabpixmap or grabImage before flipping.

note: you are limited to the screen area for grabs.
you can draw directly to the pixmap but that's really low level stuff such as writepixel readpixel. no other command works on pixmap such as drawtext, drawline etc... os of now.


Dabhand(Posted 2008) [#3]
Indiepath posted some code yonks ago, regarding render targets, basically, the backbuffer is a render target, you can create a texture in DirectX and specify that it can be used to render too, I'm using this code C++/DirectX when creating a blank image:-

Texture newtexture;
D3DXCreateTexture(pD3DDevice,imageWidth,imageHeight,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&newtexture.texture);
newtexture.texture->GetSurfaceLevel(0,&newtexture.pTextureSurface);


After creating the texture (with the specified D3DUSAGE_RENDERTARGET usage flag), I grab the surface using GetSurfaceLevel, then when I want to draw on the texture, instead of the backbuffer, you use this:-

pD3DDevice->SetRenderTarget(0,newtexture.pTextureSurface);


And jobs a good'un! :)

So, it is posssible in BlitzMax to draw to images, you really must look under the hood though and make room for it.

Dabz


Jesse(Posted 2008) [#4]
That is interesting Dabz.
Can you please post a working example so I can get a better idea how it works?


MGE(Posted 2008) [#5]
No one has posted a working version compatible with the latest version of BMax. And no one has posted a version compatiblel with both OGL and Bmax. This process is called "Render To Texture" btw.


Brucey(Posted 2008) [#6]
As dabz said, indeipath posted working code, and that HighGfx module also does it, as far as I remember.


Dabhand(Posted 2008) [#7]

No one has posted a working version compatible with the latest version of BMax. And no one has posted a version compatiblel with both OGL and Bmax.



I find it truely amazing that you had actually found time to post that in your busy life... For what good it was! Oo


This process is called "Render To Texture" btw.



Offically, by the nice chaps who make the DirectX API, they are called Render Targets... http://msdn.microsoft.com/en-us/library/bb976073.aspx... btw

But, your probably too busy to read it! :P Hehehe


Can you please post a working example so I can get a better idea how it works?



Basically, its no more than what I've posted up there in C++, the one thing you have to remember is that the backbuffer is also a render target, so after you've setup DirectX, you need to grab the backbuffer surface too:-

pD3DDevice->GetRenderTarget(0,&pBackBuffer);


Then, when you want to return drawing to the back buffer, you use:-

pD3DDevice->SetRenderTarget(0,pBackBuffer);


When you generally setup a render target in DirectX , it starts off as non transparent black, which is obviously a bit of a bugger... BUT, you can clear the target with 0 alpha, then draw on it as usual.. Which creates a masking effect (Doesnt work on the backbuffer though)! :)

This is all in DirectX9 (Though, I wouldnt have a clue about DirectX7) and is currently implemented in my own engine which I'm building.

Dabz


MGE(Posted 2008) [#8]
"Though, I wouldnt have a clue about DirectX7" lol..

Your DX9 solution is wonderful and I'm sure it has 1000's of users, but for Blitzmax coders the goal is to write games for Mac and Windows so we need a OpenGL and DirectX7 solution. The biggest hurdle is making it compatible with the existing graphics pipeline built into Blitzmax. Unless I missed something, if someone has this already working, I'll pay money for this and I'm sure others would as well.


Brucey(Posted 2008) [#9]
Unless I missed something

A search of the forum should turn something up.


Dabhand(Posted 2008) [#10]

Your DX9 solution is wonderful and I'm sure it has 1000's of users, but for Blitzmax coders the goal is to write games for Mac and Windows so we need a OpenGL and DirectX7 solution. The biggest hurdle is making it compatible with the existing graphics pipeline built into Blitzmax. Unless I missed something, if someone has this already working, I'll pay money for this and I'm sure others would as well.



Well, from what I do recall, someone posted on the forum requesting if indiepath could re-release the code.

Indiepath declined to release it to the general public, but did say that if the person in question emailed him, he would send him the source.

That was a while back mind, so... The only person to ask is Indie himself...

Shy bears get no soup, as the saying goes! :)

Dabz


plash(Posted 2008) [#11]
All links to HighGfx seem to be broken (afaik it only supported OpenGL).

The most curious thing is why Indiepath has yet to just post the source to his modules - if they are free why be so protective?


tonyg(Posted 2008) [#12]
Highgfx and Tim's RTT source


plash(Posted 2008) [#13]
Never saw the mirror, thanks.

Indiepath's module works great!


MGE(Posted 2008) [#14]
Plash...is Indiepath's code openfl and dx supported? Fingers are crossed! :) I did some amazing things in DX8 where my engine could render a whole scene to a texture. Very cool! :)


plash(Posted 2008) [#15]
You could have easily figured out both questions, if you'd simply read the code.
I'll leave it up to you.


MGE(Posted 2008) [#16]
Thanks Plash.


Jesse(Posted 2008) [#17]
Thanks on my side guys. I just hope Gillissie find all this tech stuff usefull. What A way to throw somebody new into BMAX. Welcome Aboard.


MGE(Posted 2008) [#18]
RTT doesn't work on my old intel box. Bummer.


Derron(Posted 2008) [#19]
As I remember the posted RTT-code also doesn't work when using the inofficial dx9-code placed here in the forums (which should have been updated some "this weekend" ago).

So atm you have to include some switches (if settings.mode='dx9' then doX else if settings.dx7 then doY else doZ).


bye MB