Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Help with rendering in dx8 IM Framework?

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

Hail to the cheese, Greetings, I am stumped on a basic problem; which is usually the case. I have a bare bones directx8 application using a setup that the SDK applications use. ie: Directx8 IM framework. Anyways, the symptom is that the rendering pass doesn''t render anything, the screen just comes out as the color that I pass into device->clear on the rendering pass. Ok, normally this is just a problem with lighting or textures, so I started going through the check list of things to look for: InitDeviceObject creates a texture... and the pointer comes back as valid...
D3DUtil_CreateTexture( pd3dDevice, "C:\\Test.jpg", &g_pTexture ) ;
Then I went to check the view matrix, in RestoreDeviceObjects I have:

// Set up world matrix


FLOAT      fAspect = m_d3dsdBackBuffer.Width / (FLOAT)m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 10, 1000);
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

Ok, so that meets the pre-requisits and I now go to the rendering pass... But this looks normal to me as well...
HRESULT CMyD3DApplication::Render()
    HRESULT hr;
    m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 
		D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
	if(FAILED(hr = m_pd3dDevice->BeginScene()))
        return hr;

	tSprite->render( &m_pd3dDevice );
    if(FAILED(hr = m_pd3dDevice->EndScene()))
        return hr;

    return S_OK;

void Sprite::render( LPDIRECT3DDEVICE8* m_pd3dDevice )
        //renderontoscreen( device, x+width, y+height, x, y )

	renderOntoScreen( pd3dDevice, 400, 400, 200, 200 );

void Sprite::renderOntoScreen( LPDIRECT3DDEVICE8* m_pd3dDevice, DWORD dwXOrigin, DWORD dwYOrigin, DWORD dwWidth, DWORD dwHeight )

	// Do not render if we are not visible


	if ( !m_bVisible) 


	// Create 4 texel vertices for this polygon


	DWORD dwColor = D3DCOLOR_ARGB(byte(100),byte(100),byte(100),byte(100)); 

	// UV Coordinates for the top left point


	m_Vertices[0].vPosition = D3DXVECTOR4( dwXOrigin, dwHeight, 0, 1  );  
	m_Vertices[0].dwDiffuse = dwColor;
	m_Vertices[0].tu = 1.0;  
	m_Vertices[0].tv = 0.0;  

	// UV Coordinates for the bottom left


	m_Vertices[1].vPosition = D3DXVECTOR4( dwXOrigin, dwYOrigin,  0, 1 );  
	m_Vertices[1].dwDiffuse = dwColor;  
	m_Vertices[1].tu = 1.0;  
	m_Vertices[1].tv = 1.0;  

	// UV Coordinates for the top right


	m_Vertices[2].vPosition = D3DXVECTOR4( dwWidth, dwHeight,  0, 1 );  
	m_Vertices[2].dwDiffuse = dwColor;  
	m_Vertices[2].tu = 0.0;  
	m_Vertices[2].tv = 0.0;  

	// UV Coordinates for the bottom right


	m_Vertices[3].vPosition= D3DXVECTOR4( dwWidth, dwYOrigin,  0, 1 );  
	m_Vertices[3].tu = 0.0;  
	m_Vertices[3].dwDiffuse = dwColor;  
	m_Vertices[3].tv = 1.0;  

	// 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_SRCBLEND,  D3DBLEND_SRCALPHA );
	(*m_pd3dDevice)->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZENABLE,				FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZWRITEENABLE,		FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_LIGHTING,			FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_FOGENABLE,			FALSE );
    (*m_pd3dDevice)->SetRenderState( D3DRS_ALPHABLENDENABLE,	TRUE );


	// Mip Mapping Settings


	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
    (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
    (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
    (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    (*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );


	// Draw the primitives and vertex shading


	(*m_pd3dDevice)->SetVertexShader( D3DFVF_TLVERTEX ); 
	(*m_pd3dDevice)->SetTexture( 0, g_Texture );
	(*m_pd3dDevice)->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, m_Vertices, sizeof(TLVertex2) );  


	// Set the renderer back to what it was


	(*m_pd3dDevice)->SetRenderState( D3DRS_ALPHABLENDENABLE,   FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZENABLE, TRUE );

This render function worked in my other game just perfectly, so maybe I thought it was the vertex definition. This looks right to me as well
struct TLVertex2
	D3DXVECTOR4 vPosition;  
	DWORD dwDiffuse; 
	FLOAT tu, tv;

//Make sure to define the vertex definition in the same order as the data structure otherwise everything will get foobar''d


So at this poing I am pretty much stumped, maybe someone else has an idea? I also wrote 2 functions, one that renders straight to the screen and one that renders the sprite in world space, I thought that maybe the viewport was hosed, but rendering straight to the screen doesn''t even work for those curious, here is the other implementation of the render:
void Sprite::render( LPDIRECT3DDEVICE8* m_pd3dDevice )
	renderOntoScreen( m_pd3dDevice, 400, 400, 100, 00 );

	DWORD dwColor =D3DCOLOR_ARGB(255,255,255,255);
	MYCVERTEX  Vertices[4];

	int ScaleTexture = 2;
	D3DXVECTOR3 Position(0,0,0);
	float SizeX = 5534;
	float SizeY = 5534*2.5;
	float SizeZ = 23043;
	float Height = 20034;

	Vertices[0].p = D3DXVECTOR3(Position.x+SizeX,Position.y+Height,Position.z+SizeZ);
	Vertices[0].tu = ScaleTexture*(0.5);
	Vertices[0].tv = ScaleTexture*(1.0);


	Vertices[3].tv=ScaleTexture*(0.5 );

	Vertices[2].tv=ScaleTexture* (1.0);

	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ADDRESSU,  D3DTADDRESS_WRAP  );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ADDRESSV,  D3DTADDRESS_WRAP  );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_ZENABLE, FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_LIGHTING,  FALSE );
	(*m_pd3dDevice)->SetRenderState( D3DRS_FOGENABLE,	 FALSE );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	(*m_pd3dDevice)->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
	(*m_pd3dDevice)->SetRenderState( D3DRS_DITHERENABLE, TRUE );

	(*m_pd3dDevice)->SetTexture( 0, m_tManager->getTexture( 0 ) );
	(*m_pd3dDevice)->SetVertexShader( D3DFVF_MYCVERTEX );
   	(*m_pd3dDevice)->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2,&Vertices[0],sizeof(MYCVERTEX));
	(*m_pd3dDevice)->SetRenderState( D3DRS_DITHERENABLE, FALSE );


Share this post

Link to post
Share on other sites

Hhmmmmm, good suggestion but alas, it didn''t help...

Yes, it was a much longer post than intended.

For a short version:

I can''t figure out why nothing is rendering. I create the projection matrix, set the view matrix, create a quad vertex specified by a TLVERTEX, transformed and lit, so it should render STRAIGHT to the screen...

Nothing renders, and I can''t figure out what is causing the render to fail... ;(

Share this post

Link to post
Share on other sites
It turns out the color operation render state flags were the culprit,

why exactly I am not so sure... Will have to study it some more

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!