MEMCPY - some problems

Started by
0 comments, last by Evil Steve 16 years, 8 months ago
If I have 2 structs for CUSTOM VERTEX...how can i copy both to the vertex buffer struct CUSTOMVERTEX2{FLOAT X,Y,Z;DWORD COLOR;FLOAT U,V;}; struct CUSTOMVERTEX1{FLOAT X, Y, Z; DWORD COLOR;}; memcpy(pVoid, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1)); memcpy(pVoid, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2)); this is not working :| ...what I should do? I'm using VC++, DirectX9
Advertisement
Quote:Original post by johnny_no1_boy
If I have 2 structs for CUSTOM VERTEX...how can i copy both to the vertex buffer

struct CUSTOMVERTEX2{FLOAT X,Y,Z;DWORD COLOR;FLOAT U,V;};
struct CUSTOMVERTEX1{FLOAT X, Y, Z; DWORD COLOR;};

memcpy(pVoid, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1));
memcpy(pVoid, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2));
this is not working :| ...what I should do?

I'm using VC++, DirectX9
You're overwriting the first vertex with the second. You probably want:
BYTE* pVertices = (BYTE*)pVoid;memcpy(pVertices, CUSTOMVERTEX1, sizeof(CUSTOMVERTEX1));pVertices += sizeof(CUSTOMVERTEX1);memcpy(pVertices, CUSTOMVERTEX2, sizeof(CUSTOMVERTEX2));pVertices += sizeof(CUSTOMVERTEX2);

Although, unless you're doing something extremely odd, this won't work as you expect - all the vertices used in draw calls usually have to be the same format, or it won't work. The graphics card won't be able to tell where each vertex starts.
The only exception to this is if you're storing data for different draw calls in one VB, for instance one mesh with texture coordinates, one without, and then using stream offsets to choose which one to use.

This topic is closed to new replies.

Advertisement