/* FIXED */Problem about Texture filtering in OpenGL driver

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
nutpor
Posts: 31
Joined: Sun Jun 12, 2005 5:06 pm
Location: Behind You ^_^

/* FIXED */Problem about Texture filtering in OpenGL driver

Post by nutpor »

Hi, I'm new to this engine and now face a serious problems :cry:
I develop 3D scene with 2D charactor on it (like YS VI: The Ark of Napishtim)
and I cannot set texture filtering properly I use this code in my custom scene node :

Code: Select all

virtual void setTextureFilter(TEXTURE_FILTER_FLAG efil)
	{
		eTextureFilter = efil;
		switch (eTextureFilter)
		{
			case TEXTURE_NO_FILTER:
				setMaterialFlag(EMF_BILINEAR_FILTER , FALSE);
				setMaterialFlag(EMF_TRILINEAR_FILTER , FALSE);
				break;

			case TEXTURE_BILINEAR_FILTER:
				setMaterialFlag(EMF_BILINEAR_FILTER , TRUE);
				setMaterialFlag(EMF_TRILINEAR_FILTER , FALSE);
				break;

			case TEXTURE_TRILINEAR_FILTER:
				setMaterialFlag(EMF_BILINEAR_FILTER , TRUE);
				setMaterialFlag(EMF_TRILINEAR_FILTER , TRUE);
				break;

			default:
				break;
		}
	}
When I set filter to TEXTURE_NO_FILTER it will look correct if I add some billboard and particle effect in to scene, if I don't add both things texture look like it had filtered which I don't want it to happen, I just want to use no texture filtering , so dose it has some way to do this properly?

ps. my app test in all driver (opengl, dx8, dx9) and result is not the same!.
When I change driver type result is change too. But it look finest on opengl, I think that dx8, dx9 have some problem in sorting scenenode order to be drawn.

Any help would be appreciated.
Last edited by nutpor on Tue Aug 30, 2005 4:02 am, edited 1 time in total.
Don't look back, Look in the ~MIRROR~ to look back.
nutpor
Posts: 31
Joined: Sun Jun 12, 2005 5:06 pm
Location: Behind You ^_^

Post by nutpor »

No answers!!!
Please help this is a huge problem in my project.
Don't look back, Look in the ~MIRROR~ to look back.
nutpor
Posts: 31
Joined: Sun Jun 12, 2005 5:06 pm
Location: Behind You ^_^

Post by nutpor »

:( :( :cry: :cry: :( :(
Still No Support!!!
:cry: I'm a bit tired, But looking forward for Help!. Thanks.

ps, may be I have to switch to another engine, if I can't figure out about this problems. Hmm... again I like this ENGINE because it is ease of uses, but if nessesary I will look at OGRE, NebulaDevice.
Don't look back, Look in the ~MIRROR~ to look back.
nutpor
Posts: 31
Joined: Sun Jun 12, 2005 5:06 pm
Location: Behind You ^_^

** How to Fix this Problem!!!**

Post by nutpor »

OK, I have figure it out. Bug is in the engine itself.

in COpenGLDriver.cpp
in void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial, bool resetAllRenderstates)

change:

Code: Select all

if (resetAllRenderstates || lastmaterial.BilinearFilter != material.BilinearFilter)
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
			Material.BilinearFilter ? GL_LINEAR : GL_NEAREST);
to:

Code: Select all

if (resetAllRenderstates || lastmaterial.BilinearFilter != material.BilinearFilter
		|| lastmaterial.TrilinearFilter != material.TrilinearFilter)
	{
		setTexture(0, material.Texture1);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
			Material.BilinearFilter ? GL_LINEAR : GL_NEAREST);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
		Material.BilinearFilter ? GL_LINEAR : GL_NEAREST);
		
		setTexture(1, material.Texture2);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
			Material.BilinearFilter ? GL_LINEAR : GL_NEAREST);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
			Material.BilinearFilter ? GL_LINEAR : GL_NEAREST);
	}
And all filtering problem should be gone! :D
I don't sure that this fix will remove all the bug about texture filtering in opengl, but it works fine for me and look nice in my project.

ps. I don't know how to do trilinear in opengl so I do the same both bilinear and trilinear. :oops:
Don't look back, Look in the ~MIRROR~ to look back.
Post Reply