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
|
#include "stdafx.h"
#include "vertHandler.h"
// ===========================================================================================================
// =================== Functions =============================================================================
// ===========================================================================================================
// Write vertex list to memory
void VERTHANDLER::writeBuffer(void)
{
// Create three vertices using the CUSTOMVERTEX struct built earlier
// Makes a triangle fyi
CUSTOMVERT vertices[] =
{
{ 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
};
// Create the vertex and store the pointer into v_buffer, which is created globally
d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERT), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);
VOID* pVoid; // The void pointer
// At this point, lock the memory so it doesn't move around and insert
// list of vertices there, then unlock when done
v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer
memcpy(pVoid, vertices, sizeof(vertices)); // copy the vertices to the locked buffer
v_buffer->Unlock(); // unlock the vertex buffer
}
void VERTHANDLER::cleanBuffer(void)
{
v_buffer->Release();
}
|