Converting an Image to a texture

Blitz3D Forums/Blitz3D Beginners Area/Converting an Image to a texture

nivek(Posted 2004) [#1]
How do I convert an image loaded into Blitz into a texture?

This is what I want to do: I want to take the texture from a mesh convert it into an image, add a bullet hole, convert it back to a texture and apply it to the mesh.

I've been trying to add a bullet hole to a mesh for over a week and nothing seems to work. I've tried sprites but when the mesh is animated (falling down) the sprite hangs in mid air above the mesh. I thought image drawing might work but I can't use the image as a texture directly and saving it to disc would slow down my game too much. It all has to happen in a fraction of a second.

Thanks


GfK(Posted 2004) [#2]
SetBuffer TextureBuffer(texture)
DrawImage imgBullet,X,Y
SetBuffer BackBuffer()



nivek(Posted 2004) [#3]
How do I apply the texture back to the mesh? When I apply the texture back to the mesh the bullet hole (bh) doesn't show up. What am I doing wrong?

Here's my code:

If MouseHit(1) Then
bodtex=LoadTexture("Body.jpg")
bh=LoadImage("bh.bmp")
SetBuffer TextureBuffer(bodtex)
DrawImage bh,MouseX(),MouseY()
SetBuffer BackBuffer()
EntityTexture m,bodtex
EndIf

Thanks


GfK(Posted 2004) [#4]
you're drawing the bullet hole at the wrong coordinates, i'd say.

MouseX() and MouseY() are most likely returning values which lie outside the boundaries of the texture.


nivek(Posted 2004) [#5]
I tried 0,0 100,100 200,200 300,300 400,400 500,500 and I changed the bh image to an 800,600 black image so if it worked I would be able to see it no matter were it is. But it still doesn't work. What else can I try. Can I save the altered texture to an image file? That way I can inspect it more closely.

All this worked great when I was using 2D image commands but I couldn't use the image as a texture without first saving it to a file. Is there a way to convert an image directly to a texture from within Blitz3D?

Thanks


GfK(Posted 2004) [#6]
You can use CopyRect to copy part/all of an image to a texture (and vice versa).

It won't copy alpha data though (no alpha channel in 2D images).


nivek(Posted 2004) [#7]
That worked but the texture no longer fits the mesh.

If MouseHit(1) Then
bodtex=LoadImage("Body.jpg")
bh=LoadImage("bh.bmp")
bod=CreateTexture(600,600)
SetBuffer ImageBuffer(bodtex)
SetBuffer TextureBuffer(bod)
DrawImage bodtex,0,0
DrawImage bh,MouseX(),MouseY()
CopyRect(0,0,600,600,0,0,ImageBuffer,TextureBuffer)
EntityTexture m,bod
EndIf

Thanks


Warren(Posted 2004) [#8]
A 600x600 texture will be automatically resized to 1024x1024 internally. That's probably why your texture coordinates are off.


nivek(Posted 2004) [#9]
So then how do I fix it?

I'll never understand why something that should be so simple has to be so difficult!

Thanks


Warren(Posted 2004) [#10]
Video cards require textures to be powers of two. Always have and probably always will. I don't mean to offend, but this Game Development 101 material here.

The solution would be to resize your texture to be a power of two.


nivek(Posted 2004) [#11]
I guess you can tell I'm new to 3D programing.
Thanks


Warren(Posted 2004) [#12]
We all were at one time. :) Stick with it, it gets easier...


AntonyWells(Posted 2004) [#13]

Video cards require textures to be powers of two. Always have and probably always will.


Umm...textureRect? The only downside to a non power of 2 texture is your uvs are mapped in real pixel space, rather than 0 to 1.

(B3d can't use 'em, but video cards do support them, and now.)


Warren(Posted 2004) [#14]
If by "B3D" you mean "Blitz3D", that's incorrect. It does support them but it stretches them internally to the proper size.

Non-powers of two is not something that is widely supported on the hardware end. We aren't even contemplating using it at Epic ... for the next 2 or 3 foreseeable games, we're sticking with power of two textures.


AntonyWells(Posted 2004) [#15]
Well it's not really using textureRect(The gl/nvidia term for it..no idea what dx calls them), it's just rescaling the image data to be power of 2, then using a normal texture.(I think..)

Btw, why not use them at epic? I mean unreal24k made my g5 work hard, so it's not like really old cards can run it anyway? Unless non power of 2 texture's is a very new addition..but the nvidia specifc extension is dated 2000. before the g2. Ati support no good? (I plan on using them for vivid, not just being pedantic..)


Warren(Posted 2004) [#16]
I mean unreal24k made my g5 work hard, so it's not like really old cards can run it anyway?

Well, yeah, actually they can. Turn the details down and UT2k4 will run on as low as a Voodoo3. It won't be pretty, but it will run.

As for using them, well, the artists are so used to powers of two at this point there's really no compelling reason to change...