Author Topic: something I've been working on finaly in a semi presentable state  (Read 12436 times)

0 Members and 1 Guest are viewing this topic.

Offline EdrickV

  • Valued
  • 29
    • http://members.aol.com/HunterComputers
something I've been working on finaly in a semi presentable state
2 Suggestions.
1. Make the mass edit box bigger so it can handle larger numbers. If you load a model with really high, or really long, mass you get that odd scientific notation I think. (The e+ kinda stuff.)
2. The panel label thing for the texture tab still says current dock, which you probably already know. :)

It will load models other then the provided one, though of course it doesn't do the maps. (Or at least, it didn't find the maps for the file I loaded, which doesn't surprise me since it wouldn't have a clue where to look for the maps even if it can get them from vp files, and I don't know if it can do that yet.)
Ground - "Let me help you out, you're clear to taxi any way you can, to any runway you see."

Mesh Gallery/Downloads:
http://members.aol.com/ArisKalzar/Gallery.html
Turreting 101:
http://members.aol.com/EdrickV/FS2/Turreting.html

http://members.aol.com/HunterComputers

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
it loads BMPs, as I have yet to get a PCX loader
I have just run into a bit of an odd bug, for some odd reason the rotation matrix code just died... I hadn't done anything to it...
illigal instruction when I use D3DXMatrixRotationYawPitchRoll, hmm, well it only shows up when I debug... looks like it's calling, D3DXQuaternionRotationYawPitchRoll insted
« Last Edit: January 17, 2003, 12:08:27 am by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Fry_Day

  • 28
something I've been working on finaly in a semi presentable state
PCX loading is simple with only 8-bit PCXs in mind.

The PXC file format starts with a 128-byte header, which looks like so:
Code: [Select]

typedef struct PCXHEADER {
unsigned char Manufacturer,Version,Encoding,BPP;
unsigned short XMin, YMin, XMax, YMax, HDpi, VDpi;
unsigned char ColorMap[48], Reserved, NPlanes;
unsigned short BytesPerLine, PalInfo, HScrSize, VScrSize;
char fill[54];
} PCXHEADER



