Here is my Direct3D initialization routine:
int Init_Direct3D(HWND hwnd, int width, int height, bool fullscreen){ //initialize Direct3D d3d = Direct3DCreate9(D3D_SDK_VERSION); if (d3d == NULL) { MessageBox(hwnd, L"Error initializing Direct3D", L"Error", MB_OK); return 0; } //set Direct3D presentation parameters D3DDISPLAYMODE dm; d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = (!fullscreen); d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.BackBufferFormat = dm.Format; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = width; d3dpp.BackBufferHeight = height; d3dpp.hDeviceWindow = hwnd; //Only needed for dialog boxes d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; //create Direct3D device d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); if (d3ddev == NULL) { MessageBox(hwnd, L"Error creating Direct3D device", L"Error", MB_OK); return 0; } //clear the backbuffer to black d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); //create pointer to the back buffer d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); D3DXCreateSprite(d3ddev, &sprite_handler); //turn dynamic lighting and z-buffering off d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE); d3ddev->SetRenderState(D3DRS_ZENABLE, FALSE); //set the Direct3D stream to use the custom vertex d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); return 1;}
Here's the game initialization:
int Game_Init(HWND hwnd){ //Position the camera: Camera position, camera lookat, and up direction SetCameraUp(0,0,-5, 0,0,0, 0,1,0); float ratio = (float)SCREEN_WIDTH / (float)SCREEN_HEIGHT; SetPerspective(45.0f, ratio, 0.1f, 10000.0f); //Set up the projection matrix (may wish to tweak this) //turn dynamic lighting off, z-buffering on d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE); d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE); //set the Direct3D stream to use the custom VERTEXUV d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1); //Load resources. LoadResources(); //Set up the level. CreateGrid(10, 10, 10); //Timer functions //--------------- timeBeginPeriod(1); return 1;}
LoadResources() leads to the code that creates my mesh, which I do like so:
D3DXCreateTeapot(d3ddev, &Mesh_sphere1, NULL);
Then, here's my draw routine:
//DRAW ROUTINE //------------ if(render_scene) { ClearScene(D3DCOLOR_ARGB(0,0,0,0)); if(d3ddev->BeginScene() == D3D_OK) { //Draw the level. DrawGrid(); DrawPlayers(); //Draw a sprite in the corner. sprite_handler->Begin(D3DXSPRITE_ALPHABLEND); //Print the framerate. char fps_string[256]; sprintf(fps_string, "FPS: %d", fps_framerate); DrawFont(&Font1, sprite_handler, fps_string, 320, 10); sprite_handler->End(); fps_framecount++; d3ddev->EndScene(); } d3ddev->Present(0,0,0,0); }
Inside of DrawPlayers(), here's the one line I've been using to draw the mesh.
I've also tried creating a material and setting d3ddev's material to that, but I see no difference.
Mesh_sphere1->DrawSubset(0);
Maybe that will be helpful. Thanks for the reply! Sorry, I am still somewhat of a beginner at this D3D Mesh-drawing stuff.
I will check on that debug runtime thing.