KGL- PCX from PC.

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
N64VSNES
DCEmu Freak
DCEmu Freak
Posts: 65
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sun Apr 10, 2011 12:05 pm
Has thanked: 0
Been thanked: 0

KGL- PCX from PC.

Post by N64VSNES »

Okay so I've been using some KGL and I've had problems with texturing.

Basically I can load and texture a cube if I load the texture from a romdisk, if I load it form my PC via a coders cable then it just hangs and doesn't load the image. (not slow, actually halting).

No errors or anything.

I tried this with the example in examples/kgl/basic/gl example and it's still not making a difference.

I'm sure the path to the image is correct, I've set the working directory to the correct place etc.

If you're too lazy to look at the examples, here's the code:

Code: Select all

// fn- "/pc/crate.pcx
void loadtxr(const char *fn, GLuint *txr) {
	kos_img_t img;
	pvr_ptr_t txaddr;

	if (pcx_to_img(fn, &img) < 0) { // Get's stuck here
		printf("can't load %s\n", fn);
		return;
	}

	txaddr = pvr_mem_malloc(img.w * img.h * 2);
	pvr_txr_load_kimg(&img, txaddr, PVR_TXRLOAD_INVERT_Y);
	kos_img_free(&img, 0);

	glGenTextures(1, txr);
	glBindTexture(GL_TEXTURE_2D, *txr);
	glKosTex2D(GL_RGB565_TWID, img.w, img.h, txaddr);
}
Any suggestions?

Thanks.
TapamN
DC Developer
DC Developer
Posts: 105
Joined: Sun Oct 04, 2009 11:13 am
Has thanked: 2 times
Been thanked: 90 times

Re: KGL- PCX from PC.

Post by TapamN »

Are you using the right directory? /pc/ goes to the root directory of the host system, not the directory you run dc-tool from.

So if your using a *nix, it goes to /
If your using Cygwin, it goes to C:\cygwin\ (or where ever you installed it.)

You probably want to pass something like "/pc/home/yourusername/dc/kos/examples/kgl/basic/gl/crate.pcx" as the filename. Or you could just copy the texture to your root directory.
N64VSNES
DCEmu Freak
DCEmu Freak
Posts: 65
Joined: Sun Apr 10, 2011 12:05 pm
Has thanked: 0
Been thanked: 0

Re: KGL- PCX from PC.

Post by N64VSNES »

TapamN wrote:Are you using the right directory? /pc/ goes to the root directory of the host system, not the directory you run dc-tool from.

So if your using a *nix, it goes to /
If your using Cygwin, it goes to C:\cygwin\ (or where ever you installed it.)

You probably want to pass something like "/pc/home/yourusername/dc/kos/examples/kgl/basic/gl/crate.pcx" as the filename. Or you could just copy the texture to your root directory.
It's definitely the correct directory. I know it goes to the root, but when you pass -c "whatever" you can set a custom directory (what I'm doing)

I've tried it with PNG/TGA etc and all work apart from PCX. Perhaps a bug in the KOS? I really don't know. Very strange.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Re: KGL- PCX from PC.

Post by BlackAura »

Are you sure it's not just slow?

The PCX loader reads the file one byte at a time, with no buffering. KOS's filesystem is fairly simplistic, and doesn't really do any caching or buffering of it's own. Each byte that's read requires the Dreamcast to send a request to the dcload host, and then wait for a response.

The thing's unusably slow, even over a BBA. It takes something like 1 minute to load a fairly small PCX, and that's over a 100MB/s Ethernet connection. I can't even imagine how slow it would be over a serial cable.

Simple solution:

Code: Select all

// fn- "/pc/crate.pcx
void loadtxr(const char *fn, GLuint *txr) {
   const char *tempFilename = "/ram/temp.pcx";

   kos_img_t img;
   pvr_ptr_t txaddr;

   fs_copy(fn, tempFilename); // Copy to /ram first
   if (pcx_to_img(tempFilename, &img) < 0) { // Get's stuck here
      fs_unlink(tempFilename);
      printf("can't load %s\n", fn);
      return;
   }
   fs_unlink(tempFilename);

   txaddr = pvr_mem_malloc(img.w * img.h * 2);
   pvr_txr_load_kimg(&img, txaddr, PVR_TXRLOAD_INVERT_Y);
   kos_img_free(&img, 0);

   glGenTextures(1, txr);
   glBindTexture(GL_TEXTURE_2D, *txr);
   glKosTex2D(GL_RGB565_TWID, img.w, img.h, txaddr);
}
That copies the file directly to the built-in ramdisk first. That should be much faster than reading the whole file byte by byte.

The TGA or PNG loaders are not similarly affected. They read the file in larger blocks.
Post Reply