Sign in to follow this  
nerditup

Black Screen

Recommended Posts

Hello, I have come to try and solve a problem. I have created procedures to import a .x file using various tutorials. I have managed to Initialise and Render without Errors, however when the window shows up, it appears blank. I have added light aswell to shine on the mesh but no light appears either. I know this is a vague problem, but I am wondering what would be my problem? I will post the ...rendering? procedure of DirectX. I'm sure in order to help this I need to show something else, please ask to see it if necessary. D3DXMATRIX matShip1; g_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); g_d3dDevice->BeginScene(); //Render Graphics /////////////////////////////// g_d3dDevice->SetTransform(D3DTS_WORLD, &matShip1); cDirectX::RenderMeshes(); /////////////////////////////// g_d3dDevice->EndScene(); g_d3dDevice->Present(NULL, NULL, NULL, NULL);

Share this post


Link to post
Share on other sites
You need to set the WORLD, VIEW and PROJECTION matrices.

The WORLD matrix you're setting does not seem to be initialized. I'd suggest calling D3DXMatrixTranslation() on it to set some translation in world space, such that it's not centered on the camera.

You should clear the screen to some ugly color, such as magenta (red=1, blue=1, green=0) so that geometry that shows up in black can actually be visible -- this lets you know whether you have a texturing problem or a geometry problem.

Last, use Pix to debug drawing problems. You can record an entire frame (or an entire run of a program) and step back and forth among the different draw calls, inspect the device, and see what the different states are. Very slick.

Share this post


Link to post
Share on other sites
Thanks for the reply :)

hmm, setting these Values were done in my Camera Initialising Method, do you suggest I do it again in the Rendering?

Also when I Clear the Screen to (1, 1, 0) (Magenta) it stays black, what does this mean?

I will try and use Pix to see what I can get out of this.

...Setting this to false, Do you mean I should turn off lighting? If so I need to have a value for colour? I don't think I have that.

Share this post


Link to post
Share on other sites
Just so for some help in understanding my project,


HRESULT cDirectX::InitialiseD3D(HWND hWnd)
{
//Tell our class object which instance of class it is going to be
m_WindowClass = new cWindow();

//First of all, create the main D3D object
g_D3D = Direct3DCreate9(D3D_SDK_VERSION);

//Set the Depth Level
cDirectX::m_Depth = 32;

//Set the Device Type
cDirectX::devType = D3DDEVTYPE_HAL;

//Get the Format Based on the Depth
cDirectX::GetFormat(g_D3D, m_WindowClass->blnFullscreen, cDirectX::m_Depth, &g_Format);

//Create a structure to hold the settings for our device
D3DPRESENT_PARAMETERS d3dpp;

//Clear it
ZeroMemory(&d3dpp, sizeof(d3dpp));

//Fill the structure.
//We want our program to be windowed, and set the back buffer to a format
//that matches our current display mode

d3dpp.BackBufferCount = 1; //There is 1 Backbuffer
d3dpp.BackBufferFormat = g_Format; //The Backbuffer Format
d3dpp.hDeviceWindow = hWnd; //Handle of Our Window
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //Discard Each Frame, We Don't Need Them
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; //No multi-sampling

//If Windowed
if(m_WindowClass->blnFullscreen == false)
{
d3dpp.Windowed = TRUE;
}
//If Fullscreen
else
{
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = m_WindowClass->m_Width;
d3dpp.BackBufferHeight = m_WindowClass->m_Height;
}

//Create a Direct3D device.
g_D3D->CreateDevice(D3DADAPTER_DEFAULT, cDirectX::devType, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_d3dDevice);

//Set Some Options

//Turn on back face culling. This is becuase we want to hide the back of our polygons
g_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);

//Turn on Depth Buffering
g_d3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

//Set fill state. Possible values: D3DFILL_POINT, D3DFILL_WIREFRAME, D3DFILL_SOLID
g_d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);

//Fix the Scaling Being Darker
g_d3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);

return S_OK;
}




void cDirectX::InitialiseCamera(void)
{
//The Matrices
D3DXMATRIX ViewMatrix;
D3DXMATRIX ProjectionMatrix;
D3DXMATRIX WorldMatrix;
//The Vectors
D3DXVECTOR3 EyeVector;
D3DXVECTOR3 LookatVector;
D3DXVECTOR3 UpVector;
//The Aspect Ratio Float
float fAspect;

m_WindowClass = new cWindow();

EyeVector = D3DXVECTOR3(0.0f, 0.0f, -10.0f);

LookatVector = D3DXVECTOR3(0.0f, 0.0f, 0.0f);

UpVector = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

D3DXMatrixLookAtLH(&ViewMatrix, &EyeVector, &LookatVector, &UpVector);

cDirectX::g_d3dDevice->SetTransform(D3DTS_VIEW, &ViewMatrix);

fAspect = ((float)m_WindowClass->m_Width / (float)m_WindowClass->m_Height);

D3DXMatrixPerspectiveFovLH(&ProjectionMatrix, D3DX_PI / 4, fAspect, 1.0f, 100.0f );

cDirectX::g_d3dDevice->SetTransform(D3DTS_PROJECTION, &ProjectionMatrix);

D3DXMatrixIdentity(&WorldMatrix);

cDirectX::g_d3dDevice->SetTransform(D3DTS_WORLD, &WorldMatrix);
}




