🔒 Locked
D3D float loader
Advertisement
Original Post
I''m trying to write a function that loads in floats from a file to store as the x, y, z, tu, and tv parts of my FVF_VERTEX Vertex which is FVF_TEXTURE1 and FVF_XYZ. (not sure of the exact format, can''t remeber). I''m trying to do this without using a binary file, using a .map file which can be opened in notepad which will look like:
1.0000000 1.0000000 0.0000000 0.0000000 0.0000000
...
/ / / / /
Vertex.v.x Vertex.v.y Vertex.v.z Vertex.tu Vertex.tv
so i can change the vertexes of my objects without compiling the code all the time, and can load different maps in. The problem is, i''m not sure how to load the floats in. I''ve been using fprintf to print floats into the map files which looks like:
1.0000000 , but when i try to fscanf the floats in my program crashes. Anyone know what functions i should be using to get this to work correctly. Or anyone know how i can store my file to be compatable with some input funcion you know of?
Thanks.
Drop the ascii format, unless you really need it for hand editing.
Here''s some sample code for loading structs straight into memory using fread, the opposite of which is fwrite (surprisingly!).
Cheers
Matt
Check out my project at:www.btinternet.com/~Matthew.Bennett
Here''s some sample code for loading structs straight into memory using fread, the opposite of which is fwrite (surprisingly!).
unsigned int modelverts;
stream = fopen("build01.mod", "rb");
fread(&modelverts, 2, 1, stream);
fread(&model, sizeof(D3DVERTEX), modelverts, stream);
fclose(stream);
Cheers
Matt
Check out my project at:www.btinternet.com/~Matthew.Bennett
|
you also have to make sure you dont read in more vertices then you allocated space for.......like dont let count exceed MAX_VERTICES
"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions
or if you''re using C (doesn''t matter) you could read the file to a string and then analyze the string like so:
that should work also.
JoeMont001@aol.com
|
that should work also.
JoeMont001@aol.com
use fscanf
// pseudo code will scan rows
FILE *fp = fopen("filename.map")
Vertex *v;
for i = 0 to numRows
v = verticesArray;
fscanf(fp, "%f", &v->x);
fscanf(fp, "%f", &v->y);
fscanf(fp, "%f", &v->z);
fscanf(fp, "%f", &v->u);
fscanf(fp, "%f", &v->v);
next i
MCSE, MCSD, Sun Certified Java Programmer
Pimp Daddy ;)
// pseudo code will scan rows
FILE *fp = fopen("filename.map")
Vertex *v;
for i = 0 to numRows
v = verticesArray;
fscanf(fp, "%f", &v->x);
fscanf(fp, "%f", &v->y);
fscanf(fp, "%f", &v->z);
fscanf(fp, "%f", &v->u);
fscanf(fp, "%f", &v->v);
next i
MCSE, MCSD, Sun Certified Java Programmer
Pimp Daddy ;)
Thanks people. I''ll try these ways and get back to you.
-------------
I am a Juggalo.
-------------
I am a Juggalo.
Sometimes fscanf() can get confused about whitespace, so I always put spaces around the format specifiers, like this:
fscanf(fp, " %f ", &v->x);
lntakitopi@aol.com - http://www.geocities.com/guanajam
fscanf(fp, " %f ", &v->x);
lntakitopi@aol.com - http://www.geocities.com/guanajam
Ahhh..yes, finally I see it! I didn''t even notice the & in the code above. No wonder. Thanks people.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement