Change Texture on mesh does not work

Blitz3D Forums/Blitz3D Programming/Change Texture on mesh does not work

Nikko(Posted 2004) [#1]
Hi all

When I try to assign a different texture to a previously textured mesh, I can't remove the old texture to replace ti with the new one.

Let's say .

t1=Loadtexture("tex1.jpg")
entitytexture cube,t1
freetexture t1
t2=Loadtexture("tex2.jpg")
entitytexture cube,t2

This does display the old t1 texture and not teh new one.
Am I doing a mistake somewhere.


Ross C(Posted 2004) [#2]
I don't think you can do that. Texture over a prevoiusly textured mesh. I'm not sure tho...


Nikko(Posted 2004) [#3]
so if I do a mesh editing sofware for example, each time I assign a texture to a mesh (to test if the texture is ok or not) I need to clear the mesh and re load or recreate it???

Amazing!


TeraBit(Posted 2004) [#4]
Not true at all



Works perfectly here! Perhaps posting a more complete code sample which demonstrates the problem. It's easy to miss something obvious!


Nikko(Posted 2004) [#5]
Here is the source code (the application is very big with a complex user interface, so the code will not work as this).

; this idea is to apply a filter (like seamless, blur, HSV, Bump, contrast etc...) to a texture and display the result in real time on a 3d model.

; clean the previously loaded textures and imags
If originaltexture<>0 Then FreeTexture originaltexture
If originalimage<>0 Then FreeImage originalimage
If processedtexture<>0 Then FreeTexture processedtexture
If processedimage<>0 Then FreeImage processedimage EndIf

; I load the the texture and the image (both 2d and 3d results are shown
processedtexture=LoadTexture(tmpcurrent$)
processedimage=LoadImage(tmpcurrent$)

;get the address of the texture and image buffers
processedtexturebuffer = TextureBuffer(processedtexture)
processedimagebuffer = ImageBuffer(processedimage)
; here I call the filters that will process the image internaly
ProcessBuffer(processedtexturebuffer)
ProcessBuffer(processedimagebuffer)

; now if I display the processed result like this
EntityTexture Cube,processedtexture
EntityTexture Sphere,processedtexture


Each time I change the filters I create a new texture and I want to remove the old one and replace with the new one. So I call the code above to
1-clear the old textures and image (because I display the 2d and 3d results
2-load the original texture and image
3-apply the filters to both of them
4-use entitytexture to change the 3D sample.

The 2D image is refreshed correctly, but the 3d model keep always the first processed texture.

1- I display the original : it works.
2- I display the processed result : it work
3- * nothing else will work then even to display back the original.

It seems like if the texture can be changed if the variable name changes (processedtexture <> originaltexture)
But if I freetexture the processedtexture and load another one, it is like if the freetexture was working only for memory but not for VRAM and that the model is still with the freeed texture...

I hope it is clear... it is not easy to explain.


AntonyWells(Posted 2004) [#6]
It's because when you add a texture, blitz adds it to the first empty texture slot, and then incs the index by 1.

So when you retexture over it, you're in fact setting the second texture.(That's my theory anyway.)

Anyway, just do this, I have done hundreds of time and it defnitely works.

EntityTexture MYEntity,MyTexture,0,0 ;Last par=texture index. first 0 =frame number. Always leave that at zero unless you're using a animated texture.

Then, just call the same thing to replace it,

EntityTexture myEntity,newTexture,0,0


Ross C(Posted 2004) [#7]
Sorry for the inaccurate help :o(


Nikko(Posted 2004) [#8]
Well I must say that you are right, the bug must come from somewhere else in my program. I've made 2 programs to stress test the textures and it works perfectly...


Here are they with the media included.
http://www.nikkopay.com/blitz/testtextures.zip


Beaker(Posted 2004) [#9]
SpacedMan is wrong. Blitz doesn't increment the texture index.


AntonyWells(Posted 2004) [#10]
I'm never wong.


John Blackledge(Posted 2004) [#11]
My experiments to re-texture entities (or terrains) found only possible if each new texture had a different name.


jfk EO-11110(Posted 2004) [#12]
yes, if you are oading a texture twice (and even if you edited the file meanwhile) blitz will make use of optimized vram usage and use the first texture instead - at least IF both textures use the same flags.

What you describe sounds very much like a bug in your code.