Jump to content
  • Advertisement
Sign in to follow this  

Totally newb direct3D problem with invisable geometry

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

Hey all, i was wondering if you could help me out here, I'm trying to make a simple demo that will create a triangle, but I can't seem to see my geometry, In the main function I intialise Direct3D like this:
// Global variables
LPDIRECT3D9             g_pD3D       = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9       g_pd3dDevice = NULL; // Our rendering device

Pryamid FirstCollectable; //

// Name: InitD3D()
// Desc: Initializes Direct3D
    // Create the D3D object, which is needed to create the D3DDevice.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

    // Create the Direct3D device    
                                      &d3dpp, &g_pd3dDevice ) ) )
        return E_FAIL;

    // Device state would normally be set here
	g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255));

    // Turn off D3D lighting, since we are providing our own vertex colors
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

    return S_OK;

With that lot done i try to draw using this
// Name: Render()
// Desc: Draws the scene
VOID Render()
    if( NULL == g_pd3dDevice )

    // Clear the backbuffer to a black color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
        // Rendering of scene objects can happen here
	FirstCollectable.DrawPryamid (g_pd3dDevice);
        // End the scene

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

Once that lot is done my WinMain looks a bit like this:
// Name: WinMain()
// Desc: The application's entry point
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "D3D Tutorial", NULL };
    RegisterClassEx( &wc );

    // Create the application's window
    HWND hWnd = CreateWindow( "D3D Tutorial", "ICA", 
                              WS_OVERLAPPEDWINDOW, 100, 100, 800, 600,
                              NULL, NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
        // Show the window
        // Create Some Geometry
		FirstCollectable.Initialise (g_pd3dDevice, g_pD3D, g_pVertexBuffer );
		// Set up a camera (or matricees)
		Camera newcamera (g_pd3dDevice); 

		ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );
        // Enter the message loop
        MSG msg; 
        while( GetMessage( &msg, NULL, 0, 0 ) )
            TranslateMessage( &msg );
            DispatchMessage( &msg );

    UnregisterClass( "D3D Tutorial", wc.hInstance );
    return 0;

I have classes to initialise the triangle that go like this:
void Pryamid::Initialise (LPDIRECT3DDEVICE9 gp_D3dDevice, LPDIRECT3D9 g_pD3D, LPDIRECT3DVERTEXBUFFER9 gp_VertexBuffer)
VertexBuffer = gp_VertexBuffer;
gp_D3dDevice->CreateVertexBuffer( 3*sizeof(newVertex), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &VertexBuffer, NULL );

VertexBuffer->Lock (0,0,(void**)&newVertex,0);

newVertex[0].FillVertex (-1.0f, -1.0f, 0.0f, 0xffff0000);
newVertex[1].FillVertex ( 1.0f, -1.0f, 0.0f, 0xff0000ff);
newVertex[2].FillVertex ( 0.0f,  1.0f, 0.0f, 0xffffffff);

VertexBuffer->Unlock ();
Once that is initialised i use this to draw:
void Pryamid::DrawPryamid (LPDIRECT3DDEVICE9 gp_D3dDevice)
	// To draw we pass the vertices down a stream. We set the source as our vertex buffer	
	// We then tell Direct3D the make up of the vertices

	// Now draw our one triangle
I guess you might want to see the pryamid.h file :):

class Pryamid
	void DrawPryamid (LPDIRECT3DDEVICE9);
	LPDIRECT3DDEVICE9 m_Direct3DDevice;
	Vertex newVertex [3];

and finally i have a camera class that i use to setup all my matricees:
#include "Camera.h"

Camera::Camera(LPDIRECT3DDEVICE9 gp_D3dDevice)
	FLOAT fAspect=((FLOAT)800)/600;

	// View Matrix
	// Set the camera back a bit along the Z axis and looking down Z	
	D3DXMATRIX matView;	
	D3DXVECTOR3 vEyePt(0.0f,1.0f,-3.0f );
	D3DXVECTOR3 vLookatPt(0.0f,0.0f,1.0f );
	D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f );		
	D3DXMatrixLookAtLH(&matView,&vEyePt,&vLookatPt,&vUpVec );
	gp_D3dDevice->SetTransform(D3DTS_VIEW,&matView ); 

	// World Matrix
	// Just using identity (so triangle is at origin of world)
	D3DXMATRIX matWorld;
	gp_D3dDevice->SetTransform(D3DTS_WORLD, &matWorld ); 

Well thats about it, all i get is a black screen with nothing showing at all. If there was anything else that you think you need to tell me whats going on please let me know. Oh and I'm sorry to be begging for help, but I'm a total newb at doing anything much with directx and well i didn't really know what else i should do :(

Share this post

Link to post
Share on other sites
two sugestions:
1. try moving the cam a couple of steps back , cause you might be standing infront of it.
2. turn off back face culling

if not instructed other wise , direct3d will remove one face of a polygon , assuming you will
never see that face. for example if you have a decorative crate , the player wouldn't be
allowed to look inside such a thing , so direct3d doesn't render at all to save some cpu cycles.
see D3DRS_CULLMODE in the directx SDK documentation.

Share this post

Link to post
Share on other sites
I think your problem is that your triangle points are declared in a counter-clockwise order. You are looking at what directx thinks is the backside of your triangle. Make your points in a clockwise order and it should work.

Share this post

Link to post
Share on other sites
I've tried inverting the order which I initialise the verticess and it hasn't made any difference :( anyhoo, i have uploaded the code onto my webspace download it here its built for visual studio 2005 rather than 2003 (i dunno how many people still us that)

i wish i knew what was wrong with this, I think that I've got everything in there and it matches up pretty much perfectly with the demos from microsoft.

Share this post

Link to post
Share on other sites
That site looks good, I think I'm ok when it comes to the actual starting of it, its just when i split the files up into seperate classes that i really have trouble.

PLEASE CAN SOMEONE HELP ME! Is there something blinding obvious that I'm missing here? I think that I've checked every tutorial and forum i can and i still can't see whats wrong with this bloody thing!

[Edited by - -pete- on August 14, 2006 7:11:34 AM]

Share this post

Link to post
Share on other sites
There's a tool in the DirectX SDK called 'PIX' that will help here (though you need the most recent version of it - August 2006). Take a single-frame PIX capture of your program and then look at what it's doing.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!