Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Infinite Monkey

DirectX Texture Matrices

This topic is 5539 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

I am attempting to write a DirectX version of my OpenGL renderer. When I am drawing some stuff, I use the texture matrix to select a part of a texture to be rendered. E.g. I render a button as 9 quads in a 3x3 grid, with each small quad having a small part of the button texture. This allows me to render arbitrarily large buttons with the same button texture without the corners or edges going wrong. This all works just fine in the original OpenGL renderer, but in the DirectX renderer, I just get 9 copies of the button texture in the 3x3 grid, so instead of rendering the top left corner of the texture into the top left quad, its rendering the whole texture into the top left quad. The code I''m using looks something like this: mTextureMatrixStack->TranslateLocal((float)tx, (float)ty, (float)tx); mTextureMatrixStack->ScaleLocal((float)sx, (float)sy, (float)sx); mD3dDevice->SetTransform(D3DTS_TEXTURE0, mTextureMatrixStack->GetTop()); Why is this transformation not affecting the texturing?

Share this post

Link to post
Share on other sites
If I stick in a line :

the buttons quads look less wrong. Instead of rendering the whole texture in each quad, I''m only getting some of each texture in each quad, but the part of the texture I;m getting is still wrong.

Share this post

Link to post
Share on other sites
I''m not nearly as advanced in programming as you, but from what I know, you must utilize tu and tv to set the location of each point on the image you want to use, with tu being the being the vertical and tv being the horizontal position on the texture. tu at 0 is the left of the image and tv at 1 is the bottom of the image. It looks as though OpenGl has a shortcut for this method to wrap an image across an entire set of primitives, I would suggest asking in IRC, but perhaps if you buffer in all of the verticies of your grid and call some sort of texture wrap for the single DrawPrimitive you might find the result you''re looking for.

- Valles

if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&h_Vertices, 0 ) ) )
return E_FAIL;

h_Vertices[0].x = curX;
h_Vertices[0].y = curY;
h_Vertices[0].z = curZ;
h_Vertices[0].color = 0xffffff;
h_Vertices[0].tu = 0.0;
h_Vertices[0].tv = 1.0;
h_Vertices[1].x = curX;
h_Vertices[1].y = curY+distTile;
h_Vertices[1].z = curZ;
h_Vertices[1].color = 0xffffff;
h_Vertices[1].tu = 0.0;
h_Vertices[1].tv = 0.0;
h_Vertices[2].x = curX+distTile;
h_Vertices[2].y = curY;
h_Vertices[2].z = curZ;
h_Vertices[2].color = 0xffffff;
h_Vertices[2].tu = 1.0;
h_Vertices[2].tv = 1.0;


if(thisInt < 0 || thisInt > 11)
MessageBox(NULL, m_strFrameStats, "ok", MB_OK);

g_pd3dDevice->SetTexture( 0, tGrid[thisInt] );
g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!