Original Post
I am trying to draw a rotating triangle using Direct X in the DXUT framework.
I posted a question recently on this same subject drawing a 2D triangle, which would not show up on the screen. Now, using the untransformed vertices method, the 3D triangle again, will not get drawn to the screen.
I did some troubleshooting, every function here gets called. Also, when I set the near view plane to the same value as the camera's Z coordinate, a wavering line appears in the middle of the screen (see screenshot). Other than that, the triangle never shows up.
I have tried moving the near view plane to 1.0f, as well as moving the camera closer. Nothing shows up unless the near view plane is set to the same value as the camera's Z coordinate, in which case I get a random flashing line like this:
I posted a question recently on this same subject drawing a 2D triangle, which would not show up on the screen. Now, using the untransformed vertices method, the 3D triangle again, will not get drawn to the screen.
I did some troubleshooting, every function here gets called. Also, when I set the near view plane to the same value as the camera's Z coordinate, a wavering line appears in the middle of the screen (see screenshot). Other than that, the triangle never shows up.
// FVF and vertex struct#define JGDK_BASICFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)struct JGDK_BASICVERTEX // USE JGDK_BASICFVF{ FLOAT x, y, z; DWORD color; };/* ........... */// Init functionbool GameApp::init (const WCHAR* title, HINSTANCE hInstance, bool isWindowed, int suggestedWidth, int suggestedHeight){/* initialize app ................*/ // create vertices and vertex Buffer, and store the vertices in the buffer JGDK_BASICVERTEX vertices[] = { { 2.5f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), }, { 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), }, { -2.5f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), }, }; DXUTGetD3D9Device ()->CreateVertexBuffer(3*sizeof(JGDK_BASICVERTEX), 0, JGDK_BASICFVF, D3DPOOL_MANAGED, &m_vertexBuffer, NULL); VOID* pVoid; m_vertexBuffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); m_vertexBuffer->Unlock(); DXUTGetD3D9Device ()->SetRenderState(D3DRS_LIGHTING, FALSE);return true;}void GameApp::vOnFrameRender (void){ DXUTGetD3D9Device ()->BeginScene (); static float index = 0.0f; index+=0.05; // an ever-increasing float value DXUTGetD3D9Device ()->SetFVF(JGDK_BASICFVF); D3DXMATRIX matRotateY; D3DXMatrixRotationY(&matRotateY, index); DXUTGetD3D9Device ()->SetTransform(D3DTS_WORLD, &matRotateY); D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (0, 0.0f, 10.0f), &D3DXVECTOR3 (0.0f, 0.0f, 0.0f), &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); DXUTGetD3D9Device ()->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), (FLOAT) 800 / (FLOAT)600, 10.0f, 100.0f); DXUTGetD3D9Device ()->SetTransform(D3DTS_PROJECTION, &matProjection); DXUTGetD3D9Device ()->SetStreamSource(0, m_vertexBuffer, 0, sizeof(JGDK_BASICVERTEX)); DXUTGetD3D9Device ()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); g_HUD.OnRender( m_timer.getDelta ()); DXUTGetD3D9Device ()->EndScene ();// DXUT calls the device's Present () function after this callback is returned}I have tried moving the near view plane to 1.0f, as well as moving the camera closer. Nothing shows up unless the near view plane is set to the same value as the camera's Z coordinate, in which case I get a random flashing line like this: