[Solved] 2DBackground,a bug of OGRE?

Problems building or running the engine, queries about how to use features etc.
lmas19820607
Halfling
Posts: 72
Joined: Wed Dec 06, 2006 7:35 am

[Solved] 2DBackground,a bug of OGRE?

Post by lmas19820607 »

I want to show a 1024*768 png file as background, there is some line on the picture file.
I run my application by 1024 * 768 fullscreen mode. The picture is not as clear as I want. The vertical lines looks good, but the horizontal lines looks bad.

And I found that when I show a 1024 * 512 picture, it works well.

I have tried several way to show the background, and the result was same. I use
http://www.ogre3d.org/wiki/index.php/Di ... ackgrounds.
and
http://www.ogre3d.org/wiki/index.php/SpriteManager2d
and also tried to use Overlay.


this is my code. It's modifed from http://www.ogre3d.org/wiki/index.php/Di ... ackgrounds.

MaterialPtr material = MaterialManager::getSingleton().create("Background", "General");
material->getTechnique(0)->getPass(0)->createTextureUnitState("test3.png");
material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
material->getTechnique(0)->getPass(0)->setLightingEnabled(false);
material->getTechnique(0)->getPass(0)->setTextureFiltering(TFO_NONE);
// Create background rectangle covering the whole screen
Rectangle2D* rect = new Rectangle2D(true);
Ogre::RenderSystem * rs = Root::getSingleton().getRenderSystem();
Real a = rs->getHorizontalTexelOffset();
Real hoffset = rs->getHorizontalTexelOffset() / (0.5 * 1024);
Real voffset = rs->getVerticalTexelOffset() / (0.5 * 768);
rect->setCorners(-1 + hoffset, 1 - voffset, 1 + hoffset, -1 - voffset);
rect->setMaterial("Background");
// Render the background before everything else
rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
// Hacky, but we need to set the bounding box to something big
// NOTE: If you are using Eihort, please see the note below on setting the bounding box
rect->setBoundingBox(AxisAlignedBox(-100000.0*Vector3::UNIT_SCALE, 100000.0*Vector3::UNIT_SCALE));
// Attach background to the scene
SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
node->attachObject(rect);

this the png file
Image
this the screen shot
Image
lmas19820607
Halfling
Posts: 72
Joined: Wed Dec 06, 2006 7:35 am

Post by lmas19820607 »

I found the answer.
It's nothing about draw, but something about load texture.
When I load a 1024 * 768 picture, Ogre creates a 1024 * 1024 Texture, the texture is already not clear.

I put my background picture into a 1024*1024 png file, then the problem is gone.
User avatar
neocryptek
Gnome
Posts: 335
Joined: Sat Mar 01, 2003 11:21 pm
Location: Idaho, USA

Post by neocryptek »

Sounds like your card doesn't support non power of two textures, so Ogre is trying to be helpful and upscale them to power of two; this of course causes artifacts. Ogre.log should list this, along with other card capabilities. As you found in the above post, using a power of two texture prevents Ogre from scaling it.
futnuh
Goblin
Posts: 225
Joined: Sun Sep 25, 2005 3:22 am
Location: Calgary, Alberta
x 1

Re: [Solved] 2DBackground,a bug of OGRE?

Post by futnuh »

lmas19820607 wrote:[...]
I have tried several way to show the background, and the result was same. I use http://www.ogre3d.org/wiki/index.php/Di ... ackgrounds. [...]
The above wiki page is now blank. Has someone deleted the contents?

[edit]Correct link is http://www.ogre3d.org/wiki/index.php/Di ... ackgrounds . Seems that phpBB is including the trailing dot in the href[/edit]