XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Sprite scaling

Last post 12/07/2009 15:53 by legalize. 2 replies.
  • 06/06/2009 13:54

    Sprite scaling

    This might been asked/answered before, but done quick search and could not find.

    Im currently working on a 2D gui system for D3D10 and looking into using sprites instead of vertex buffer i lock/update each control be drawed.
    I pretty much copied the code from the DXUT framework to get my sprite drawn but noticed something strange about the sprite scaling.

    My application is running in windowed mode: 800x600
    I have a texture loaded to use as background (fill entire render screen) wich is: 1024x786 dimension.

    This is my code for drawing the background image:
    Notice the line: D3DXMatrixScaling( &matScaling, 2.0f, 2.0f, 1.0f );

    So am i doing something wrong here or is it normal that the scale must be 2.0 for filling the entire screen?


    g_pSprite->Begin( 0 );

    g_pEffect->GetTechniqueByIndex( 0 )->GetPassByIndex( 0 )->Apply( 0 );

    D3DXMATRIXA16 matScaling;
    D3DXMATRIXA16 matTranslation;
    D3DXMatrixScaling( &matScaling, 2.0f, 2.0f, 1.0f );
    D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 0.5f );

    D3DX10_SPRITE Sprite;
    Sprite.matWorld = matScaling * matTranslation;
    Sprite.pTexture = g_pTexture;
    Sprite.TexCoord.x = 0.0f;
    Sprite.TexCoord.y = 0.0f;
    Sprite.TexSize.x = 1.0f;
    Sprite.TexSize.y = 1.0f;
    Sprite.TextureIndex = 0;
    Sprite.ColorModulate = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 0.5f );

    g_pSprite->DrawSpritesBuffered( &Sprite, 1 );

    g_pSprite->End();

  • 11/07/2009 10:22 In reply to

    Re: Sprite scaling

    To me it sounds logical, if you have 800x600 pixels, how can you render a 1024x768 pixel texture? impossible to view it all atone since you don't have pixel to cover the entire texture! so you have to reduce the pixels to show the entire texture.

    but what the problem is i don't understand, that your texture is beeing reduced to the half scale? or is somthing else happening?
    Whow, thats a big memory leak...
    It sure is! and we are sinking!

    kartflygaren675@hotmail.com
  • 12/07/2009 15:53 In reply to

    Re: Sprite scaling

    Looking at the documentation for ID3DX10Sprite, its not clear what coordinate space the TexSize member is using. However, I don't see how scaling by a factor of 2.0 is going to be correct. If your intention is to match the 1024x768 image 1:1 to the 800x600 window, then you need to scale it by 800/1024 (which is the same as 600/768) if we were talking about a coordinate space in pixels.

    However, getting the right transformation requires knowing what coordinate space you're starting with since transformations map from one coordinate space to another. You can't get the desired output if you don't know what input coordinate system is being used.

Page 1 of 1 (3 items) Previous Next