I am using D3D9 for rendering some simple things, a movie, as the backmost layer, then on top of that some text messages, and now wanted to add some buttons to that.
Before adding the buttons everything seemed to have worked fine, and I was using a [color=#2A2A2A]D3DXSPRITE for the text as well (D3DXFONT), now I am loading some graphics for the buttons, but they seem to be scaled to something like 1.2 of its original size (in my test window I centered the graphic, but it being too big it just doesnt fit well, for example the client area is 640x360, the graphic is 440, so i expect 100 pixel on left and right, left side is fine [I took screenshot and "counted" the pixels in photoshop], but on the right there is only about 20 pixels)
My rendering code is very simple (I am omitting error checks etc for brevity)
[color=#0000cd]// initially viewport was set to width/height of client area
[color=#0000cd]// clear device
[color=#0000cd]m_d3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0,0,0,0), 1.0f, 0 );
[color=#0000cd]// begin scene
[color=#0000cd]m_d3dDevice->BeginScene();
[color=#0000cd]// render movie surface (just two triangles to which the movie is rendered)
[color=#0000cd]m_d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
[color=#0000cd]m_d3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); // bilinear filtering
[color=#0000cd]m_d3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); // bilinear filtering
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); //Ignored
[color=#0000cd]m_d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
[color=#0000cd]m_d3dDevice->SetTexture( 0, m_movieTexture );
[color=#0000cd]m_d3dDevice->SetStreamSource(0, m_displayPlaneVertexBuffer, 0, sizeof(Vertex));
[color=#0000cd]m_d3dDevice->SetFVF(Vertex::FVF_Flags);
[color=#0000cd]m_d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
[color=#0000cd]// render sprites
[color=#0000cd]m_sprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_DO_NOT_ADDREF_TEXTURE);
[color=#0000cd]// text drop shadow
[color=#0000cd]m_font->DrawText( m_playerSprite, m_currentMessage.c_str(), m_currentMessage.size(),
[color=#0000cd]&m_playerFontRectDropShadow, DT_RIGHT|DT_TOP|DT_NOCLIP, m_playerFontColorDropShadow );
[color=#0000cd]// text
[color=#0000cd]m_font->DrawText( m_playerSprite, m_currentMessage.c_str(), m_currentMessage.size(),
[color=#0000cd]&m_playerFontRect, DT_RIGHT|DT_TOP|DT_NOCLIP, m_playerFontColorMessage ) );
[color=#0000cd]// control object
[color=#0000cd]m_sprite->Draw( m_texture, 0, 0, &m_vecPos, 0xFFFFFFFF ); // draws a few objects like this
[color=#0000cd]m_sprite->End()
[color=#0000cd]// end scene
[color=#0000cd]m_d3dDevice->EndScene();
What did I forget to do here? Except for the control objects (play button, pause button etc which are placed on a "panel" which is about 440 pixels wide) everything seems fine, the objects are positioned where I expect them, but just too big. Btw I loaded the images using D3DXCreateTextureFromFileEx (resizing wnidow, and reacting to lost device etc works fine too).
For experimenting, I added some code to take an identity matrix and scale is down on the x/y axis to 0.75f, which then gave me the expected result for the controls (but also made the text smaller and out of position), but I don't know why I would need to scale anything. My rendering code is so simple, I just wanted to draw my 2D objects 1;1 the size they came from the file...
I am really very inexperienced in D3D, so the answer might be very simple...
thanks
Bjoern