Original Post
Hi there,
I''ve been trying to learn DX8, so I thought I would just create a background and slap a sprite on it as an example. However, I''m running into problems sizing them correctly. I''ve heard the arguements to just use DX7, but I would really like to figure this out in DX8 (since I''m already familiar with DX7).
I can get the background to display properly if I use D3DXCreateTextureFromFile(...), SetTexture(...), & DrawPrimitiveUP(...). I''m sure I can get the sprite to display properly using the same method, but I wanted to use D3DXSprite::Draw(...) because it allows you to specify a rectangle in the texture to use as your sprite (rather than the whole thing). So when I use D3DXCreateTextureFromFile(...), D3DXCreateSprite(...), & Draw(...), the sprite appears but is sized wrong (way too large, even though the scaling should have been the normal default size). So I changed the scaling down, but could never quite get it right - the sprite was always just a little off. So, just to experiment, I tried to do the background using the same method of using a sprite - just to see what would happen. When I used the default scaling, my 800x600 background was way too large and went off my 800x600 screen. So I put the scaling to (.5, .5), and that fit into the screen, but in a perfect square (when I thought it would be 400x300 if scaled properly). I guess I''m just not understanding the scaling functionality of the Draw(...) method or maybe I''m loading the texture wrong...
Can anyone help? I''m trying to place and size my background and sprites properly. What am I doing wrong? Is there a better way to handle these? Any help would be GREATLY appreciated! :-)
Thanks,
Todd Geraty
RELEVANT CODE (removing unneeded code):
I used this code to create and display the background (the first way) and it seemed to display just fine:
hr = D3DXCreateTextureFromFile(m_pID3DDevice, _T("Game.bmp"), &m_pID3DTextureBackground);
m_MainVerts[0].v.x = 0;
m_MainVerts[0].v.y = SCREEN_HEIGHT - 1;
m_MainVerts[0].v.z = 0;
m_MainVerts[0].tu = 0;
m_MainVerts[0].tv = 1;
m_MainVerts[0].rhw = 1;
m_MainVerts[0].color = 0xFFFFFF;
m_MainVerts[0].specular = 0;
m_MainVerts[1].v.x = 0;
m_MainVerts[1].v.y = 0;
m_MainVerts[1].v.z = 0;
m_MainVerts[1].tu = 0;
m_MainVerts[1].tv = 0;
m_MainVerts[1].rhw = 1;
m_MainVerts[1].color = 0xFFFFFF;
m_MainVerts[1].specular = 0;
m_MainVerts[2].v.x = SCREEN_WIDTH - 1;
m_MainVerts[2].v.y = SCREEN_HEIGHT - 1;
m_MainVerts[2].v.z = 0;
m_MainVerts[2].tu = 1;
m_MainVerts[2].tv = 1;
m_MainVerts[2].rhw = 1;
m_MainVerts[2].color = 0xFFFFFF;
m_MainVerts[2].specular = 0;
m_MainVerts[3].v.x = SCREEN_WIDTH - 1;
m_MainVerts[3].v.y = 0;
m_MainVerts[3].v.z = 0;
m_MainVerts[3].tu = 1;
m_MainVerts[3].tv = 0;
m_MainVerts[3].rhw = 1;
m_MainVerts[3].color = 0xFFFFFF;
m_MainVerts[3].specular = 0;
hr = m_pID3DDevice->SetTexture(0, m_pID3DTextureBackground);
hr = m_pID3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, m_MainVerts, sizeof(CCustomVertex));
I used this code to create and display the background (the second way) and couldn''t get it to display properly:
hr = D3DXCreateTextureFromFile(m_pID3DDevice, _T("Game.bmp"), &m_pID3DTextureBackground);
hr = D3DXCreateSprite(m_pID3DDevice, &m_pID3DXSprite);
hr = m_pID3DXSprite->Draw(m_pID3DTextureBackground, NULL, &D3DXVECTOR2(0.5f, 0.5f), NULL, 0, &D3DXVECTOR2(0.0f, 0.0f), D3DCOLOR_XRGB(255, 255, 255));
I used this code to create and display the sprite and couldn''t get it to display properly:
hr = D3DXCreateTextureFromFile(m_pID3DDevice, _T("Pieces.bmp"), &m_pID3DTextureSprite);
hr = D3DXCreateSprite(m_pID3DDevice, &m_pID3DXSprite);
hr = m_pID3DXSprite->Draw(m_pID3DTextureSprite, NULL, &D3DXVECTOR2(0.5f, 0.5f), NULL, 0, &D3DXVECTOR2(400.0f, 300.0f), D3DCOLOR_XRGB(255, 255, 255));