D3D9 VC++
I'll try to present this as a spot-the-mistake. I haven't used vectors for a long time so I'm not sure what I'm missing.
What worked:
#include "VertexDefs.h"
static const TEXTDVERTEX verts[] = {
{-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f},
{511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f},
{-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f},
{-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f},
{511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f},
{511.5f, 511.5f, 0.0f, 1.0f, 1.0f, 1.0f} };
void* pVerts;
if(FAILED(m_pVertexBuffer->Lock(0, sizeof(verts), (void**)&pVerts, NULL)))
{
return E_FAIL;
}
memcpy(pVerts, &verts, sizeof(verts));
m_pVertexBuffer->Unlock();
///////////////// My TEXTDVERTEX struct /////////////////////////
struct TEXTDVERTEX
{
float x,y,z,rhw,u,v;
};
This simply renders a quad with a texture that is opened later.
I want to stop using the array and start using a vector. Here's what doesn't work:
#include "VertexDefs.h"
#include <vector>
/////////////// Later, in the same {} scope ... //////////////////////
{
vector <TEXTDVERTEX> verts;
TEXTDVERTEX* temp1 = new TEXTDVERTEX(-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f);
verts.push_back(*temp1);
delete temp1;
TEXTDVERTEX* temp2 = new TEXTDVERTEX(511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f);
verts.push_back(*temp2);
delete temp2;
TEXTDVERTEX* temp3 = new TEXTDVERTEX(-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f);
verts.push_back(*temp3);
delete temp3;
TEXTDVERTEX* temp4 = new TEXTDVERTEX(511.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f);
verts.push_back(*temp4);
delete temp4;
TEXTDVERTEX* temp5 = new TEXTDVERTEX(511.5f, 511.5f, 0.0f, 1.0f, 1.0f, 1.0f);
verts.push_back(*temp5);
delete temp5;
TEXTDVERTEX* temp6 = new TEXTDVERTEX(-0.5f, 511.5f, 0.0f, 1.0f, 0.0f, 1.0f);
verts.push_back(*temp6);
delete temp6;
void* pVerts;
if(FAILED(m_pVertexBuffer->Lock(0, sizeof(verts), (void**)&pVerts, NULL)))
{
return E_FAIL;
}
memcpy(pVerts, &verts, sizeof(verts));
m_pVertexBuffer->Unlock();
}
//////////// I added a quick ctor to the TEXTDVERTEX struct /////////////////
struct TEXTDVERTEX
{
TEXTDVERTEX(float xx, float yy, float zz, float rrhw, float uu, float vv):
x(xx), y(yy), z(zz), rhw(rrhw), u(uu), v(vv){}
float x,y,z,rhw,u,v;
};
Compiles fine, nothing appears. Anything obvious I've missed? Thanks if anyone spots it.