Sign in to follow this  

UV Mapping changed with VS 2005 ?

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

Ok, I once had a working sprite renderer when Directx 8 first came out and I was running VC 6. Several years later VS 2005 comes out and I break out some motivation to dig through some old code. So, I launch up my game and hit run and now there are rendering issues in my sprite's render. I get random 1 pixel 'tears' on the edges of my sprites. I am not sure why going from Direct8 Vc6 to DirectX 8 VS2005 would make a difference in the UV coordinate systems so I thought I would get some input here... My render function is nothing fancy and so it here is...
//**********************************************************************************************
// Renders a graphic straight to the screen and bypasses world geometry transformation in the
// pipeline
//**********************************************************************************************
void Sprite::renderOntoScreen( LPDIRECT3DDEVICE8* m_pd3dDevice, float dwXOrigin, float dwYOrigin, float dwWidth, float dwHeight )
{  
	//*******************************************************
	// Define each vertex color
	//*******************************************************
	DWORD dwColor[NUM_VERTICES];
	for ( int i = 0; i< NUM_VERTICES; i++ )
	{
		dwColor[i] = D3DCOLOR_ARGB( (int)m_cColor[i].m_nAlpha, (int)m_cColor[i].m_nRed, (int)m_cColor[i].m_nGreen, (int)m_cColor[i].m_nBlue );
	}

	//*******************************************************
	// Get the level desc so we can get info on the texture
	//*******************************************************
	D3DSURFACE_DESC desc;
	m_tManager->getTexture( m_strTextures[m_nCurTexture] )->GetLevelDesc(0, &desc);

	//*******************************************************
	// UV Coordinates for the top left point
	//*******************************************************
	m_Vertices[UPPER_LEFT].vPosition = D3DXVECTOR4( dwXOrigin - 0.5f, dwYOrigin - 0.5f, 0, 1  );  
	m_Vertices[UPPER_LEFT].dwDiffuse = dwColor[UPPER_LEFT];
	m_Vertices[UPPER_LEFT].tu = 0.0;  
	m_Vertices[UPPER_LEFT].tv = 0.0;  
	
	//*******************************************************
	// UV Coordinates for the bottom left
	//*******************************************************
	m_Vertices[BOTTOM_LEFT].vPosition = D3DXVECTOR4( dwXOrigin - 0.5f, dwHeight - 0.5f,  0, 1 );  
	m_Vertices[BOTTOM_LEFT].dwDiffuse = dwColor[BOTTOM_LEFT];  
	m_Vertices[BOTTOM_LEFT].tu = 0.0; 
	m_Vertices[BOTTOM_LEFT].tv = (float)m_vOrigSize.y/(float)desc.Height; 
	
	//*******************************************************
	// UV Coordinates for the top right
	//*******************************************************
	m_Vertices[UPPER_RIGHT].vPosition = D3DXVECTOR4( dwWidth - 0.5f, dwYOrigin - 0.5f,  0, 1 );  
	m_Vertices[UPPER_RIGHT].dwDiffuse = dwColor[UPPER_RIGHT];  
	m_Vertices[UPPER_RIGHT].tu = (float)m_vOrigSize.x/(float)desc.Width;
	m_Vertices[UPPER_RIGHT].tv = 0.0;
	
	//*******************************************************
	// UV Coordinates for the bottom right
	//*******************************************************
	m_Vertices[BOTTOM_RIGHT].vPosition= D3DXVECTOR4( dwWidth - 0.5f, dwHeight - 0.5f,  0, 1 );  
	m_Vertices[BOTTOM_RIGHT].dwDiffuse = dwColor[BOTTOM_RIGHT]; 
	m_Vertices[BOTTOM_RIGHT].tu = (float)m_vOrigSize.x/(float)desc.Width;
	m_Vertices[BOTTOM_RIGHT].tv = (float)m_vOrigSize.y/(float)desc.Height;

	//*******************************************************
        // Set render states, make sure Zbuffer is turned off,
        // this paste to the screen will create a 0,0 which will
        // fail lots of graphics if it is turned on
        //*******************************************************
        (*m_pd3dDevice)->SetRenderState( D3DRS_ZENABLE,                 m_bUseZ );
        (*m_pd3dDevice)->SetRenderState( D3DRS_ZWRITEENABLE,            FALSE );
        (*m_pd3dDevice)->SetRenderState( D3DRS_FOGENABLE,               FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_LIGHTING,                FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ALPHABLENDENABLE,        TRUE );
        (*m_pd3dDevice)->SetRenderState( D3DRS_CULLMODE,                D3DCULL_NONE );

        //*******************************************************
        // Determine which blending technique to use...
        //*******************************************************
	(*m_pd3dDevice)->SetRenderState( D3DRS_SRCBLEND,	m_nSrcBlend );
	(*m_pd3dDevice)->SetRenderState( D3DRS_DESTBLEND,	m_nDestBlend );

        //*******************************************************
        // Mip Mapping Settings
        //*******************************************************
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_NONE );
        (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_NONE );
        (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_NONE );
    
	//*******************************************************
        // Choose which color operations to use
        //*******************************************************
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLOROP,   m_nColorOp );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

	//*******************************************************
        // Choose which alpha operations to use
        //*******************************************************
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAOP,   m_nAlphaOp );
        (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
       (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

	//*******************************************************
	// Draw the primitives and vertex shading
	//*******************************************************
	(*m_pd3dDevice)->SetVertexShader( D3DFVF_TLVERTEX ); 
	(*m_pd3dDevice)->SetTexture( 0, m_tManager->getTexture( m_strTextures[m_nCurTexture] ) );
	(*m_pd3dDevice)->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, m_Vertices, sizeof(TLVertex2) );  
}
I appreciate the help !

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The cause is more likely to be subtle differences in graphics cards and drivers, rather than the version of VS used to compile.

Also, shouldn't your bottom / right rather be for example xOrigin + Width rather than just Width?

Share this post


Link to post
Share on other sites

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