to quote myself about the file format:
Quote
The size of the picture *must* be determined by X/Ymax - X/YMin, since not all PCX savers support HDpi and VDpi, and although I haven't seen a single PCX that didn't have XMin and YMin set to 0, better safe than sorry (Another tiny afterthought: don't forget to add 1 to XMax and YMax (a picture from 0 to 127 is 128 pixels wide)). I also believe that Version should be set to 5, since that's the version used by both 256 color and 24bpp PCXs.
One nasty PCX trap is that BytesPerLine is always even, even if the width of the picture is odd (It seems pretty stupid to keep word alignment in a file, even if it makes sense in memory), but that shouldn't be a problem since texture sizes are powers of two.


PCX files have a simple RLE compression scheme. when you read a byte, if its upper two bits are set to 1 (can be checked by if (byte&0xc0)), then the 6 lower bits (byte&0x3F) are the repeat count of the next byte, which is always a color value. If the byte is less than 0xC0, it's a plain color value.

A loop to convert a compressed PCX data to a char * would look like so:
Code: [Select]

int counter, i; //to see how far we are in the file, and assuming no C++ style loop variable declarations
char byte1, byte2;



do {
 byte1 = fgetc(fileptr);
 if (byte1&0xc0)
 {
  byte2 = fgetc(fileptr);
  counter += byte1 & 0x3f;
  for(i = 0; i < byte1 & 0x3f; i++)
   *dest_buffer++ = byte2;
 }
 else {
  *dest_buffer++ = byte1;
  counter++;
 }
} while (counter


Note: This code has some faults, starting with it's assuming that the width of the PCX is even (but that won't be a problem unless we go DirectX 9 or OpenGL 2.0), and continuing to not handling 24-bit PCXs, includign hard-coding the stopping point to before the palette (which doesn't exist in 24-bit PCXs), but it should be enough for you to get the basics of unpacking PCXs

 

Offline DTP

  • ImPortant Coder
  • 28
    • http://www.c4-group.dk
something I've been working on finaly in a semi presentable state
Well, thanks for the explanation, even when it was not aimed for me.

I even understood it all, so thats how RLE works.

in short:
how many bytes next have the same value.
VBB member; reg aug 1999; total posts 600.
War is a lion, on whos back you fall, never to get up.
Think big. Invade Space.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
well that'll sove half problem,
don't supose you'd know how to write that to D3DTexture8 (I think that's the name) :)
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Fry_Day

  • 28
something I've been working on finaly in a semi presentable state
I think you can lock the texture surface (like doing with the back-buffer), and access it like a simple array (As far as I recall, there's a data type D3D_LOCKED_RECT, or something like that. Look at the D3D examples. I'm sure there was something using that in there)
« Last Edit: January 24, 2003, 01:05:34 pm by 791 »

 
something I've been working on finaly in a semi presentable state
is there any chance of someone rewriting this for opengl? it's about time we saw some multiplatform editing tools... LInux/OSX ports of freespace 2 aren't really worth it yet because we have NO editing tools. get us some turret/hardpoint editing tools etc then we can help...
wrong answer you see hiding in that asteroid belt are 6 dralthi fighters, a Kilrathi gangbang. -Devereaux

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
well part of the whole point was for me to learn DX and MFC so if someone else wants to take a crack at it fine but I will not, and I am programing this in DX8.1 directly so it would _not_ be easy to change over to another API.

on a brighter note I am makeing considerable progres
don't beleve me click here
that includes source if anyone wants to see how I'm doing stuff, the code is 90% pure mine, a lot of the DX specific code is from NeXe and I had a bit of MFC code taken from someone else for getting my tab selector working

I havn't even touched the PCX loading beond my inital atempt, I think I've gotten the header loading working but nothing else, and untill I figure out how I am going to get it into the proper texture format I probly won't.

it uses vertex buffers and has many diferen't examples for going through the BSP structure
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
OK getting back to PCX loading
how would I figure out the size of the image data, I want to have the header the image and the pallet to all have there own seperate buffers that I can just go

fread(&pcx_file->head, sizeof(char), 128, pcxfile);
int size = calculate_imagesize(pcx_file);
fread(&pcx_file->image, size, 1, pcxfile);
fread(&pcx_file->pallet, sizeof(char), 768, pcxfile);

then just use the pallet entries to directly fill out a corectly formatted bit map during the decompression, If I had some idea how to fill out the texture format this would make things a lot easier.

and fighter01-01a.pcx has a resolution of 223x437 so it has to take into account  oddly shaped dimentions
« Last Edit: January 26, 2003, 06:09:46 pm by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline DTP

  • ImPortant Coder
  • 28
    • http://www.c4-group.dk
something I've been working on finaly in a semi presentable state
Quote
Originally posted by Bobboau
OK getting back to PCX loading
how would I figure out the size of the image data, I want to have the header the image and the pallet to all have there own seperate buffers that I can just go

fread(&pcx_file->head, sizeof(char), 128, pcxfile);
int size = calculate_imagesize(pcx_file);
fread(&pcx_file->image, size, 1, pcxfile);
fread(&pcx_file->pallet, sizeof(char), 768, pcxfile);

then just use the pallet entries to directly fill out a corectly formatted bit map during the decompression, If I had some idea how to fill out the texture format this would make things a lot easier.

and fighter01-01a.pcx has a resolution of 223x437 so it has to take into account  oddly shaped dimentions


read it once with INT getchar(), it returns one char per read like this, and it returns NULL on EOF.

Code: [Select]


while(getchar())
{
size++;
}


you then got the total size of the file, and all you need to do then is the math, like this

imagesize=size-(768+128), now use fread.

not sure if you have to close and open it again.
VBB member; reg aug 1999; total posts 600.
War is a lion, on whos back you fall, never to get up.
Think big. Invade Space.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
something I've been working on finaly in a semi presentable state
Another way to do it is with _findfirst:
Code: [Select]

int calculate_imagesize(LPSTR pcx_filename)
{
_finddata_t FindStruct;

_findclose(_findfirst(pcx_filename, &FindStruct));

return (FindStruct.size - (768 + 128));
}
« Last Edit: January 27, 2003, 03:57:30 am by 374 »
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
OK this is what I'm working with right now, it isn't working maybe someone can see were I'm going wrong
Code: [Select]
struct pcx_head{
char Manufacturer;
char Version;
char Encoding;
char BitsPerPixel;
short Xmin;
short Ymin;
short Xmax;
short Ymax;
short Hdpi;
short Vdpi;
char ColorMap[16][3];
char Reserved;
char Nplanes;
short BytesPerLine;
char filler[60];
};

struct pcx{
pcx_head head;
BYTE *image;
char palette[768];
};

void load_pcx( char *file_name);

void load_pcx( char *file_n){

int x, y, i, size = 0, imgsize = 0;

CString pcx_string;
pcx p_file;
pcx *pcx_file = &p_file;
char file_name[128];
// char head_buf[128];
BYTE *image;
char c;
strcpy(file_name, file_n);
strcat(file_name, ".pcx");

FILE *pcxfile=fopen(file_name, "rb");

if(!pcxfile){
pcx_string.Format("could not load the file %s", file_name);
MessageBox(NULL, pcx_string, "!", MB_OK);
return;
}

while(!feof(pcxfile))
{
fread(&c, sizeof(char), 1, pcxfile);
size++;
if(size > 10000000)return;
}
size -= (768+128);

fclose(pcxfile);

pcxfile=fopen(file_name, "rb");

if(!pcxfile){
pcx_string.Format("could not load the file %s", file_name);
MessageBox(NULL, pcx_string, "!", MB_OK);
return;
}
pcx_file->image = new BYTE[size];
// pcx_file->image = p;

fread(&pcx_file->head, sizeof(char), 128, pcxfile);
fread(pcx_file->image, sizeof(char), size, pcxfile);
fread(&pcx_file->palette, sizeof(char), 768, pcxfile);

x = pcx_file->head.Xmax - pcx_file->head.Xmin + 1;
y = pcx_file->head.Ymax - pcx_file->head.Ymin + 1;
imgsize = x*y;
image = new BYTE[imgsize];

BYTE rep;
int offset = 0;

int j = 0;

//the decompression loop
while(offset <= size){
if(pcx_file->image[offset] & 0xC0){//if the first two bits are set, the next six show how many times to repete the next byte
rep = pcx_file->image[offset++] & 0x3f;
for(i = 0; i< rep; i++){
image[j++] = pcx_file->image[offset++];
if(offset <= size)break;
}
}else{
image[j++] = pcx_file->image[offset++];
if(offset <= size)break;
}
}

// image = new char[(pcx_file->head.BytesPerLine * (pcx_file->head.Ymax - pcx_file->head.Ymin))];
// fread(&image, pcx_file->head.BytesPerLine * (pcx_file->head.Ymax - pcx_file->head.Ymin), 1, pcxfile);
// fread(&pcx_file->palette, sizeof(pcx_file->palette), 1, pcxfile);

// for(i=0;i // image[0];
delete(pcx_file->image);
int X = 0, Y = 1, I=(Y*x)+X ;
pcx_string.Format("pixel %d,%d, pixel no. %d in %s is %d", X, Y, I, file_name, image[I]);
MessageBox(NULL, pcx_string, "!", MB_OK);
// }

delete(image);

fclose(pcxfile);
}
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline DTP

  • ImPortant Coder
  • 28
    • http://www.c4-group.dk
something I've been working on finaly in a semi presentable state
what type is BYTE,

an extern *char from somewhere else
or a mistake.
VBB member; reg aug 1999; total posts 600.
War is a lion, on whos back you fall, never to get up.
Think big. Invade Space.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
it's an unsigned char
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline DTP

  • ImPortant Coder
  • 28
    • http://www.c4-group.dk
something I've been working on finaly in a semi presentable state
as far as i can tell, this
Code: [Select]

while(!feof(pcxfile))
{
fread(&c, sizeof(char), 1, pcxfile);
size++;
if(size > 10000000)return;
}


includes the EOF, because it simply has not gotten to that when the char just before EOF is read. EOF gets read. and then feof(pcxfile) gets set

so your size would be incorrect by +1.

you could do this instead
Code: [Select]

while(fread(&c,sizeof(char),1, pcxfile))
          {
              if(size >MAX_FILE_SIZE)
              return;
           }


it will discontinue the while loop becuase EOF is NULL, and while(NULL) {dostuff} will not dostuff.

btw, i spend a great deal of time studing this for my TBL checker,
sinze i have to read in some 1 mb files.

i do however acces files like this
Code: [Select]

#include
#include //header for std::ifstream functions
using namespace std;//so i dont have to type std:: all the time
#include //header for usefull c++ type strings
using namespace std;
#include //header for simple output to screen, always much better than printf from ordinary C

somefunction()
{
ifstream myfile(*char)//opens the file
myfile.(AWHOLELOTOFUSEFULL-SUBFUNCTIONS)//mscv6.0 should auto show you the functions.
myfile.getline(aconstchar,READ_MAX,'\n')//terminate read on
encounter newline, and certainly if read_max has been reached
//and it dont care if it is a binary or textfile it is reading.



//also, strings are better than chars, since you dont have to deal with all the rules that ordinary C_strings has.

string mystring ="some words"
string mysecondstring =mystring.substr(6,5);
printf(mysecondstring);// would output "word"

//you can even do this
char[10] junk='1234567890';
mythirdstring = junk;

/*c++ strings auto expands, or contracts according to what they are being setting equal to. something ordinary c-style strings can´t

//no more the, cant convert char[n1] to char[n2] and so on.




why all this, well its always good to know the basics, but coding is moving towards C++, becuase it is more accesible, and decreases production time, you might as well learn c++, rather than punching c.-style stuff that is becomming obselete.
« Last Edit: January 27, 2003, 10:29:33 pm by 508 »
VBB member; reg aug 1999; total posts 600.
War is a lion, on whos back you fall, never to get up.
Think big. Invade Space.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
well for most string intensive things I use CStrings, most of the char things you see there are actualy just buffers for things I didn't care or didn't know what they were.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
in any case I must have a fundemental lack of understanding about the file strcusture and/or what I am suposed to do with it, I think it reads the first line corectly...no, no it is't
« Last Edit: January 28, 2003, 01:07:22 am by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
ok this seems to be working better
Code: [Select]
//the decompression loop
while((offset <= size) && (j <= imgsize)){
if(pcx_file->image[offset] > 192){//if the first two bits are set, the next six show how many times to repete the next byte
rep = (pcx_file->image[offset++] - 192 );
for(i = 0; i< rep; i++){
image[j++] = pcx_file->image[offset];
if((offset >= size) || (j > imgsize))break;
}
offset++;
}else{
image[j++] = pcx_file->image[offset++];
if((offset >= size) || (j > imgsize))break;
}
}
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
yes I think I've got it to decompres into a byte map for even sized textures, wich I can use to generate the textures eventualy,
what do I have to do to get it to read odd sized files, should it ignor the last one or something, what is it there for?
Code: [Select]
//the decompression loop
while((offset <= size) && (j <= imgsize)){
if(x != pcx_file->head.BytesPerLine){
if(j%x == 1)//if we've hit the end of the line
offset++;//skip one
}

if(pcx_file->image[offset] > 192){//if the first two bits are set, the next six show how many times to repete the next byte
rep = (pcx_file->image[offset++] - 192 );
for(i = 0; i< rep; i++){
image[j++] = pcx_file->image[offset];
if((offset >= size) || (j > imgsize))break;
}
offset++;
}else{
image[j++] = pcx_file->image[offset++];
if((offset >= size) || (j > imgsize))break;
}
}


it seems to work
« Last Edit: January 28, 2003, 03:01:06 am by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
something I've been working on finaly in a semi presentable state
ok now I need some way to load it to a IDirect3DTexture8, anyone want to give me a clue :D

   
Code: [Select]
if (D3D_OK != D3DXCreateTexture(g_pDevice, x, y, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &d3dtexture))MessageBox(NULL, "texture creation failed", "!", MB_OK);

D3DLOCKED_RECT img_rec;

D3DSURFACE_DESC surf_desc;

d3dtexture->GetLevelDesc(0,&surf_desc);

if(surf_desc.Format == D3DFMT_A8R8G8B8){
//d3dtexture->UnlockRect(0);
if (D3D_OK != d3dtexture->LockRect(0, &img_rec, NULL, D3DLOCK_NOSYSLOCK ))MessageBox(NULL, "lock failed", "!", MB_OK);

//DWORD color;
struct temp_color{
BYTE b;
BYTE g;
BYTE r;
BYTE a;
} *pix;

temp_color temp;
temp.b = 128;
temp.g = 128;
temp.r = 128;
temp.a = 128;

// DWORD *pix;
// DWORD temp = 0;
pix = (temp_color *)img_rec.pBits;
int pitch = img_rec.Pitch;
// pix[0] = 0;
int place = 0;
for(i = 0; i for(j = 0; j place = (i*pitch)+j;
pix[place] = temp;
}
}

d3dtexture->UnlockRect(0);

}


ok, it doesn't seem to be bug enough
« Last Edit: January 28, 2003, 12:57:33 pm by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together