Archived

This topic is now archived and is closed to further replies.

u0_80

custom file format d3d

Recommended Posts

u0_80    122
i''m trying to come up with a simple file format i could load vertices from in d3d 8, and i''m having some trouble reading from the text file and putting the data into my FVF, and then finally putting it into the vertex buffer. right now the file format is very simple: 1.0 1.0 1.0 0.0 1.0 etc...x,y,z,tu,tv i''m trying to load the data with this code: ifstream somefile(theFile); char aString[3]; for (int i = 0; i < 3; i++) { somefile >> aString; vertices.x = atof(aString); somefile >> aString; vertices[i].y = atof(aString); somefile >> aString; vertices[i].z = atof(aString); somefile >> aString; vertices[i].tu = atof(aString); somefile >> aString; vertices[i].tv = atof(aString); } somefile.close(); if( FAILED( d3dDevice->CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_VERTEX, D3DPOOL_DEFAULT, &d3dVB ) ) ) return E_FAIL; VOID* theVertices; if( FAILED( d3dVB->Lock( 0, 0, (BYTE**)&theVertices, 0 ) ) ) return E_FAIL; memcpy( theVertices, vertices, sizeof(vertices)); d3dVB->Unlock(); I get no errors, but when I try to render the geometry from the file, nothing shows up...can anyone help? thanks!

Share this post


Link to post
Share on other sites
nathanvos    122
In:

if( FAILED( d3dDevice->CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_VERTEX, D3DPOOL_DEFAULT, &d3dVB ) ) )
return E_FAIL;

You create a vertexbuffer where each vertex has a position (x,y,z) a normal(x,y,z) an a texture coord (x,y).
your ''vertices'' must also have a position, normal and texture coord. (but i think you already had that )

then:

for (int i = 0; i < 3; i++)
{
somefile >> aString;
vertices.x = atof(aString); << should be: vertices.x = atof(aString);
somefile >> aString;
vertices[i].y = atof(aString);
somefile >> aString;
vertices[i].z = atof(aString);
somefile >> aString;
vertices[i].tu = atof(aString);
somefile >> aString;
vertices[i].tv = atof(aString);
}
And:
if you can''t see anything check the following things:
- Disable lighting
- Ambient 0xFFFFFFFF
- Set background color to anything but black or white
- Set cullmode in your renderstate to none
- Make sure your matrices are setup correctly

Hope this helps!


Nathan Vos
http://www.triple-interactive.nl/nathan

Share this post


Link to post
Share on other sites
u0_80    122
the code must have gotten chopped when i posted it...i did have vertices.x...but thanks for the reply! can anyone else help? this is really beating me up...

Share this post


Link to post
Share on other sites
JonnyBoy    122
vertices.x not vertices.x

Also char aString[3] is too short, set it to at least 40 or something. Even with your 3 digit coords this will spill over due to the end string character.

Have you used the debugger to see what vertices [0]to[3] contain when the program counter has reached the end of the for-loop. If they do not contain the correct data it''s a problem with parsing/reading the file, if they do contain the correct data, then the problem is later, like the renderer for example.

Share this post


Link to post
Share on other sites
thedo    124
might help you if you look at how to post code on the forums
here:

http://www.gamedev.net/community/forums/faq.asp

Neil


WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post


Link to post
Share on other sites