Jump to content
  • Advertisement
Sign in to follow this  
bobbinus

about texture coordinates

This topic is 4878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I have a Box class in my game that represent simple boxes in the game world. Because there are many of them I use a static mesh member so all instances share this(ie. therefore they share the same tex coords too). x,y,z members record the dimensions of each box so that when i render them i just use an appropriate scaling matrix. Now the sticky part: I want the texture i use to be repeated(wrap address mode) but ensuring that in world space the texture image(some bricking) is always the same size. So currently as i scale each box the result is that the image is simply stretched. I know that for each rendering operation of each box i can Lock() the vertex buffer and maniupalte the tex coords so that I can solve this problem however this seems like it might be a little too much unneccessary effort on the hardware. I thought maybe there was a smarter way to do this, possibly using SetTextureStageState() but i can't find it..(prefer noit to use shaders either plz). Thankyou ;p

Share this post


Link to post
Share on other sites
Advertisement
I may have misread what you said, but here's my attempt:


D3DXMATRIX TexMatrix;
D3DXMatrixScaling(&TexMatrix, BOXWIDTH / TEXTURESIZE, BOXHEIGHT / TEXTURESIZE, 1.0f);
g_D3D.GetDevice()->SetTexture(0, pTexture);




In my test, I had a 128x128 and a 32x32 texture. I set this and it tiled it 3 time s in each direction.

Share this post


Link to post
Share on other sites
I assume u r applying this as:
g_D3D.GetDevice()->TexMatrix( D3DTS_TEXTURE0 , &matScaling );

I am currently trying to solve the problem this way but i think its a dead end. The problem here is that each box has 3 scalable dimensions: width,height and,depth(and all 3 will generally be different for each instance of the box). So basically 2 texture coordinates(u,v) will always be scaled by the width(x)and height(y) of the box no matter which vertex is bing operated on. This means only one face of the box can be textured without distortion of the original texture(in this case the z face).

I have been at this problem all day and I am just about worn out. I thought the solution would be simple at first but the more dead ends I run into the more convinced I am that this situation is an impossible one... ;((((

Simply because the box is made up from 24 vertices(4 per face), to mainpulate the vertex texture coordinates correctly it needs to be done for each face. So vertices on the z face need to be scaled by the x,y dimensions of the box and so on. So a per vertex solution is needed which i think means a shader would be the only hope. Highly doubtful that a shader could do this but its been a while since i used them.

As far as i can see the only simple way is to have a mesh object for each box object, lock and manipulate the tex coords once. Seems it must be better than locking for each render just for the sake of only having one mesh object for all boxes....

Share this post


Link to post
Share on other sites
Oops, I forgot that line. But its actually D3DTS_TEXTURE1. From what I read the texture addresses at 0 means no coordinates (I don't know why they would do this, but that is just what I read in a texture or book or something.)

Share this post


Link to post
Share on other sites
No m8, D3DTS_TEXTURE0 means to apply this transform to texture stage 0. ie the first stage. D3DTS_TEXTURE1 would apply this transform to texture stage 2 if u had that.

Share this post


Link to post
Share on other sites
That makes sense, but the code works fine for me.

Edit: Thats because I'm done and this was the first time I had used this. For some reason stating any stage works fine.

Can you explain why its not working? Is is rendering incorrectly?

Share this post


Link to post
Share on other sites
I cant do it immediatly but i am pretty sure that wont do the job ocmpletly. The problem is that this line:
D3DXMatrixScaling(&TexMatrix, BOXWIDTH / TEXTURESIZE, BOXHEIGHT / TEXTURESIZE, 1.0f);

only takes into account the height and width. So the Z axis faces will be treated correctly because their tex coords should be scaled by this. However the the Y axis faces should have their u,v coords scaled by the width and depth of the box....similarly the X axis faces should be scaled by height and depth.

assumes x axis is width, y axis is height, z axis is depth

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!