Jump to content
  • Advertisement

Archived

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

monkeyography

tiled texturing newbie

This topic is 5579 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''m trying to draw a tiled floor by having a texture repeat on a two-triangle square. However, the whole square just adopts the color of the texture at pixel (0,0). this is my custom vertex:
struct TexVertex
{
    D3DXVECTOR3 pos;
    D3DXVECTOR3 norm;
    int tu, tv;
    TexVertex( const D3DXVECTOR3* posIn, const D3DXVECTOR3* normIn, int tuIn,
               int tvIn )
        : pos( *posIn ), norm( *normIn), tu( tuIn ), tv( tvIn ){}
    TexVertex& operator=( const TexVertex& in )
        { pos = in.pos; norm = in.norm; tu = in.tu; tv = in.tv; return *this; }
};
#define D3DFVF_TEXVERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_NORMAL )
This is where I set up the vertex buffer:
    // set up floorBuf

    TexVertex floorVertices[] = 
    {
        TexVertex( &D3DXVECTOR3( 0, 0, 0 ), &D3DXVECTOR3( 0, 0, -1 ),
                   0, tiles ), // bottom left

        TexVertex( &D3DXVECTOR3( 0, Globals::tileSize * tiles, 0 ),
                   &D3DXVECTOR3( 0, 0, -1 ), 0, 0 ), // top left

        TexVertex( &D3DXVECTOR3( Globals::tileSize * tiles, 0, 0 ),
                   &D3DXVECTOR3( 0, 0, -1 ), tiles, tiles ), // bottom right

        TexVertex( &D3DXVECTOR3( Globals::tileSize * tiles,
                                 Globals::tileSize * tiles, 0 ),
                   &D3DXVECTOR3( 0, 0, -1 ), tiles, 0 ) // top right

    };
    void* pFloorVertices;
    
    if( D3D_OK != pd3dDevice->CreateVertexBuffer(
                        4 * sizeof( TexVertex ), 0,
                        D3DFVF_TEXVERTEX, D3DPOOL_DEFAULT, &floorBuf ) )
        throw "FAILED to allocate vertex buffer for floor";

    if( FAILED( floorBuf->Lock( 0, sizeof( floorVertices ),
                                (BYTE**)&pFloorVertices, 0 ) ) )
        throw "FAILED to lock vertex buffer for floor";

    memcpy( pFloorVertices, floorVertices, sizeof( floorVertices ) );
    floorBuf->Unlock();
and here''s where I draw the floor:
    D3DMATERIAL8 floorMat = { { 1.0f, 1.0f, 1.0f, 1.0f, },
                             { 1.0f, 1.0f, 1.0f, 1.0f, },
                             { 0.0f, 0.0f, 0.0f, 1.0f, },
                             { 0.0f, 0.0f, 0.0f, 1.0f, }, 0.0f, };
    pd3dDevice->SetMaterial( &floorMat );

    pd3dDevice->SetTexture( 0, tileTex->getResource() );

    pd3dDevice->SetStreamSource( 0, floorBuf, sizeof( TexVertex ) );
    pd3dDevice->SetVertexShader( D3DFVF_TEXVERTEX );
    pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
The program''s already pretty extensive (despite my ignorance on these simple things) because I''ve been loading all graphics till now from .x files. Chances are most likely that I''ve messed up something simple but if everything seems aok then it''s possible a default setting necessary to simple texture tiling was changed somwhere. Thanks for any help

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure if this helps, but I figure I''ll offer what I''ve go LOL.

For a texture to "tile" the specifed texture coordinates must be greater than 1.0. I believe you are using 0 and for your texture coords... if you used 0 and 2, it will tile twice.

Share this post


Link to post
Share on other sites
figured it out. I hate how such stupid things are always so frustrating. I needed the texture coordinates in my custom vertex to be floats rather than ints. problem solved

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!