Sign in to follow this  

Textured Quads

This topic is 3716 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 guys, i've followed the article on the site for rendering textured quads, but i don't seem to get any results, i've tried lots of varations but the texture just never shows up. In my "DrawQuad" function i have the following code: This is in D3D8 by the way...
	RECT dest;
	DWORD fvf;
	D3DSURFACE_DESC desc;
	TLVERTEX* m_pVertex = NULL;
	
	texture->GetLevelDesc ( 0, &desc );

	dest.left = x;
	dest.top = y;
	dest.right = dest.left + desc.Width;
	dest.bottom = dest.top + desc.Height;

	Backbones.GetDevice ( )->GetVertexShader ( &fvf );
	Backbones.GetDevice ( )->SetStreamSource ( 0, m_pVertexBuffer, sizeof ( 		TLVERTEX ) );
	Backbones.GetDevice ( )->SetVertexShader ( D3DFVF_TEXTUREDQUAD );

    	m_pVertexBuffer->Lock ( 0, 4 * sizeof(TLVERTEX), (BYTE**)&m_pVertex, 0 );
	
	m_pVertex[0].colour = colour;
	m_pVertex[0].x = (float)dest.left - 0.5f;
	m_pVertex[0].y = (float)dest.top - 0.5f;
	m_pVertex[0].z = 1.0f;
	m_pVertex[0].rhw = 1.0f;
	m_pVertex[0].u = 0.0f;
	m_pVertex[0].v = 0.0f;

	m_pVertex[1].colour = colour;
	m_pVertex[1].x = (float)dest.right - 0.5f;
	m_pVertex[1].y = (float)dest.top - 0.5f;
	m_pVertex[1].z = 1.0f;
	m_pVertex[1].rhw = 1.0f;
	m_pVertex[1].u = 1.0f;
	m_pVertex[1].v = 0.0f;

	m_pVertex[2].colour = colour;
	m_pVertex[2].x = (float)dest.right - 0.5f;
	m_pVertex[2].y = (float)dest.bottom - 0.5f;
	m_pVertex[2].z = 1.0f;
	m_pVertex[2].rhw = 1.0f;
	m_pVertex[2].u = 1.0f;
	m_pVertex[2].v = 1.0f;

	m_pVertex[3].colour = colour;
	m_pVertex[3].x = (float)dest.left - 0.5f;
	m_pVertex[3].y = (float)dest.bottom - 0.5f;
	m_pVertex[3].z = 1.0f;
	m_pVertex[3].rhw = 1.0f;
	m_pVertex[3].u = 0.0f;
	m_pVertex[3].v = 1.0f;

	m_pVertexBuffer->Unlock ( );
	
	Backbones.GetDevice ( )->SetTexture ( 0, texture );
	Backbones.GetDevice ( )->DrawPrimitive ( D3DPT_TRIANGLEFAN, 0, 2 );

	Backbones.GetDevice ( )->SetVertexShader ( fvf );

	Backbones.GetDevice ( )->SetStreamSource ( 0, NULL, 0 );
In my "Initialize" function i have:
	Backbones.GetDevice ( )->CreateVertexBuffer ( sizeof ( TLVERTEX ) * 4, NULL, D3DFVF_TEXTUREDQUAD, D3DPOOL_MANAGED, &m_pVertexBuffer );
and in "Invalidate" i have:
	SAFE_RELEASE ( m_pVertexBuffer );
If anyone could help me out it would be greatly appreciated, i basically just want to be able to render textured quads without using the sprite class :) Thanks.

Share this post


Link to post
Share on other sites
  • Your RHW value shouldn't be 1.0f or 0.0f. Try using 0.5f instead.
  • Have you tried it without a texture to see if that makes a difference?
  • Have you tried / are you clearing your backbuffer to a non-black colour in case your quad is being drawn, but black for some reason (Although it's unlikely with transformed verts)

    And, slightly off topic:
  • It's generally preferable to use an orthogonal projection matrix and to specify your quads in world space now. That lets D3D handle vertex transforms and gives you things like rotation for "free".
  • Any particular reason you're using DX8 instead of DX9? DX9 is pretty much the standard now.

    Share this post


    Link to post
    Share on other sites

    This topic is 3716 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.

    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