Copy an Image to a Texture

Blitz3D Forums/Blitz3D Programming/Copy an Image to a Texture

_33(Posted 2007) [#1]
I'm trying to see if this is possible, and if it's also possible to do this with flag 256 active (texture in GDDR).

Any hints on doing this with banks or with kernel32 functions are appreciated.

I've first tought of CopyBuffer ImageBuffer(image), TextureBuffer(texture).... Sadly, that doesn't exist ....... It would be too easy I suppose.

Related topics:
http://www.blitzbasic.com/Community/posts.php?topic=30480
http://www.blitzbasic.com/Community/posts.php?topic=71615

*** NOTE: Do NOT reply with solutions involving Read/WritePixelFast!

Cheers.


_33(Posted 2007) [#2]
Anyone ever used this?
CopyRect src_x,src_y,src_width,src_height,dest_x,dest_y,[src_buffer],[dest_buffer]

Apparently it should work as the Blitz3D docs mention.


b32(Posted 2007) [#3]
Yes, you can use that command to copy an image onto a texture. For the buffers, use ImageBuffer() and TextureBuffer():

I'm not sure if the 'offset' value needed for that method using banks with textures can be found somewhere. However I can imagine that is it different that the image's offset. (72)
I found this topic: http://www.blitzforum.de/forum/viewtopic.php?p=83935&sid=ef10e840ad9c2c239204839a1fdcd8c3
It contains a list of many 'offset' values that can be used with that method.


_33(Posted 2007) [#4]
So, I suppose the proper logic of doing things in Blitz3D is to build my texture in an image, and then move the image into a texture in GDDR (flag 256). Talking aboutr stuff like procedural texturing, and building a Font texture to be used on vertexes.


b32(Posted 2007) [#5]
As I understood, the most compatible way of doing this is drawing everything to the backbuffer, and then use CopyRect to copy it onto the texture. Other methods (using SetBuffer) might not work on some machines.


_33(Posted 2007) [#6]
I see. I've tried creating an image, and building my fonts using that, and then copying that to the texture space in GDDR, but there were problems.

The first problem was that I lost my alpha values! That is a big minus (thumbs down) for this method.

The second thing I found was some glitches on the textures on the top left corner (some rare textures). I've checked my functions and nothing seems wrong there.

So I'll definately try the backbuffer version and see if that works.

But, it is much faster than WritePixelfast, already, with Tom's technique to plot pixels on an image space.

EDIT: Same with the backbuffer, I loose my alpha values. Also, copying from backbuffer to texturebuffer is incredibly slow, compared to working with an image buffer. Probably what happens, since the backbuffer is in video memory, it copies the backbuffer to the main memory and then performs the CopyRect, for every CopyRect! So, it is slow...


Stevie G(Posted 2007) [#7]
If you're not willing to use read/writepixelfast you've no chance of retaining alpha information.

Before you rule out this method, can you explain EXACTLY what you are trying to do?

Stevie


_33(Posted 2007) [#8]
Before you rule out this method, can you explain EXACTLY what you are trying to do?


I'm trying to save the 3 or 4 seconds it takes for my software terminal to initialize it's internal fonts. Actually, it's 3 or 4 seconds on my 2.8 Ghz Opteron, it might be 6 or 8 seconds on a P4, or 15 seconds on a P3 ;). All this, specifically because I'm using WritePixelFast.

I wanted to avoid writing BMP files with the fonts in there, but it seems I have less and less choice, because of the way Blitz3D works.

By the way, I am already using WritePixelFast since the time I began this project and added software generated bitmap fonts. It's just getting more and more obvious that this is too slow.

Now Stevie G, I don't know what exactly you're asking me. You can always read my notes in the worklog and see where I'm at. I don't see what sort of a solution you can come up to, other than "save your fonts on the first build to bitmap, that way the next time it runs, it will just load them into vram..."

BTW, the ALPHA values are VERY important for transparency of the characters. Reason for this is because the terminal is in 2D but overlays the 3D scene. Meaning that I can't have a black square with a letter inside. So, putting transparency using the alpha is possibly the best way to do this. Unless, I overlooked something.


ShadowTurtle(Posted 2007) [#9]
Precompile your Font and load it simply via loadimage / loadtexture (some flag)...

*beaten*


Stevie G(Posted 2007) [#10]

Now Stevie G, I don't know what exactly you're asking me. You can always read my notes in the worklog and see where I'm at. I don't see what sort of a solution you can come up to, other than "save your fonts on the first build to bitmap, that way the next time it runs, it will just load them into vram..."



I think it's clear that I'm simply trying to help you but your response has made me none the wiser and I don't have time to trawl through your worklog.

Is there a reason why you don't want to save the bmp image of the font(s) and load them in as textures with the ( mask or alpha ) & vram flags set? I'm assuming your using 2d-in3d to display the text.

If I'm missing the point ignore me and I'll leave the thread for those fluent in esperanto.

Stevie


_33(Posted 2007) [#11]
Stevie G, I respect your work. Now my work is specific. It's like procedural texturing. I build my fonts in the init bootstrap. I could save them and load them from the HDD, but then it's impractical. The reason I'm building my fonts from some bits of values is that I can implement shadow and contour while I'm building the font using alpha values, from options in my system. If the bitmaps are already done, I'd have to have a bitmap for every case and have a way to manage the bitmaps and loading/saving, which would be uber clumsy.


Stevie G(Posted 2007) [#12]
Ah .. ok, I see where you're coming from, now that makes much more sense! I completely agree that this is indeed a pain in the rear.

I ran into similar problems when writing a 2d-in-3d single surface, pixel perfect GUI lib. I didn't want to store loads of different fonts and sizes etc... In the end I only needed to have 3 font sizes stored on one bitmap. I created numerous other fonts from these by changing the vertex colours of each quad ( one per letter ). This also allows you to have a nice contour blend ....



Not sure how you would go about applying your shadow effect but if you feel that this technique may help then let me know.

Cheers
Stevie