Sign in to follow this  
Erakis

Texturing quad 3/4 screen size

Recommended Posts

Hi, I would like to texturate a big quad having 3/4 size of my window. Here is what I'm doing : Here is the initialization part

// Get dimension of my window
RECT rcScene;
GetClientRect(m_hWnd, &rcScene);

// Quad size
float fxInterfaceSize = 600.0f;
float fyInterfaceSize = 600.0f;
float fxInterfaceCoordinate = ((rcScene.right - rcScene.left) - fxInterfaceSize) / 2;
float fyInterfaceCoordinate = ((rcScene.bottom - rcScene.top) - fyInterfaceSize) / 2;

// Initialize vertex position at screen center (x, y, z, rhw, colour, u, v)
CUSTOMVERTEX2_ Vertices2[] =
{
	{fxInterfaceCoordinate,                   fyInterfaceCoordinate,                   0.0f, 1.0f, 0xFFFFFFFF, 0.0f, 0.0f },
	{fxInterfaceCoordinate + fxInterfaceSize, fyInterfaceCoordinate,                   0.0f, 1.0f, 0xFFFFFFFF, 1.0f, 0.0f },
	{fxInterfaceCoordinate + fxInterfaceSize, fyInterfaceCoordinate + fyInterfaceSize, 0.0f, 1.0f, 0xFFFFFFFF, 1.0f, 1.0f },
	{fxInterfaceCoordinate,                   fyInterfaceCoordinate + fyInterfaceSize, 0.0f, 1.0f, 0xFFFFFFFF, 0.0f, 1.0f }
};

// Create vertext
if( FAILED( m_D3DDev->CreateVertexBuffer(4 * sizeof( CUSTOMVERTEX2_ ),
	D3DUSAGE_WRITEONLY,
	D3DFVF_CUSTOMVERTEX2_,
	D3DPOOL_DEFAULT,
	&g_pVBTQ,
	NULL ) ) )
{
    return E_FAIL;
}

// Fill the vertex buffer
VOID* pVertices2;
if( FAILED( g_pVBTQ->Lock( 0, sizeof( Vertices2 ), ( void** )&pVertices2, 0 ) ) )
    return E_FAIL;
memcpy( pVertices2, Vertices2, sizeof( Vertices2 ) );
g_pVBTQ->Unlock();

// Create a texture
if( FAILED( m_D3DDev->CreateTexture(1024, 1024,
				    1,
				    D3DUSAGE_DYNAMIC,
				    D3DFMT_A8R8G8B8,
				    D3DPOOL_DEFAULT,
				    &g_pOORT,
					NULL) ) )
{
    return E_FAIL;
}

// Lock texture and render a rectangle with round corner over GDI
D3DLOCKED_RECT lockedRect;
g_pOORT->LockRect(0, &lockedRect, NULL, 0);
	Gdiplus::Bitmap bitmap(1024, 1024, lockedRect.Pitch, PixelFormat32bppARGB , (BYTE*)lockedRect.pBits);
	Gdiplus::Graphics graphicOff( &bitmap );
	graphicOff.SetSmoothingMode(SmoothingModeAntiAlias);

	Rect rcBackground
		(
			0, 
			0,
			1024 - 1, 
			1024 - 1
		); 

	Color cContour(150, 255, 0, 0);
	Pen pContour(cContour, 1);

	Color cBackground(150, 180, 180, 180);
	SolidBrush bBackground(cBackground);

	GraphicsPath gp;
	int d = 30;
	gp.AddArc(rcBackground.X, rcBackground.Y, d, d, 180, 90);
	gp.AddArc(rcBackground.X + rcBackground.Width - d, rcBackground.Y, d, d, 270, 90);
	gp.AddArc(rcBackground.X + rcBackground.Width - d, rcBackground.Y + rcBackground.Height - d, d, d, 0, 90);
	gp.AddArc(rcBackground.X, rcBackground.Y + rcBackground.Height - d, d, d, 90, 90);
	gp.AddLine(rcBackground.X, rcBackground.Y + rcBackground.Height - d, rcBackground.X, rcBackground.Y + d/2);
	graphicOff.DrawPath(&pContour, &gp);
	graphicOff.FillPath(&bBackground, &gp);

	::GdiFlush();

       // Save bitmap
       //CLSID clsidEncoder;
       //getCodecClsid(L"image/bmp", &clsidEncoder);
       //bitmap.Save(L"C:\\Test.bmp", &clsidEncoder); 
g_pOORT->UnlockRect(0);
And here is the way I render to surface
m_D3DDev->SetTexture(0, g_pOORT);
m_D3DDev->SetStreamSource( 0, g_pVBTQ, 0, sizeof(CUSTOMVERTEX2_) );
m_D3DDev->SetFVF( D3DFVF_CUSTOMVERTEX2_ );
m_D3DDev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2 );
All is well working except that the right and bottom red border is missing. It is as if pixels line was missing on the right and bottom side. But I save the bitmap and it is correct. Best regards

Share this post


Link to post
Share on other sites
If you create a 1024x1024 texture, and draw it at less than 1024x1024 size on the screen, then some pixels will have to be ignored. If you generate and use mipmaps for it the problem should go away, though the line might get slightly different color as 1 pixel on the screen corresponds to more than 1 pixel in the texture, a displayed pixel should be the average color of contained texels.

Share this post


Link to post
Share on other sites
I corrected the situation by giving a size of 512 to the texture and the bitmap. And it seems to be correct.

Unfortunately I'm in my early days in Direct3D so I do not understand too what a MipMaps :(

I waiting a book by Frank D. Luna, it should happen soon;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this