TextureName is Broken

Started by Kippykip, July 30, 2019, 12:21:03

Previous topic - Next topic

Kippykip

I can't seem to get TextureName to work, it returns a bunch of weird characters, but not the file path of the loaded texture like it should.
Returns "���"
when it should return something like
"wcrate.jpg"

Here's a mini example
Import openb3dmax.b3dglgraphics
Graphics3D(640, 480, 0, 32)
Local texturemanual:TTexture = LoadTexture("wcrate.jpg")
Print TextureName(texturemanual)


Here's the Blitz3D equivalent
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
texturemanual = LoadTexture("wcrate.jpg")
DebugLog TextureName(texturemanual)
RenderWorld
Flip
WaitKey


I tried messing about with the EntityName code to try and fix the TextureName function, but I don't really understand C++ much and just kept getting the same results.
Most success I had was adding these to texture.cpp
#include "bmaxdebug.h"

string Texture::TextureName(){
DebugLog(file);
DebugLog(file.c_str());
return file;

But that's not setting the var of course, just outputting it to the BlitzMax console which does have the right path.

markcwm

You were nearly there, all you needed was "return tex->file.c_str();"

The file member (field) is a C++ string and has to be converted to a C string (char array), a slightly different format, this can then be read by BMax as a pointer to the array and converted to a Blitz string with FromCString function.

Should be fixed in latest commit but only tested in Linux.

Kippykip

Quote from: markcwm on July 31, 2019, 02:15:35
You were nearly there, all you needed was "return tex->file.c_str();"

The file member (field) is a C++ string and has to be converted to a C string (char array), a slightly different format, this can then be read by BMax as a pointer to the array and converted to a Blitz string with FromCString function.

Should be fixed in latest commit but only tested in Linux.
Ah damn hahaha, I was trying all sorts of stuff. Thanks for fixing it!
Now I can add animated map textures commands into my virtual console! :D

Kippykip


markcwm

Great, I'm not sure how you need TextureName for this but I did enjoy the video.

Kippykip

Quote from: markcwm on July 31, 2019, 23:40:58
Great, I'm not sure how you need TextureName for this but I did enjoy the video.
Ah, well basically I made this console command that scans every texture on each surface on the map mesh when called, and if a filename matches with TextureName(), then that surface is added to this ANIMTEX type with a list of surfaces where it changes the texture frame at a set rate.
Because otherwise I'd probably have to hardcode the map mesh's surface index number for what textures I want to animate, and everytime I'd make a change and re-export the model the surface index numbers would change. This is just an easy way of doing it for me.

The ingame console command works like this:
Map.AnimTexture ReplacementTexture$ NewTexture$ FrameWidth# FrameHeight# Count# Delay# TexFlags#
A real example I used in the video is this:
Map.AnimTexture fwater1 fwater 64 64 4 15 1

Once again thanks for fixing that command! ^-^