[Bug?]draw2DImage renders dirtily

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.
Post Reply
former_
Posts: 2
Joined: Wed Aug 27, 2008 7:21 am

[Bug?]draw2DImage renders dirtily

Post by former_ »

following code renders a dirty image.

Code: Select all

#pragma comment( lib, "irrlicht.lib" )
#include <irrlicht.h>

using namespace irr;
using namespace video;
using namespace core;

int main(int argc, char* argv[])
{
	IrrlichtDevice* device = createDevice( EDT_DIRECT3D9, dimension2di( 150, 350 ) );
	IVideoDriver* driver = device->getVideoDriver();

	ITexture* tex = driver->getTexture( "paperdoll.png" );
	dimension2di texSize = tex->getOriginalSize();

	while( device->run() )
	{
		driver->beginScene( true, true, 0xff6060ff );
		driver->draw2DImage( tex, position2di(0,0), rect<s32>(0,0,texSize.Width,texSize.Height), 0, 0xffffffff, true );
		driver->endScene();
	}

	device->drop();
}
paperdoll.png's size is 150 x 350.
when I use pow2 image ( or copy pixels to pow2 texture ), it renders correctly.
Is it a bug? or specification?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

It's a specification. Some (most?) graphics cards require textures to be pow2 so when you load a non-pow2 texture into Irrlicht it scales it up/down to the nearest pow2 which usually ruins the quality of the image.

So basically just use pow2 images by either rescaling yourself or introducing padding which can be done like you've done it.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It looks OK to me using the SVN trunk and a simple 150 x 350 png. What version of Irrlicht are you using, and what exactly do you mean by "dirty image"?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
former_
Posts: 2
Joined: Wed Aug 27, 2008 7:21 am

Post by former_ »

to JP
Thanks for answering.
But then, I have a question.
when I create non-pow2 texture by addTexture() (in environment which does not support non-pow2 texture ) and render it by draw2DImage(), it seems incorrect. Why?

here's code:

Code: Select all

#pragma comment( lib, "irrlicht.lib" )
#include <irrlicht.h>
#include <memory.h>

using namespace irr;
using namespace video;
using namespace core;

int main(int argc, char* argv[])
{
	IrrlichtDevice* device = createDevice( EDT_DIRECT3D9, dimension2di( 150, 350 ) );
	IVideoDriver* driver = device->getVideoDriver();

	ITexture* tex = driver->addTexture( dimension2di( 150, 350 ), "paperdoll" );
	IImage* img = driver->createImageFromFile( "paperdoll.png" );

	char* texPix = static_cast<char*>(tex->lock());
	char* imgPix = static_cast<char*>(img->lock());

	for( int h = 0; h < 350; ++h )
	{
		memcpy( texPix, imgPix, 150 * 4 );
		texPix += tex->getPitch();
		imgPix += img->getPitch();
	}

	tex->unlock();
	img->unlock();
	img->drop();

	dimension2di texSize = tex->getOriginalSize();

	while( device->run() )
	{
		driver->beginScene( true, true, 0xff6060ff );
		driver->draw2DImage( tex, position2di(0,0), rect<s32>(0,0,texSize.Width,texSize.Height), 0, 0xffffffff, true );
		driver->endScene();
	}

	device->drop();
}
and image:

Image

to rogerborg

I used version 1.4.1.

I uploaded.
this is used image and expected

Image

but

Image

It occurs when videocard does not support non-pow2 texture.
My notebook computer does not supports non-pow2 texture, so It occurs.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Oh, right. By "dirty", I thought you meant badly strided.

If you create a 256 x 512 image, and place your 150 x 350 image in the top left of it, it should appear with 1:1 scaling.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
torleif
Posts: 188
Joined: Mon Jun 30, 2008 4:53 am

Post by torleif »

To make translucency appear leet in irrlicht just use PNG. You might as well abuse the hell out of it, as it's a great feature.

I had the same problem with textures when I started learning irrlicht. It was really annoying, but it's best to to fight the system and use 2^X images.

This means:
16x16
32x32
64x64
127x127
256x256
512x512 ... and so on. You can combine them like 127x512.


So to solve your problem fire up Photoshop or GIMP, and convert it into a 2^X sized PNG image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

torleif wrote:127x127
2 ^ 6.989 ?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply