Jump to content

  • Log In with Google      Sign In   
  • Create Account


BSOD

Member Since 02 May 2012
Offline Last Active May 03 2012 06:45 AM
-----

Posts I've Made

In Topic: Vertex format problem

03 May 2012 - 06:10 AM

Hmm, actually this work and the program works fast. Because I was think such of loop will slow it down and that's way I was searching for some tricks. Anyway thanks for the advice.

In Topic: Vertex format problem

03 May 2012 - 04:19 AM

Lol here what I'll read this summer about -

shading. But for now here is what I do: I use a block of structures to store the vertex from the file and then I put it into the vertex buffer. Here is the code:



//The structure where I store the vertex
struct CUSTOMVERTEX {
CUSTOMVERTEX();
FLOAT X, Z, Y; FLOAT U, V, U1, V1; DWORD COLOR, COLOR1, COLOR2;
};

//The vertex format declaration

D3DVERTEXELEMENT9 dwDecl3[] =
	{
{0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_TEXCOORD, 0},
		{0, 20, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT,
									 D3DDECLUSAGE_TEXCOORD, 1},
		{0, 28, D3DDECLTYPE_D3DCOLOR,   D3DDECLMETHOD_DEFAULT,
									 D3DDECLUSAGE_FOG, 0},
{0, 32, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_COLOR, 1},
   {0, 36, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT,
								 D3DDECLUSAGE_COLOR, 0},
		D3DDECL_END()
	};

//The function creating the vertex buffer
void Room::CreateBuffers(unsigned long ptr, Map* BaseClass) {
//Some code........

CUSTOMVERTEX* vertex;
vertex=new CUSTOMVERTEX[NumVertices];

GetF(0, ptr+56+BaseClass->MapOffset, sizeof(CUSTOMVERTEX)*NumVertices, &vertex[0]);	  //Load the vertex positions from the file

//Create the buffer


d3ddev->CreateVertexBuffer(NumVertices*sizeof(CUSTOMVERTEX),
								   0,
								   0,
								   D3DPOOL_MANAGED,
								   &v_buffer,
								   NULL);

		 VOID* pVoid;	// a void pointer

		 // lock t_buffer and load the vertices into it
if(v_buffer) {
		 v_buffer->Lock(0, 0, (void**)&pVoid, 0);
		 memcpy(pVoid, vertex, NumVertices*sizeof(CUSTOMVERTEX));
		 v_buffer->Unlock();
delete[] vertex;
}
else
vertex=NULL;

d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
}



Any advice about this code. And I can't change the format because I don't made it - it's from a game.

In Topic: Vertex format problem

02 May 2012 - 11:06 AM

What is this

swizzle - I mean can you give me an example with a function call?



Best regards!


Thanks!


PARTNERS