Archived

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

Bacardi34

Meshes not being displayed

Recommended Posts

Bacardi34    122
I know somone just asked about meshes not being displayed, and i read it and checked and its not the problem i am having. I cant get meshes to be displayed at all. The app works, and runs in full screen, but all i get is blackness. The following is the code i have used. Game Init:
  
if( NULL == ( g_pd3d = Direct3DCreate9( D3D_SDK_VERSION )))
        return;

#ifndef DEBUG
	// Get Display modes

	UINT displayModeCount = g_pd3d->GetAdapterModeCount( D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8 );
	// Go Through the display modes

	for( UINT displayMode = 0; displayMode < displayModeCount; displayMode++ )
	{
		//Check current display mode

		g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8, displayMode, &g_d3dDisplayMode );

		// If it matches what i want, break out

		if( g_d3dDisplayMode.Width == SCREENWIDTH && g_d3dDisplayMode.Height == SCREENHEIGHT )
			break;
	}// End For

	// Make sure the display mode was matched

	if( g_d3dDisplayMode.Width != SCREENWIDTH && g_d3dDisplayMode.Height != SCREENHEIGHT )
	{
		MessageBox( NULL, "NO DISPLAY MODE FOUND", "No Display mode found", NULL );
		PostQuitMessage( 0 );
		return;
	} // End if


	// Setup the d3d Present parameters

	ZeroMemory( &g_d3dpp, sizeof( g_d3dpp ));
	g_d3dpp.BackBufferCount				= 1;
	g_d3dpp.BackBufferHeight			= g_d3dDisplayMode.Height;
	g_d3dpp.BackBufferWidth				= g_d3dDisplayMode.Width;
	g_d3dpp.SwapEffect					= D3DSWAPEFFECT_FLIP;
	g_d3dpp.MultiSampleType				= D3DMULTISAMPLE_NONE;
	g_d3dpp.BackBufferFormat			= g_d3dDisplayMode.Format;
	g_d3dpp.hDeviceWindow				= g_hwnd;							
	g_d3dpp.Windowed					= false;
	g_d3dpp.EnableAutoDepthStencil		= true;
	g_d3dpp.AutoDepthStencilFormat		= D3DFMT_D16;
	g_d3dpp.Flags						= NULL;
	g_d3dpp.PresentationInterval		= D3DPRESENT_INTERVAL_DEFAULT;
	g_d3dpp.FullScreen_RefreshRateInHz	= g_d3dDisplayMode.RefreshRate;
// Create the d3d Device

	 if( FAILED( g_pd3d->CreateDevice( D3DADAPTER_DEFAULT,					// Use the defualt adapter

									D3DDEVTYPE_HAL,							// Use hardware layer

									g_hwnd,									// focus window handle

                                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,	// Use HARDWARE for vertex processing

                                    &g_d3dpp,								// Present params 

									&g_pd3dDevice )))						// Ponter to device

	 {
         MessageBox( NULL, "Could not create Divice", "Could not create device", NULL );
		return;
	 }




	// Store Device type

	g_d3dDevType = D3DDEVTYPE_HAL;
	// Setup the view port

	g_d3dVpMain.X = 0;
	g_d3dVpMain.Y = 0;
	g_d3dVpMain.Width = SCREENWIDTH;
	g_d3dVpMain.Height = SCREENHEIGHT;
	g_d3dVpMain.MinZ = 0.0f;
	g_d3dVpMain.MaxZ = 1.0f;
	// Set Viewport

	g_pd3dDevice->SetViewport( &g_d3dVpMain );
  
Then Scene init
  

	// init the camera

	D3DXVECTOR3 vLookAt, vEyePt, vUpVec;
	vLookAt.x = 0.0f; vLookAt.y = 0.0f; vLookAt.z = 5.0f;
	vEyePt.x = 0.0f; vEyePt.y = 0.0f; vEyePt.z = 0.0f;
	vUpVec.x = 0.0f; vUpVec.y = 1.0f; vUpVec.z = 0.0f;
	g_Camera.SetViewParams( vEyePt, vLookAt, vUpVec );
	g_Camera.SetProjParams( D3DX_PI / 4, SCREENWIDTH / SCREENHEIGHT, 0.0f, 500.0f );
	
	
	// init the ground

	g_Ground.Create( g_pd3dDevice, "xground.x" );
	g_Ground.SetFVF( g_pd3dDevice, D3DFVF_CUSTOMVERTEX );
	D3DXVECTOR3 vLoc;
	D3DXMATRIX matTemp;
	vLoc.x = 0; vLoc.y = 0; vLoc.z = 10;
	D3DXMatrixTransformation( &matTemp, NULL, NULL, NULL, NULL, NULL, &vLoc );
	g_Ground.SetMatrix( matTemp );


	SAFERELEASE( &matTemp );
	SAFERELEASE( vLoc );
  
