Skip to main content
gamedev.net
🔒 Locked

Primitive drawing

Started by foursticksj 1 reply 1.1k views
Original Post
foursticksj
foursticksj
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.

// 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:





Photobucket
valles
valles
Without compiling the code I see a few problems:
1) Your index isn't increasing.
2) Your RotateY should be run after your camera settings.
3) The z values for your triangle aren't within the near and far plane.
foursticksj
foursticksj
The index is static, It is definitely increasing.
The point I was trying to make was that if I put the z values of the triangle in between front and far view plane, nothing shows up on the screen. If I run the code as shown above, I get the screenshot as a result. I'm a bit confused on the exact values I should use for my settings.

Which values should I use (for vertices, view, and projection) that I would know without a doubt that isn't the problem?


Topic Locked

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

Sign in to reply to this topic.