Why does my .x model not show ?

Started by
3 comments, last by rfterdarc 17 years, 6 months ago
Hi guys , in the article posted here http://www.gamedev.net/reference/articles/article2079.asp I tried to implement the drawing of x files into my own app but , i cannot get my model to show at ALL..what the heck am i doing wrong ? I`ll try and show some code ..but PLEASE HELP ME PLEASE !! OK first i set the global vars: CModel* g_pModel= NULL; // A model object to work with Then i load the file like so : SAFE_DELETE(g_pModel); g_pModel = new CModel(gd3dDevice); g_pModel->LoadXFile("tiny.x"); Then I draw it: HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER |D3DCLEAR_STENCIL, 0x0099FF, 0.0f, 0)); HR(gd3dDevice->BeginScene()); //draw the model //Update the model g_pModel->Update(1); //what should this be ? or does it not matter ? g_pModel->Draw(); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); BUT NOTHING SHOWS !!?? This is my camera and projection setup -> // Sets up the camera 1000 units back looking at the origin. D3DXMATRIX V; D3DXVECTOR3 pos(0.0f, 0.0f, -1000.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); //to rotate VIEW ANGLE D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXMatrixLookAtLH(&V, &pos, &target, &up); HR(gd3dDevice->SetTransform(D3DTS_VIEW, &V)); // The following code defines the volume of space the camera sees. D3DXMATRIX P; RECT R; GetClientRect(mhMainWnd, &R); float width = 800; float height = 600; D3DXMatrixPerspectiveFovLH(&P, D3DX_PI*0.25f, width/height, 1.0f, 2500.0f); HR(gd3dDevice->SetTransform(D3DTS_PROJECTION, &P)); And this is my render states ---> // This line of code disables Direct3D lighting. HR(gd3dDevice->SetRenderState(D3DRS_LIGHTING, false)); // Turn on the zbuffer gd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE); // ***** // Culling gd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); // **** // The following code specifies an alpha test and reference value. HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 10)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER)); // The following code is used to setup alpha blending. HR(gd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE)); HR(gd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1)); HR(gd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)); HR(gd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)); gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); //***** // Indicates that we are using 2D texture coordinates. HR(gd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2)); So basically ..i`m lost ..please HELP !!? [Edited by - Tenshi_rdk on October 20, 2006 5:39:14 PM]
Advertisement
it's been awhile since i've used the DirectX API

you're loading tiny.x and setting camera 1000 away? Maybe it's too small to show up? Try scaling it or loading a different model?
How do i scale it ?
And i saw somewhere i need to setup a WORLD MATRIX ??
What is that , is it really nessecary ?

Or how do i translate my model to be 100% sure it's at 0,0,0 coordinates ?

Please ! THANKS !
i just got my model to show !!!

the problem was with this ..
HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER |D3DCLEAR_STENCIL, 0x00000000, 0.0f, 0));

i had to change it to (the z value)

HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER |D3DCLEAR_STENCIL, 0x00000000, 1.0f, 0));

but i`m sure I fiddled with it before...can someone explain to me why this happened ?

i Dont understand it..PLEASE ( for future reference )
clearing the z buffer (depth buffer) to 0.0f means that every pixel drawn will(?) fail the depth test (by default less than or equal to) and not be drawn to the screen

e.g.

draw a cube, the pixels it will have z values of like...... 100, 230.56f, (greater than 0), ...

the depth test is: draw the pixel if its less than or equal to the current pixel (0.0f)...
draw if 100 <= 0
draw if 230.56f <= 0

setting the z to 1.0f in the clear function, means each pixel will be its maximum value... from the projection matrix i think

This topic is closed to new replies.

Advertisement