Then in render
  
// This debug code will just set the camera and view matrices, and then render the temp ground.

	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 
		D3DCOLOR_XRGB( 0,0,255 ), 1.0f, 0 );

	// Set the world matrix

	D3DXMatrixIdentity( &g_WorldMat );
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_WorldMat );
	g_pd3dDevice->SetTransform( D3DTS_VIEW, &g_Camera.GetViewMatrix() );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_Camera.GetProjMatrix() );

	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

	// Begin the scene

	g_pd3dDevice->BeginScene();

	g_Ground.Render( &g_pd3dDevice, g_WorldMat );

	g_pd3dDevice->EndScene();
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
  
I have been playing with diffrent matries and moving the camera, but i get nothing. Maybe i am using the CD3DFile class wrong? But i cant find any tuts or examples on it. I just am going from what i can figure out after reading all the code for it. Anyone have any ideas what i am doing wrong? Many thanks in advance

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
you need to call g_Ground.InitDeviceObjects()
or something like that
maybe RestoreDeviceObjects()

instead of CD3DFile possibly use CD3DMesh

Share this post


Link to post
Share on other sites
Bacardi34    122
Ok, i will give it a try. I Tried using CD3DMesh before. But the only thing is, i didnt see how to use matrices to transform the mesh. I would rather use CD3DMesh, if somone could tell me how to transform it.
Thanks btw.

[edit]
I changed my scene init to this

   // init the camera

D3DXVECTOR3 vLookAt, vEyePt, vUpVec;
vLookAt.x = 0.0f; vLookAt.y = 0.0f; vLookAt.z = 5.0f;
vEyePt.x = 0.0f; vEyePt.y = 0.0f; vEyePt.z = 0.0f;
vUpVec.x = 0.0f; vUpVec.y = 1.0f; vUpVec.z = 0.0f;
g_Camera.SetViewParams( vEyePt, vLookAt, vUpVec );
g_Camera.SetProjParams( D3DX_PI / 4, SCREENWIDTH / SCREENHEIGHT, 0.0f, 500.0f );


// init the ground

g_Ground.Create( g_pd3dDevice, "xground.x" );
g_Ground.SetFVF( g_pd3dDevice, D3DFVF_CUSTOMVERTEX );
D3DXVECTOR3 vLoc;
D3DXMATRIX matTemp;
vLoc.x = 0; vLoc.y = 0; vLoc.z = 10;
D3DXMatrixTransformation( &matTemp, NULL, NULL, NULL, NULL, NULL, &vLoc );
g_Ground.SetMatrix( matTemp );
g_Ground.RestoreDeviceObjects( g_pd3dDevice );


SAFERELEASE( &matTemp );
SAFERELEASE( vLoc );

and it didnt work.
Maybe i am missing a matrix transformation or something somewhere?

[edited by - Bacardi34 on January 30, 2003 2:12:20 PM]

Share this post


Link to post
Share on other sites
ababkin    122
it''s pretty strang that u see blackness

cause to clear up the screen in render() you use 0,0,255 = blue color.

I imagine that either the camera is inside the mesh and mesh is not lighted properly, or your app doesnt render at all (for some reason)

just my $0.02

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
normally you dont need to set the fvf.

the problem could possibly be with your .x file.

if you have the dx sdk installed go to.
c:\dxsdk\samples\tutorials\tutorial 1\

the path is something like that im not completely sure cause i dont have it on this comp.

take the tiger.x and tiger.bmp files and try loading that.

/// --------------
something else I just noticed actually
your camera is at position 0,0,5 looking at position 0,0,0
and your mesh is sitting at 0,0,10.
so the mesh would be behind you

Share this post


Link to post
Share on other sites
Bacardi34    122
The other wierd thing is that when i run it in windowed mode, it cycles through colors like crazy. So something is wrong, i just am not sure what.
I know the mesh i have is good, because it works in the dxmesh view program that came with the sdk
any other thoughts?
Thanks for the input

Share this post


Link to post
Share on other sites