Jump to content
  • Advertisement
Sign in to follow this  

Texturing quad 3/4 screen size

This topic is 3154 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

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_ ),
	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 ) );

// Create a texture
if( FAILED( m_D3DDev->CreateTexture(1024, 1024,
					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 );

	Rect rcBackground
			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);


       // Save bitmap
       //CLSID clsidEncoder;
       //getCodecClsid(L"image/bmp", &clsidEncoder);
       //bitmap.Save(L"C:\\Test.bmp", &clsidEncoder); 
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->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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!