New problem.. This is getting bad =/

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

New problem.. This is getting bad =/

Post by Yotunii »

So, I've kinda fixed my transparent texture problem by adding the image to the gui env instead of drawing it myself. My new problem, is that the image gets scaled (it is not a power of 2), but there must be a workaround on this.
I do not accept having to rescale images or manually add padding to my images. I have tried fixing this by changing some code in COpenGLTexture:

Before:

Code: Select all

glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, ImageSize.Width,
		ImageSize.Height, 0, format, type, ImageData);
After:

Code: Select all

	int wpot = NearestPowerOfTwo(ImageSize.Width);
	int hpot = NearestPowerOfTwo(ImageSize.Height);
	glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, wpot, hpot, 0, format, type, NULL);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ImageSize.Width, ImageSize.Height, format, type, ImageData);
NearestPowerOfTwo is a function I have defined that rounds up to the next power of two. Now, this code should add padding, so that the texture does not have to be scaled. This is, although, not working.

So, any ideas? I need the fastest response I can get on this one.

Thanks.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Any deadlines to meet? :lol:
I think your code will define a texture which has the texture padded, but it will draw the complete texture, not just the subpart you would like to have. So you have to adjust texture coordinates as well.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

Oh, but my pad is transparent. It doesn't matter much to me that it draws something transparent =)..
My problem is, it seems, that it is scaling the texture down, then up when drawing, cause the texture is very grainy.

And no, I don't really have a deadline, I just don't like waiting :D
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, checked the source where you applied the changes. The texture/image is already software scaled at at that point, so it won't change anything (it's already a power of two).
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

I see.. any idea how I would go on about changing that? Cause I kinda need it.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Add the texture manually with addTexture specifying the 2^n dimensions you calculated, then copy your image into the texture after locking the texture. Or refactor the texture setup to support non-pot textures :wink:
Oh, another one: Change the scaling function in the texture setup to add padding instead of scaling the image.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

I like that last idea, if I could just find the scaling function ;)

Edit: Never mind, I found it in in getImageData.. I can't see how to rewrite it tho :/
Last edited by Yotunii on Mon Aug 14, 2006 3:00 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Search for "scale texture" in CopneGLTexture.cpp. It's in getImageData.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

I'm trying to simply make it not change the image, then doing the little OpenGL trick later. I'll see how it works out and post here again :D
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

I give up.. I had to mod half the engine, and now I have to cast the driver to COpenGLDevice, which is a type only existant inside Irrlicht, to call the virtual function I have defined. This is endless.

I am afraid you have to realize that such a simple problem, can be so impossible with your engine. You should very hardly consider this, it is either a major design flaw on your part, or on my part.

Hybrid: Thanks for trying to help me on this, and I wasn't trying to be really rude in this post. I'm just stating that it might be a big benefit to change the way this is designed, cause I bet you can see the problem :)
terence
Posts: 12
Joined: Sat Apr 01, 2006 2:22 pm
Contact:

Post by terence »

I don't want to confuse anybody..but anyways..

Doing a little research on my part..looking at how other engine handle it..

Believe this is handle by 'chunking' textures..basically spliting textures multiple power of 2 texture chains....

For example if you have a texture of 800x600..could chunk it into 4x3..256x256 texture chunks(12 textures)..

I was just checking it out in the torque engine which doesn't help anybody..but I think that is right way to handle it..

You would also have to re-write the draw function and others..to ensure it supported chunked bitmaps.

This is also the correct way to handle it because of how your cards VRAM is organized and how it handles 2D texture surfaces if I am not mistaken.
Yotunii
Posts: 16
Joined: Sun Aug 13, 2006 9:44 am

Post by Yotunii »

My engine just does at shown in the first post, it works really great.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Isn't there an OpenGL extension to allow non power of 2 textures?
Image
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Image
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

And and here's some easier reading information on it - http://www.gamedev.net/community/forums ... _id=310559

So basically, if this ARB is available, you don't have to force textures to power of 2.

The engine could add a TEXTURE_CREATION_FLAG - ETCF_FORCE_POWER_OF_TWO.
If the flag is enabled, it makes the texture power of 2, even if the ARB is supported.
If the flag is disabled, or false and the ARB is supported, it leaves the texture alone.
And if the flag is disabled, or false, and the ARB is NOT supported, then it forces the texture to power of 2.
Image
Post Reply