2 Questions to Textures

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
X-prt
Posts: 7
Joined: Wed Oct 10, 2007 6:20 pm

2 Questions to Textures

Post by X-prt »

I searched a while in the Forums and found a few Threads about texture-scrolling and everytime it's said to should work doesn't
that's exactly my first problem...
that stands in the main-loop:

Code: Select all

cube->getMaterial(0).getTextureMatrix(0).setTranslation(core::vector3df(x,y,0));
y+=0.01f;
x+=0.01f;
no effect.
also no effect by using setTextureTranslate(x,y);
(rotation works, scaleing too, somehow... i don't understand that scaling-thing... i know what it should do but everytime i tried it with different scaleings the texture then was just one-colored and thats all)

my second problem is that i want to draw on textures in runtime...
how do i do that?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

my second problem is that i want to draw on textures in runtime...
how do i do that?

Code: Select all

// get pointer to texture data
u32* p = (u32*)texture->lock();

// get color of pixel
video::SColor color = p[i];

// set new color to pixel
p[i] = color.color;

// unlock texture
texture->unlock();
This code is for 32 bit color mode texture. Other modes work similar just force return value of lock() function to apropirate type.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I've never really tried to use the texture matrix methods provided, but I'd start debugging by trying buildTextureTransform().

EDIT: Actually, it is quite obvious that setTextureTranslate() is wrong. You can see it quite clearly if you compare it to buildTextureTransform(). In setTextureTranslate() the translation is set into the third column of the matrix, but buildTextureTransform() uses the third row. It should be the third row, but it looks like someone transposed the matrices or got them from an OpenGL tutorial. i.e. setTranslation() modifies M[2] and M[6], but it should be modifying M[8] and M[9].

You should put a post in the Bugs forum and link back to this topic.

Travis
vi-wer
Posts: 93
Joined: Sun May 20, 2007 7:15 pm
Location: Germany
Contact:

Post by vi-wer »

There seems to be another bug in texture translation. When using OpenGL driver the UVCoords are translated into a different y-direction than when using Direct3D. Or is it supposed to be corrected by setTextureTranslate() ?
However here's a code snippet I'm using for correct texture translation for now:

Code: Select all

matrix4 mat;
float xtrans = 0.2f;
float ytrans = 0.4f;

// translate texture coords
mat(2,0) = xtrans;
if( m_driver->getDriverType() == video::EDT_OPENGL )
   mat(2,1) = -ytrans;
else
   mat(2,1) = ytrans;
X-prt
Posts: 7
Joined: Wed Oct 10, 2007 6:20 pm

Post by X-prt »

thanks a lot... all problems solved

that scrolling works now, but it scrolls all my textures...
i have no idea why, because the object orientated call on this method should only transform the texture from the object, that it was called on, shouldn't it?

is there any good way of using drawing-functions or methods on that array i get from ->lock()?

because i want to write text on it
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You get access directly to pixels with lock() so you can do anything you vant by editing pixels. Pixels are stored like simple array so if you want to get pixel from 2d coordinates you must do some simple math. Should be something like:

Code: Select all

pixelindex = ycoord * texturewidth + xcoord
No functions like text writing out there. You have to code it yourself. But that wont be difficult, just take texture with text and copy it on your object texture. With some necessary offset of course.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Unless you're just writing text to the texture, I'd suggest using render to texture.

Travis
X-prt
Posts: 7
Joined: Wed Oct 10, 2007 6:20 pm

Post by X-prt »

i thought of rendering to the texture.
but i thought that could be slow...

okay it'll not be too slow, i think.

do you have any idea, why there are scrolled all my textures, instead of only the one i use the method on? (is that correct english :oops: ?)

thanks a lot again for helping me out
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, the translation access is fixed, I now have to check for the wron orientation.
jef
Posts: 18
Joined: Sat Nov 13, 2004 10:10 pm

Post by jef »

do you have any idea, why there are scrolled all my textures...
That problem was fixed in Irrlicht 1.4. It sounds to me that
You are using Irrlicht 1.3.1 or an older version.

If so, try with Irrlicht SDK 1.4 beta.
http://prdownloads.sourceforge.net/irrl ... p?download
X-prt
Posts: 7
Joined: Wed Oct 10, 2007 6:20 pm

Post by X-prt »

yes you're right, jef

i'm using 1.3.1

ok i'll try the beta.

thanks for the info
Post Reply