d3d9 Sprites Upside Down...

This is a discussion on d3d9 Sprites Upside Down... within the Game Programming forums, part of the General Programming Boards category; So my texture wrappers finally doing what it's told... except that all of the textures are upside down. I did ...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    Thumbs up d3d9 Sprites Upside Down...

    So my texture wrappers finally doing what it's told... except that all of the textures are upside down. I did a little googling and Microsoft says that all .bmp's are rendered upside down, but that was back in Direct3D 3. Anyways, how do I get around this one? I will post code if need be.

    Help is much appreciated!

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You have your u,v coords reversed. Regardless of how the data is stored in memory the final determinant in orientation is the u,v coords. I suspect you have the v portion of your u,v's in the reverse order of what they should be. A triangle strip for a quad using counter clockwise culling will be in this order: top left,top right,bottom left,bottom right

    Here are the correct coords for a unit quad in local space using D3DPT_TRIANGLESTRIP.

    Format is x,y,z,u,v.

    -1.0f,1.0f,0.0f,0.0f,0.0f
    1.0f,1.0f,0.0f,1.0f,0.0f
    -1.0f,-1.0f,0.0f,0.0f,1.0f
    1.0f,-1.0f,0.0f,1.0f,1.0f

    Projection matrix:

    Code:
    D3DXMATRIX matProj;
    D3DXMatrixOrthoOffCenterLH(&matProj,left,right,bottom,top,znear,zfar);
    
    m_pDevice->SetTransform(D3DTS_PROJECTION,&matProj);
    Last edited by VirtualAce; 04-06-2009 at 07:07 PM.

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Thanks, I just realised that I was using D3DXMatrixPerspectiveFovLH instead of D3DXMatrixOrthoOffCenterLH. Anyways, I changed it and now I can't see anything at all. Here's how I am setting it all up:

    Code:
    D3DXMATRIX P;
    RECT R;
    GetClientRect( mhMainWnd, &R );
    float width  = (float)R.right;
    float height = (float)R.bottom;
    
    D3DXMatrixOrthoOffCenterLH( &P, 0.0f, width, height, 0.0f, 0.0f, 1.0f );
    HR( gd3dDevice->SetTransform( D3DTS_PROJECTION, &P ) );
    
    HR(gd3dDevice->SetRenderState( D3DRS_LIGHTING, false ) );
    I've tried putting my textures at a couple of coordinates that I think should appear but they don't.

    Also, I haven't been using D3DPT_TRIANGLESTRIP. I've been drawing with ID3DXSprite:: Draw() which hasn't requested the type of coordinates I think you're talking about.
    Last edited by yaya; 04-04-2009 at 05:21 PM.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    After using that projection matrix all your sprites will be expressed in screen coordinates and will always lie in the 4th quadrant.

    If you are using ID3DXSprite then the transformations will be taken care of for you.

    For 2D you must translate back to the origin, rotate, scale, and then translate back to the screen coordinates. If you want to have a center of rotation then do not translate back to the origin and translate the center of rotation expressed as an offset from the center of the object.

    Translating back to 0,0,0 and rotating will rotate about the center of the object. Translating back to any other location than 0,0,0 and rotating will result in an off-center rotation.

  5. #5
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    I'm still having all the same problems. I'll post the very bare code I use to draw it in Ortho. Hopefully you can see something out of place.

    Code:
    	// Calculate screen size
    	D3DXMATRIX P;
    	RECT R;
    	GetClientRect( mhMainWnd, &R );
    	float width  = (float)R.right;
    	float height = (float)R.bottom;
    
    	// Set up camera
    	D3DXMatrixOrthoOffCenterLH( &P, 0.0f, width, height, 0.0f, 0.0f, 1.0f ); 
    	HR( gd3dDevice->SetTransform( D3DTS_PROJECTION, &P ) );
    	
    	// This is all the drawing stuff (this happens when everything else is drawn)
    	ID3DXSprite* Sprite = NULL;
    	HR( D3DXCreateSprite( gd3dDevice, &Sprite ) );
    	HR( Sprite->Begin( D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DONOTMODIFY_RENDERSTATE ) );
    	HR( Sprite->Draw( GetTexture( temp.TextureID ), NULL, &GetCenter( temp.TextureID ), &temp.Position, temp.Color ) ); // GetTexture return IDirect3DTexture9*
    	HR( Sprite->Flush() );
    	HR( Sprite->End() );
    	
    	// Add textures
    	// defined: void MakeSprite( int Tex_ID, float x, float y, float z, short r, short g, short b );
    	MakeSprite( AddTexture( "test.bmp", 128, 128 ), 10.0f, 10.0f, 0.0f, 255, 255, 255 );
    	
    	// Drawing everything
    	onResetDevice();
    	HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0));
    	HR(gd3dDevice->BeginScene());
    	
    	DrawSprites(); // This draws all the sprite stuff from before
    
    	HR(gd3dDevice->EndScene());
    	HR(gd3dDevice->Present(0, 0, 0, 0));
    This all compiles fine in both Ortho and Perspective but nothing appears in Ortho.

    Thanks a bunch.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. DirectX and Sprites
    By andyhunter in forum Game Programming
    Replies: 6
    Last Post: 12-24-2004, 06:40 PM
  3. I Found some nice sprites but need more...
    By BigCheese in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2004, 06:03 PM
  4. Sprites and different formats?
    By Tommaso in forum Game Programming
    Replies: 6
    Last Post: 11-01-2002, 12:33 AM
  5. Animating Multiple Sprites
    By Tommaso in forum Game Programming
    Replies: 2
    Last Post: 10-11-2002, 01:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21