Skip to main content
gamedev.net
🔒 Locked

Serius problem (D3D9)

Started by cjb0087 4 replies 1.6k views
Original Post
cjb0087
cjb0087
ive tried everything i can think of, end even checked my code against the tutorials'' sample (SDK) my poly isnt showing up at all. here is me code: //include d3d9 interface #include <Windows.h> #include <mmsystem.h> #include <d3dx9.h> //lib''s needed #pragma comment (lib, "winmm.lib") #pragma comment (lib, "d3d9.lib") #pragma comment (lib, "d3dx9dt.lib") #pragma comment (lib, "d3dxof.lib") #pragma comment (lib, "dxguid.lib") #pragma comment (lib, "d3dx9.lib") //custom vertex type struct VERTEXSTRUCT { float x,y,z; //transformed position for the vertex DWORD color; //vertex colour }; #define VERTEXFVF (D3DFVF_XYZ|D3DFVF_DIFFUSE) //d3d variables LPDIRECT3D9 d3d = NULL; //d3d object LPDIRECT3DDEVICE9 d3ddevice = NULL; //rendering device PDIRECT3DVERTEXBUFFER9 vertexbuffer = NULL; // Buffer to hold vertices //window variables HWND hwnd = NULL; //window handle bool initd3d() { //create the d3d9 thing if (NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION))) return false; //how the device behaves D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp,sizeof(d3dpp)); d3dpp.Windowed = true; //running windowed d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //discard prev frame after flipping d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; //use current display mode if( FAILED( d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddevice ) ) ) return false; // Turn off culling d3ddevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Turn off lighting d3ddevice->SetRenderState( D3DRS_LIGHTING, FALSE ); return true; } void cleanup() { //release used dx objects if (vertexbuffer != NULL) vertexbuffer->Release(); if (d3ddevice != NULL) d3ddevice->Release(); if (d3d != NULL) d3d->Release(); } void setupmatrices() { D3DXMATRIX matWorld, matView, matProjection; D3DXMatrixRotationY(&matWorld, timeGetTime()/100.0f ); d3ddevice->SetTransform(D3DTS_WORLD,&matWorld); D3DXMatrixLookAtLH(&matView,&D3DXVECTOR3(0,3,-5),&D3DXVECTOR3(0,0,0),&D3DXVECTOR3(0,1,0)); d3ddevice->SetTransform(D3DTS_VIEW, &matView); D3DXMatrixPerspectiveFovLH(&matProjection,D3DX_PI/4,1.0f,1.0f,1.00f); d3ddevice->SetTransform(D3DTS_PROJECTION, &matProjection); } void render() { // Clear the back buffer to a red color d3ddevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); // Begin the scene if(SUCCEEDED(d3ddevice->BeginScene())) { // Setup the world, view, and projection matrices setupmatrices(); // Render the vertex buffer contents d3ddevice->SetStreamSource(0, vertexbuffer, 0, sizeof(VERTEXSTRUCT)); d3ddevice->SetFVF(VERTEXFVF); d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1); // End the scene d3ddevice->EndScene(); } // Present the backbuffer contents to the display d3ddevice->Present( NULL, NULL, NULL, NULL ); } bool initgeom() { //create the array of verts for processing VERTEXSTRUCT verts[] = { { -1.0f,-1.0f, 0.0f, 0xffff0000, }, { 1.0f,-1.0f, 0.0f, 0xff0000ff, }, { 0.0f, 1.0f, 0.0f, 0xffffffff, }, }; //create the vertex buffer if (FAILED(d3ddevice->CreateVertexBuffer(3*sizeof(VERTEXSTRUCT),0,VERTEXFVF,D3DPOOL_DEFAULT,&vertexbuffer,NULL))) return false; //place verts into vertex buffer VOID* pVertices; if(FAILED(vertexbuffer->Lock( 0, sizeof(verts), (void**)&pVertices, 0 ) ) ) return false; memcpy(pVertices, verts, sizeof(verts)); vertexbuffer->Unlock(); return true; } LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc( hWnd, msg, wParam, lParam ); } INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ) { // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "D3D Window", NULL }; wc.hCursor = LoadCursor(NULL, IDC_ARROW); RegisterClassEx(&wc); // Create the application''s window hwnd = CreateWindow( "D3D Window", "D3D Window", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL ); // Initialize Direct3D if(initd3d()) { ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); MSG msg; ZeroMemory( &msg, sizeof(msg) ); if(initgeom()) //only continue if the vertex buffer was made successfully { while( msg.message!=WM_QUIT ) { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else render(); } } } cleanup(); UnregisterClass( "D3D Window", wc.hInstance ); return 0; }
Random Number
Random Number
Try changing your background to white and setting the render state to wire frame. I had a similar problem before and that worked for me.

So do

d3ddevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );

and maby try

d3ddevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);

if all goes well u will see your polygon in wireframe now. =D

Let me know how it goes.



[edited by - Random Number on April 17, 2004 12:23:23 PM]
Game Programming Nub: Dont listen to me
henrym
henrym
quote:
Original post by cjb0087
...
D3DXMatrixRotationY(&matWorld, timeGetTime()/100.0f );
d3ddevice->SetTransform(D3DTS_WORLD,&matWorld);
...



Try leaving the world matrix alone... or set it to the Identity. It's the only thing that stands out to me as being odd.

When I run timeGetTime it returns a value of around 3 million. Dividing that by 100 and we see that we're trying to rotate by 30000 radians - about 5000 whole rotations...

[edited by - henrym on April 17, 2004 6:05:20 PM]
cjb0087
cjb0087
meh, I''ve started again with DESIGNING the code layout so hopefully it should be more structered and easier to read, but tahnks for the help anyway
cjb0087
cjb0087
jsut got the same probalem, i cleared the backbuffer to white and lo and behold there was a black polygon there
Kawahee
Kawahee
quote:

#include <Windows.h>
#include <mmsystem.h>
#include <d3dx9.h>



correct me if i''m wrong, but don''t u need #include?

I''m a signature virus, copy me into your signature and help me spread!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.