void cDirectX::Render()
{
//Define the Matrices for Our Mesh Objects
D3DXMATRIX matShip1;

//Clear the backbuffer to a Magenta color
g_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(1, 1, 0), 1.0f, 0);

//Begin the scene
g_d3dDevice->BeginScene();

//Render Graphics

//Initialise the Camera Object
cDirectX::InitialiseCamera();

///////////////////////////////
g_d3dDevice->SetTransform(D3DTS_WORLD, &matShip1);

cDirectX::RenderMeshes();
///////////////////////////////

//End the scene
g_d3dDevice->EndScene();

//Flip the back and front buffers so that whatever has been rendered on the back buffer
//will now be visible on screen (front buffer).
g_d3dDevice->Present(NULL, NULL, NULL, NULL);
}





void cDirectX::InitialiseMeshes(LPSTR pFilename)
{
LPD3DXBUFFER pMaterialsBuffer = NULL;
LPD3DXMESH pMesh = NULL;

D3DXLoadMeshFromX(pFilename, D3DXMESH_SYSTEMMEM, g_d3dDevice, NULL,
&pMaterialsBuffer, NULL, &m_dwMaterials, &pMesh);

D3DXMATERIAL* matMaterials = (D3DXMATERIAL*)pMaterialsBuffer->GetBufferPointer();

//Create two arrays. One to hold the materials and only to hold the textures
m_MeshMaterials = new D3DMATERIAL9[m_dwMaterials];
m_MeshTextures = new LPDIRECT3DTEXTURE9[m_dwMaterials];

for(DWORD i = 0; i < m_dwMaterials; i++)
{
// Copy the material
m_MeshMaterials[i] = matMaterials[i].MatD3D;

// Set the ambient color for the material (D3DX does not do this)
m_MeshMaterials[i].Ambient = m_MeshMaterials[i].Diffuse;

// Create the texture - it may not exist.
if(FAILED(D3DXCreateTextureFromFile(g_d3dDevice,
matMaterials[i].pTextureFilename,
&m_MeshTextures[i])))
{
m_MeshTextures[i] = NULL;
}
}

//Make sure that the normals are setup for our mesh
pMesh->CloneMeshFVF(D3DXMESH_MANAGED, MESH_D3DFVF_CUSTOMVERTEX, g_d3dDevice, &m_Mesh);

//Compute the Normals and Send Them to the Mesh Object
D3DXComputeNormals(m_Mesh, NULL);
}




void cDirectX::RenderMeshes()
{
for(DWORD i = 0; i < m_dwMaterials; i++)
{
//Set the material and texture for this subset
g_d3dDevice->SetMaterial(&m_MeshMaterials[i]);
g_d3dDevice->SetTexture(0, m_MeshTextures[i]);

m_Mesh->DrawSubset(i);
}
}





void cDirectX::InitialiseLight()
{
D3DLIGHT9 d3dLight;

//Initialize the light structure.
ZeroMemory(&d3dLight, sizeof(D3DLIGHT9));

d3dLight.Type = D3DLIGHT_POINT;

d3dLight.Position.x = 0.0f;
d3dLight.Position.y = 10.0f;
d3dLight.Position.z = 0.0f;

d3dLight.Attenuation0 = 0.1f;
d3dLight.Attenuation1 = 0.0f;
d3dLight.Attenuation2 = 0.0f;
d3dLight.Range = 200.0f;

d3dLight.Diffuse.r = 1.0f;
d3dLight.Diffuse.g = 1.0f;
d3dLight.Diffuse.b = 1.0f;

d3dLight.Ambient.r = 0.0f;
d3dLight.Ambient.g = 0.0f;
d3dLight.Ambient.b = 0.0f;

d3dLight.Specular.r = 0.0f;
d3dLight.Specular.g = 0.0f;
d3dLight.Specular.b = 0.0f;

//Assign the point light to our device in poisition (index) 0
g_d3dDevice->SetLight(0, &d3dLight);

//Enable our point light in position (index) 0
g_d3dDevice->LightEnable(0, TRUE);

//Turn on lighting
g_d3dDevice->SetRenderState(D3DRS_LIGHTING, true);

//Set ambient light level
g_d3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(100, 100, 100));
}



all of these functions are called within the project, the majority are called in a initialise game function. I think the problem is in how the DirectX is initialised, it just won't produce any results.

Share this post


Link to post
Share on other sites

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