Jump to content
  • Advertisement
Sign in to follow this  

Black Screen

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

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

//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
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;
//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);


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

//Render Graphics

//Initialise the Camera Object

g_d3dDevice->SetTransform(D3DTS_WORLD, &matShip1);


//End the scene

//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;

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 = matMaterials.MatD3D;

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

// Create the texture - it may not exist.
m_MeshTextures = 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->SetTexture(0, m_MeshTextures);


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
Sign in to follow this  

  • 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!