Page 2 of 2

Posted: Fri Dec 10, 2004 5:10 pm
by Falco Girgis
JS Lemming wrote:Ooooookaaayyy... Right.... You don't know whay I'm talking about do you?
Me wrote:Okay, JSL. You've so totally lost me.
Obviously, we've already established that.

I never will understand what you're talking about. I've never made a level editor and you keep refering to:

123
456
789

As that. That's not a very good explanation. What in the hell are those numbers? Coordinates? Tile identification numbers?

Call me stupid, but I think I'm just ignorant of what you're trying to say.

Posted: Fri Dec 10, 2004 6:37 pm
by Tvspelsfreak
JS Lemming wrote:
GyroVorbis wrote:Okay, JSL. You've so totally lost me.

Coordinate 1,1 on a 20x20 coordinate plane is 1,1 on a 23421423423423x4324234234324234324234 coordinate plane.
Ooooookaaayyy... Right.... You don't know whay I'm talking about do you?

When the below is spliced and set into memory:

Code: Select all

123 
456 
789
it looks like this in memory:

Code: Select all

123456789
When the mutated (resized) image is spliced in (below)

Code: Select all

123000 
456000 
789000
It looks like this in memory

Code: Select all

123000456000789000
When a level is loaded, it asociates the values in the file with the index of the spliced array. So the level data in a way becomes corrupt.
Yeah, but the thing is.
We need to add to the height (not width as shown in your example).
It'll look the same in memory exept larger.

Posted: Fri Dec 10, 2004 8:53 pm
by JS Lemming
Yeah, but the thing is.
We need to add to the height (not width as shown in your example).
It'll look the same in memory exept larger.
Yeah, only if the original image happened to have a width that was power of 2, which is not always the case for sprites too. And GV, those numbers were just representations of indivual tiles. thats all. It was either that or post a pic. (too lazy)

Posted: Fri Dec 10, 2004 9:35 pm
by MarauderIIC
Can't you load your tile data into a 2d array? Then you have actual coordinates.

Posted: Sat Dec 11, 2004 8:36 pm
by JS Lemming
Since no one seems to have a solution, I'll go ahead and bust out my idea. After the PC version is completed, me or somebody else makes a program that loads a spite sheet or tileset (same thing). It then asks for width, height, and number of tiles in the image. It then finds the most efficient ratio of perfect square dimmensions and tiles the individual pieces left to right, top to bottom. Thus making it difficult to edit, hence it is done after developement, and then usable by the DC. Now we can move on with our lives. 8)

Posted: Sat Dec 11, 2004 9:19 pm
by MarauderIIC
So just individual images for now?

Posted: Sun Dec 12, 2004 9:16 am
by Falco Girgis
Remember, that whole Sprite vs. Image battle a while back?
MarauderIIC wrote:So just individual images for now?
JSL, you've been pwnt!

Posted: Sun Dec 12, 2004 10:40 am
by JS Lemming
GyroVorbis wrote:Remember, that whole Sprite vs. Image battle a while back?
MarauderIIC wrote:So just individual images for now?
JSL, you've been pwnt!
I don't get it? What are you talking about Mar? You too GyroV, how was I pwnt? Its not like my idea said anything about using seperate images...

Posted: Sun Dec 12, 2004 2:19 pm
by MarauderIIC
I meant, do we want to use sep. images instead of spritesheets for now during development, to avoid the power-of-2-messing-up-sheet problem? Then we can pad individual images w/ blank data to achieve power of two.
Actually, my OpenGL + non-standard-LoadBMP bit here can load non-power-of-twos and then it scales them to power of two for usage. IIRC, it scales the actual image part to fit when I draw on a shape. Mipmapping also works but is slower. (Been a while since I looked at this code.) You'll note the memory handling stuff is in C. The tutorial does it that way but I'm also sure I could do something like have a class and then pad the class w/ an array... This uses actual numbers though.

Code: Select all

bool Texture::loadTexture(string pfilename, bool mipmap) {

	AUX_RGBImageRec* texImage[1];
	BYTE* scaleTex = NULL;

	memset(texImage, 0, sizeof(void*)*1);

	float powerLog;
	int powerOfTwo;
	//int powerOfTwo2;
	GLenum errored = 0;

	int newWidth;
	int newHeight;
	bool scaleImage = false;

	if (!(texImage[0] = LoadBMP(pfilename))) {
		debug(("loadTexture() : LoadBMP returned null. Could not open file '" + pfilename + "' for read."));
		return false;
	}

 	glGenTextures(1, &theTexture);

	glBindTexture(GL_TEXTURE_2D, theTexture);
 
	width = texImage[0]->sizeX;
	height = texImage[0]->sizeY;
	newWidth = texImage[0]->sizeX;
	newHeight = texImage[0]->sizeY;

	if (!mipmap) {
		//See if the image is a power of two. If it's not, mipmap it.
		powerLog = log(texImage[0]->sizeX)/log(2);
		powerOfTwo = roundFloat(powerLog);
		if (powerOfTwo != powerLog) {
			if (powerOfTwo < powerLog)
				powerOfTwo++;
			newWidth = (unsigned int)pow(2, powerOfTwo);
			scaleImage = true;
		}

		powerLog = log(texImage[0]->sizeY)/log(2);
		powerOfTwo = roundFloat(powerLog);
		if (powerOfTwo != powerLog) {
			if (powerOfTwo < powerLog)
				powerOfTwo++;
			newHeight = (unsigned int)pow(2, powerOfTwo);
			scaleImage = true;
		}
	}

	if (mipmap) {

		errored = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texImage[0]->sizeX,
			texImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, texImage[0]->data);

		if (errored) {
			string str = (char*)gluErrorString(errored);
			debug("Mipmap error: " + str);
			MessageBox(NULL, "Mipmap error.", "a", MB_OK);
		}

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	} else if (scaleImage) {

		scaleTex = (BYTE*)malloc(newWidth * newHeight * 3 * sizeof(BYTE));

		if (!scaleTex) {
			MessageBox(NULL, "Error allocating texture resize.", "err", MB_OK);
			return false;
		}

		errored = gluScaleImage(GL_RGB, texImage[0]->sizeX, texImage[0]->sizeY, GL_UNSIGNED_BYTE,
			texImage[0]->data, newWidth, newHeight, GL_UNSIGNED_BYTE, scaleTex);

		if (errored) {
			string str = (char*)gluErrorString(errored);
			debug("Scale error: " + str);
			MessageBox(NULL, "Scale error.", "a", MB_OK);
		}
		//width = newWidth;
		//height = newHeight;
	
		glTexImage2D(GL_TEXTURE_2D, 0, 3, newWidth,
			newHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
			scaleTex);

		debug("Scaled " + pfilename);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		
	} else {
		glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage[0]->sizeX,
			texImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
			texImage[0]->data);

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	}


	if (texImage[0]) {
		if (texImage[0]->data)
			free(texImage[0]->data);
		free(texImage[0]);
	}

	if (scaleTex)
		free(scaleTex);

	return true;

}

Posted: Mon Dec 13, 2004 7:27 am
by JS Lemming
Nah, I think sep images is too much work. Sheets will work great.

Posted: Mon Dec 13, 2004 5:21 pm
by MarauderIIC
Then what's the problem with powers of two?! ARAGHAHh

Posted: Mon Dec 13, 2004 8:16 pm
by JS Lemming
MarauderIIC wrote:Then what's the problem with powers of two?! ARAGHAHh
I thought we already solved that problem.