Direct 3D Simple pipeline problem?

Hi

I am creating my first direct3d program and have just created a pipeline and as you probably guessed can't work out why the triangle I have created is not being drawn to screen. I have included my Direct3D class which initialises the device and renders the image to screen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "Direct3D.h"

DefineSingleton(Direct3D);

Direct3D::Direct3D(void)
{
	m_Rotate = 0.0f;
}
Direct3D::~Direct3D(void)
{
	m_vbuffer->Release();    // close and release the vertex buffer
	m_D3Ddev->Release();    // close and release the 3D device
	m_D3D->Release();    // close and release Direct3D

}
int
Direct3D::CreateDevice(HWND hWindow,int ScreenWidth, int ScreenHeight,bool Windowed)
{
	HRESULT hRes;	//Variable for error checking
	m_screenWidth = ScreenWidth;
	m_screenHeight = ScreenHeight;
	m_Windowed = Windowed;

	m_D3D = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use

	if(Windowed)
	{
		d3dpp.Windowed = TRUE;    // program windowed
	}
	else
	{
		d3dpp.Windowed = FALSE;    // program fullscreen
	}

    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWindow;    // set the window to be used by Direct3D

	//This sets the bit channels to 8 per channel
	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;    // set the back buffer format to 32-bit
    d3dpp.BackBufferWidth = ScreenWidth;    // set the width of the buffer
    d3dpp.BackBufferHeight = ScreenHeight;    // set the height of the buffer

    // create a device class using this information and information from the d3dpp stuct
    hRes = m_D3D->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWindow,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &m_D3Ddev);
	
	if (hRes != S_OK)
	{
		return 0;
	}

	//Set the light
	m_D3Ddev->SetRenderState(D3DRS_LIGHTING, FALSE);    // turn off the 3D lighting

	return 1;

}
void
Direct3D::RestoreSurfaces()
{
}
void
Direct3D::ClearSurface(HWND hWindow)
{
}
void
Direct3D::PresentBackBuffer(HWND hWindow)
{
}
void
Direct3D::RenderFrame()
{
	//As an example clear window to blue
    m_D3Ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    m_D3Ddev->BeginScene();    // begins the 3D scene

    //Any 3D rendering onto the back buffer to be done here
	// select which vertex format we are using
	m_D3Ddev->SetFVF(CUSTOMFVF);

	/************************************************************************************************************************/
	//SET UP PIPELINE
	/*************************************************************************************************************************/
	//WORLD TRANSFORMATION
	/*************************************************************************************************************************/
	D3DXMATRIX matrixRotateY;    // a matrix to store the rotation information on X axis

	m_Rotate += 0.5f;
	// build a matrix to rotate the model by Rotate
	D3DXMatrixRotationX(&matrixRotateY, m_Rotate);

	// tell Direct3D about our matrix
	m_D3Ddev->SetTransform(D3DTS_WORLD, &matrixRotateY);
	/*****************************************************************************************************************************/
	//VIEW TRANSFORMATION
	/******************************************************************************************************************************/
	D3DXMATRIX matrixView;    // the view transform matrix

	D3DXMatrixLookAtLH(&matrixView,
					   &D3DXVECTOR3 (100.0f, 100.0f, 100.0f),    // the camera position
					   &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
					   &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction

	m_D3Ddev->SetTransform(D3DTS_VIEW, &matrixView);    // set the view transform to matrixView
	/***********************************************************************************************************************/
	//PROJECTION TRANSFORMATION
	/***********************************************************************************************************************/
	D3DXMATRIX matrixProjection;    // the projection transform matrix

	D3DXMatrixPerspectiveFovLH(&matrixProjection,
							   D3DXToRadian(45),    // the horizontal field of view
							   (FLOAT)m_screenWidth / (FLOAT)m_screenHeight,    // aspect ratio
							   1.0f,    // the near view-plane
							   100.0f);    // the far view-plane

	m_D3Ddev->SetTransform(D3DTS_PROJECTION, &matrixProjection);    // set the projection transform

	/***************************************************************************************************************************/

	// select the vertex buffer to display
	m_D3Ddev->SetStreamSource(0, m_vbuffer, 0, sizeof(CustomVertex));

	// copy the vertex buffer to the back buffer
	m_D3Ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    m_D3Ddev->EndScene();    // ends the 3D scene

    m_D3Ddev->Present(NULL, NULL, NULL, NULL);    // displays the created frame

}
void
Direct3D::InitialiseGraphics(Triangle* tri)
{
	 // create the vertex and store the pointer into v_buffer
   m_D3Ddev->CreateVertexBuffer(tri->NumVertices*sizeof(CustomVertex),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &m_vbuffer,
                               NULL);

    VOID* pVoid;    // the void pointer

    m_vbuffer->Lock(0, 0, (void**)&pVoid, 0);    // lock the vertex buffer
    memcpy(pVoid, tri->m_Vertex, sizeof(tri->m_Vertex));    // copy the vertices to the locked buffer
    m_vbuffer->Unlock();    // unlock the vertex buffer

}
LPDIRECT3DDEVICE9
Direct3D::GetDirect3DObject()
{
	return m_D3Ddev;
}


I have a triangle object which is passed into the Initialise function, this triangle has 3 vertices which are defined when I load my assets.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void
Game::LoadAssets()
{
	//m_test = new OffsetSprite();
	//m_test->LoadOffsetSprite("TEST","..\\test.bmp",5 ,3.00f, 10, 10);

	//Set up a triangle and fill vertices
	m_triangle = new Triangle();
	m_triangle->SetVertex(3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), 1);
    m_triangle->SetVertex(0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), 2);
    m_triangle->SetVertex(-3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), 3);
	Direct3D::GetInstance()->InitialiseGraphics(m_triangle);


}


If anything else is needed then let me know....and go easy on the jargon, Im no pro :)

Phantompig
Umm never used direct 3d but i'm guessing here. After setting your Vertex's & Color with

Direct3D::GetInstance()->InitialiseGraphics(m_triangle);

Use on line 13
Direct3d::GetInstance()->RenderFrame();


Being that just looking through the code RenderFrame() Actually puts the object onto the screen and
InitialiseGraphics() Just puts the object into memory.
Last edited on
Sorry I should have been clearer... the RenderFrame() is called in the programs main loop, away from my comp at the mo but will double check the RenderFrame() is being executed.

Any other suggestions are greatly appreciated
Its really hard to say without seeing what is happening in your other code.
the direct3d looks pretty strait forward. I will play with it and see what report what i find. Like i said i never have used it. It just looks like you first pass your your window that your working with to Direct3d::CreateDevice();
Then just pass the verticals into Direct3D::InitialiseGraphics();
Then just call Direct3d::RenderFrame();

Like i said I will play with.
Topic archived. No new replies allowed.