Jump to content
  • Advertisement
Sign in to follow this  
PumpkinPieman

Passing a vertex list through a function.

This topic is 5454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I know forsure that my vertices are in the VB? I think I may have messed up somewhere. Declarations:
struct my_vertex
{
    FLOAT x, y, z, rhw; // The transformed position for the vertex.
    DWORD colour; // The vertex colour.
};

#define D3D8T_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

my_vertex g_triangle_vertices[] =
{
	{250.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0),}, //Vertex 1 - Red (250, 100)
	{400.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0),}, //Vertex 2 - Green (400, 350)
	{100.0f, 350.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255),}, //Vertex 3 - Blue (100, 350)
};



WinMain
if(!NewWindow.d3d_load_vertexbuffer(&VB, (BYTE**)g_triangle_vertices, 3*sizeof(my_vertex),D3D8T_CUSTOMVERTEX)){
				MB("Vertex Buffer Not Loaded");
			}
			IDirect3DDevice8* localdevice = NewWindow.d3d_return_device();

...




			while(msg.message != WM_QUIT){
				if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)){
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}

				localdevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
				localdevice->SetStreamSource(0,VB,sizeof(my_vertex));
				NewWindow.d3d_scene_clear();
				if(NewWindow.d3d_scene_begin())
				{
					if(FAILED(localdevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1))){
						NewWindow.d3d_draw_font(&Font2, "Failed ...", 20, 40, D3DCOLOR_RGBA(255,255,255,255));
					}else{
						NewWindow.d3d_draw_font(&Font2, "Successful ...", 20, 40, D3DCOLOR_RGBA(255,255,255,255));
					}

					NewWindow.d3d_scene_end();
				}
				NewWindow.d3d_scene_present();
			}




cDirect3D.cpp
bool cDirect3D::d3d_load_vertexbuffer(LPDIRECT3DVERTEXBUFFER8* pp_vb, const void* pv_Vertices, UINT v_size, DWORD FVF, DWORD useage)
{
	if(FAILED(m_d3d_device->CreateVertexBuffer(v_size, useage, FVF, D3DPOOL_MANAGED, pp_vb))){
		return false;
	}
	d3d_update_vertexbuffer(pp_vb, pv_Vertices, 0);
	return true;
}

bool cDirect3D::d3d_update_vertexbuffer(LPDIRECT3DVERTEXBUFFER8* pp_vb, const void* pv_Vertices, UINT v_size)
{
	assert((*pp_vb)!=NULL); 

	VOID* pVertices;
    if(FAILED((*pp_vb)->Lock(0, v_size, (BYTE**)&pVertices, 0)))
    {
        return false;
    }
    memcpy(pVertices, pv_Vertices, v_size);
    (*pp_vb)->Unlock();

	return true;
}



Share this post


Link to post
Share on other sites
Advertisement
You're not passing the size parameter to your vb update function, so it's not copying anything


bool cDirect3D::d3d_load_vertexbuffer(LPDIRECT3DVERTEXBUFFER8* pp_vb, const void* pv_Vertices, UINT v_size, DWORD FVF, DWORD useage)
{
if(FAILED(m_d3d_device->CreateVertexBuffer(v_size, useage, FVF, D3DPOOL_MANAGED, pp_vb))){
return false;
}
-->d3d_update_vertexbuffer(pp_vb, pv_Vertices, v_size);
return true;
}

Share this post


Link to post
Share on other sites
This is along the same topic. I'm working with indices right now and have the same function layout. It's giving me a problem when trying to render that one poly.
WinMain.cpp
Declarations

DWORD my_index[] = {0,1,2};
LPDIRECT3DINDEXBUFFER8 IB = NULL;




WinMain.cpp
WinMain

if(!NewWindow.d3d_load_indexbuffer(&IB, my_index, 3*sizeof(DWORD))){
MB("Index Buffer Not Loaded");
localdevice->SetTexture(0, Texture);
localdevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
localdevice->SetVertexShader(D3D8T_CUSTOMVERTEX);
localdevice->SetStreamSource(0,VB,sizeof(my_vertex));

localdevice->SetIndices(IB, 0);
// inside render loop
// localdevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
NewWindow.d3d_draw_font(&Font, "Vertex Rendering", 20, 20, D3DCOLOR_RGBA(180,33,33,255));
if(FAILED(localdevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 3, 0, 1))){
NewWindow.d3d_draw_font(&Font2, "Failed ...", 20, 40, D3DCOLOR_RGBA(255,255,255,255));
}else{
NewWindow.d3d_draw_font(&Font2, "Successful ...", 20, 40, D3DCOLOR_RGBA(255,255,255,255));
}




cDirect3D.cpp

bool cDirect3D::d3d_load_indexbuffer(LPDIRECT3DINDEXBUFFER8* pp_ib, const void* pi_Vertices, UINT i_size, DWORD useage)
{
D3DPOOL POOL;
if(useage == D3DUSAGE_DYNAMIC){
POOL = D3DPOOL_DEFAULT;
}else{
POOL = D3DPOOL_MANAGED;
}
if(FAILED(m_d3d_device->CreateIndexBuffer(i_size, useage, D3DFMT_INDEX16, POOL, pp_ib))){
return false;
}

return d3d_update_indexbuffer(pp_ib, pi_Vertices, i_size);
}

bool cDirect3D::d3d_update_indexbuffer(LPDIRECT3DINDEXBUFFER8* pp_ib, const void* pi_Vertices, UINT i_size, DWORD Flags)
{
assert((*pp_ib)!=NULL); // Just so I don't need to do a single if statement during locking and unlocking
VOID* pIndices;
if(FAILED((*pp_ib)->Lock(0, i_size, (BYTE**)&pIndices, Flags)))
{
return false;
}
memcpy(pIndices, pi_Vertices, i_size);
(*pp_ib)->Unlock();

return true;
}

bool cDirect3D::d3d_unload_indexbuffer(LPDIRECT3DINDEXBUFFER8* pp_ib)
{
if((*pp_ib)!=NULL){
(*pp_ib)->Release();
(*pp_ib) = NULL;
}
return true;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!