So I have an amusing story to share. Last night, I was working on my Direct X Editor, trying to get the initial polygons on the screen to test my viewport/learn a little about vertex buffers in direct x. Needless to say I learned something about Vertex Buffers.
So the plan was to create a grid of verticies for the purpose of creating a reference grid on the xz plane about the y axis. Simple enough right? I thought so. Anyways, I get my verticies set up and I create my Vertex Buffer (so I thought) and set up the function to do the drawing. Nothing appears...
Well shoot! What did I do wrong? Am I drawing the Polys in the wrong direction (Counter clock wise instead of clock wise). So I try a simple test, I rotate the grid using an x transformation of 180 degrees. Still nothing.
Hmmm... I think to myself, that is strange. Time for some debugging. So I step through my vertex declaration and convince myself that my location of verticies are correct. I check my viewport declaration, its correct. And now I am frustrated.
I get out some sample code, add it to the project, and give it a try. Sure enough, the sample code appears on the screen as two annoying little spinning squares right where my grid is suppose to be. So there is obviously something wrong with my code. I compare and compare to no avail. I try to insert my vertex buffer into the sample drawing code, no luck. I even try to redefine my vertex points exactly as the sample code, no luck. Now I am really confused.
Finally! I figured it out, apparently when you create the vertex buffer. Normally you have to create a void pointer object for use in referencing the memory that the vertex buffer will use to hold our vertex information. Then we use this pointer to lock the vertex buffer, copy the memory and unlock the vertex buffer and all is good.
Well... let me tell you, sometimes life has a way of playing small games with your head.
Frustratingly enough, the memcpy function used in this procedure doesn't care much what type of pointer you place in its parameters. We want this definition: memcpy(void*, Verts, sizeof(Verts)); where Verts is the array of vertex structs that we want to put in the buffer. Yet it turns out that I was using this: memcpy(void*, VertexBufferObject, sizeof(Verts));
What this means, I really do not have a clue, but once I fixed the memcpy, life was good again, except for the mess I made in my editor code trying to debug... Oh well.
No comments:
Post a Comment