Jump to content
  • Advertisement
Sign in to follow this  
ReaVeR-Andrey

D3D inaccuracy.

This topic is 4893 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 am making UI system using D3D. I draw textures by creating a flat rect and drawing it using IDirect3DDevice::DrawPrimitiveUP (). However corners of my windows don't match with the window frame (the size of the hole depends on window's size). Here's my code:
bool UI::Draw ( bool active, int x, int y, UITexture const& tex, int width, int height )
{
   if ( width == 0 )
      width = tex.width;
   if ( height == 0 )
      height = tex.height;
   float x1 = (float) D3D::width / (float) defWidth * (float) x;
   float y1 = (float) D3D::height / (float) defHeight * (float) y;
   float x2 = x1 + (float) D3D::width / (float) defWidth * (float) width;
   float y2 = y1 + (float) D3D::height / (float) defHeight * (float) height;

   D3D::SetFVF ( Vertex2D::FVF );


   Vertex2D v [6];

   float u1 = (float) tex.x;
   float v1 = (float) tex.y;
   float u2 = u1 + (float) tex.width;
   float v2 = v1 + (float) tex.height;
   u1 /= (float) texture.width;
   v1 /= (float) texture.height;
   u2 /= (float) texture.width;
   v2 /= (float) texture.height;
	float z = 0;
   v [0] = Vertex2D ( Vector2D ( x1, y1 ), Vector2D ( u1, v1 ), 0xffffffff, z );
   v [1] = Vertex2D ( Vector2D ( x2, y1 ), Vector2D ( u2, v1 ), 0xffffffff, z );
   v [2] = Vertex2D ( Vector2D ( x2, y2 ), Vector2D ( u2, v2 ), 0xffffffff, z );
   v [3] = v [2];
   v [4] = Vertex2D ( Vector2D ( x1, y2 ), Vector2D ( u1, v2 ), 0xffffffff, z );
   v [5] = v [0];
	
   if ( active )
      D3D::SetTexture ( 0, texture );
   else
      D3D::SetTexture ( 0, grayTexture );

   D3D::DrawTriangles ( v, 2 );

   return true;
}
static bool DrawTriangles ( Vertex2D const* tris, int nTris )
{
   return lpDev ? SUCCEEDED ( lpDev->DrawPrimitiveUP ( D3DPT_TRIANGLELIST, nTris, tris, sizeof ( Vertex2D ) ) ) : false;
}
static bool SetTexture ( int stage, Texture const& t )
{
   return lpDev ? SUCCEEDED ( lpDev->SetTexture ( stage, t.lpTexture ) ) : false;
}
static bool SetFVF ( DWORD fvf )
{
   return lpDev ? SUCCEEDED ( lpDev->SetFVF ( fvf ) ) : false;
}



Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ReaVeR-Andrey
I am making UI system using D3D. I draw textures by creating a flat rect and drawing it using IDirect3DDevice::DrawPrimitiveUP (). However corners of my windows don't match with the window frame (the size of the hole depends on window's size). Here's my code:
*** Source Snippet Removed ***


I'm not really sure what you mean, in that code you draw only one rectangle, where do you get your window frame from? Do you mean the _window_ frame? And if so, you might be doing other things wrong. Such as an "improper" world matrix.

EDIT: make sure you use a texture POW2, otherwise you might get such problems, as the texture has transparent edges.

Share this post


Link to post
Share on other sites
Here's a screenshot (the bad corner is circled in red):
Image (653 Kb)

EDIT: I'm using a skin 256x256. Here it is:
Skin 256x256

Edited by Coder: Inlining an image that is 653 Kb is murder! [smile]

[Edited by - Coder on July 20, 2005 11:58:56 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!