Load a 3DS file
I coded a program which loads the data of 3DS files. But I can''t get it working.
Can you help me to debug the code? Please.
Here''s the code:
#include
#include
///////////////////////////////////////////////////////////////////
//Mesh
char objectname [256];
WORD nvertices;
WORD nfaces;
float listvertices;
float listfaces;
float listuvcoord;
//Material
char materialname [256];
double ambient;
double diffuse;
double specular;
//Mapping
char texturename [256];
float uscale; float vscale;
double listuvscale [2] = {uscale, vscale};
float uoffset; float voffset;
double listuvoffset [2] = {uoffset, voffset};
float rotationangle;
///////////////////////////////////////////////////////////////////
FILE *bin3ds;
///////////////////////////////////////////////////////////////////
unsigned char ReadChar ()
{
return (fgetc (bin3ds));
}
unsigned int ReadInt ()
{
unsigned int temp = ReadChar ();
return (temp | (ReadChar () << 8));
}
///////////////////////////////////////////////////////////////////
int read_material (void)
{
bin3ds = fopen ("file", "r");
WORD id;
int done = 0;
while (done != 1)
{
if (feof (bin3ds))
{
done = 1;
break;
}
id = ReadInt ();
switch (id)
{
case 0xA000: //Material Name
{
int i = 0;
char ch;
while ((ch = fgetc (bin3ds)) != 0)
{
materialname = ch;
i++;
}
materialname = ''\0'';
}
break;
case 0xA010: //Ambient Color
{
short red;
short green;
short blue;
double redambient;
double greenambient;
double blueambient;
fread (&red, sizeof (byte), 1, bin3ds);
fread (&green, sizeof (byte), 1, bin3ds);
fread (&blue, sizeof (byte), 1, bin3ds);
redambient = (1/255)*red;
greenambient = (1/255)*green;
blueambient = (1/255)*blue;
ambient = (redambient, greenambient, blueambient);
}
break;
case 0xA020: //Diffuse Color
{
short red;
short green;
short blue;
double reddiffuse;
double greendiffuse;
double bluediffuse;
fread (&red, sizeof (byte), 1, bin3ds);
fread (&green, sizeof (byte), 1, bin3ds);
fread (&blue, sizeof (byte), 1, bin3ds);
diffuse = (reddiffuse, greendiffuse, bluediffuse);
}
break;
case 0xA030: //Specular Color
{
short red;
short green;
short blue;
double redspecular;
double greenspecular;
double bluespecular;
fread (&red, sizeof (byte), 1, bin3ds);
fread (&green, sizeof (byte), 1, bin3ds);
fread (&blue, sizeof (byte), 1, bin3ds);
specular = (redspecular, greenspecular, bluespecular);
}
break;
}
}
fclose (bin3ds);
return 0;
}
int read_mapping (void)
{
bin3ds = fopen ("file", "r");
WORD id;
int done = 0;
while (done != 1)
{
if (feof (bin3ds))
{
done = 1;
break;
}
id = ReadInt ();
switch (id)
{
case 0xA300: //Mapping Filename
{
int i = 0;
char ch;
while ((ch = fgetc (bin3ds)) != 0)
{
texturename = ch;
i++;
}
texturename = ''\0'';
}
break;
case 0xA354: //V Scale
{
fread (&vscale, sizeof (float), 1, bin3ds);
}
case 0xA356: //U Scale
{
fread (&uscale, sizeof (float), 1, bin3ds);
}
case 0xA358: //U Offset
{
fread (&uoffset, sizeof (float), 1, bin3ds);
}
case 0xA35A: //V Offset
{
fread (&voffset, sizeof (float), 1, bin3ds);
}
case 0xA35C: //Rotation Angle
{
fread (&rotationangle, sizeof (float), 1, bin3ds);
}
}
}
fclose (bin3ds);
return 0;
}
int read_mesh (void)
{
bin3ds = fopen ("file", "r");
WORD id;
int done = 0;
while (done != 1)
{
if (feof (bin3ds))
{
done = 1;
break;
}
id = ReadInt ();
switch (id)
{
case 0x4000: //Object Name
{
int i = 0;
char ch;
while ((ch = fgetc (bin3ds)) != 0)
{
objectname = ch;
i++;
}
objectname = ''\0'';
}
case 0x4110: //Vertices List
{
fread (&nvertices, sizeof (WORD), 1, bin3ds);
fread (&listvertices, sizeof (float), nvertices, bin3ds);
}
case 0x4140: //U And V Coordinates
{
fread (&listuvcoord, sizeof (float), (nvertices*2), bin3ds);
}
}
}
fclose (bin3ds);
return 0;
}
/////////////////////////////////////////////////////////////////// </i>
Makes no sense to post such a code. learn how to use your debugger!
Just set a breakpoint at the beginning of your prog and step through. Post questions related to debugging or the concrete problem you encountered.
Just set a breakpoint at the beginning of your prog and step through. Post questions related to debugging or the concrete problem you encountered.
- thomas
There''s no error when I compile the program. But when I launch it, it crashes and says:
"The instruction at "0x004019ac" referenced memory at "0x83126fcc". The memory could not be "read".
"The instruction at "0x004019ac" referenced memory at "0x83126fcc". The memory could not be "read".
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement