ifstream somefile(theFile);
char aString[3];
for (int i = 0; i < 3; i++) {
somefile >> aString;
vertices.x = atof(aString);
somefile >> aString;
vertices.y = atof(aString);
somefile >> aString;
vertices.z = atof(aString);
somefile >> aString;
vertices.tu = atof(aString);
somefile >> aString;
vertices.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();
</code>
I get no errors, but when I try to render the geometry from the file, nothing shows up…can anyone help?
thanks! </i>
custom file format d3d
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:
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.y = atof(aString);<br> somefile >> aString;<br> vertices.z = atof(aString);<br> somefile >> aString;<br> vertices.tu = atof(aString);<br> somefile >> aString;<br> vertices.tv = atof(aString);<br>}<br>And:<br>if you can''t see anything check the following things:<br>- Disable lighting<br>- Ambient 0xFFFFFFFF<br>- Set background color to anything but black or white<br>- Set cullmode in your renderstate to none<br>- Make sure your matrices are setup correctly<br><br>Hope this helps!<br> </i> <br><br>Nathan Vos<br>http://www.triple-interactive.nl/nathan
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.y = atof(aString);<br> somefile >> aString;<br> vertices.z = atof(aString);<br> somefile >> aString;<br> vertices.tu = atof(aString);<br> somefile >> aString;<br> vertices.tv = atof(aString);<br>}<br>And:<br>if you can''t see anything check the following things:<br>- Disable lighting<br>- Ambient 0xFFFFFFFF<br>- Set background color to anything but black or white<br>- Set cullmode in your renderstate to none<br>- Make sure your matrices are setup correctly<br><br>Hope this helps!<br> </i> <br><br>Nathan Vos<br>http://www.triple-interactive.nl/nathan
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...
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.
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.
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?!?!
here:
http://www.gamedev.net/community/forums/faq.asp
Neil
WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement