draw2DImage and DirectX pixel gaps

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

draw2DImage and DirectX pixel gaps

Post by Nalin »

A friend of mine was trying to use draw2DImage to draw a simple 2D tiled level when he ran into the following problem:

DirectX tile problem:
http://img385.imageshack.us/my.php?image=ge4sg7.png

The problem is the line of black pixels between each row of tiles. That shouldn't happen. Indeed, once switched to OpenGL mode, it draws perfectly (aside from the 1.4+ scaling bug which is already known.)

It works correctly in Irrlicht version 1.3.1. He tried 1.4.1 and the SVN trunk and they both failed to work.

Code: Select all

// Render Tiles
// Level is 64x64 tiles.  Tiles are 16x16 pixels.
ITexture *tileset = driver->getTexture("images/tiles.png");
if (tileset != 0)
{
    for (int i = 0; i < 64*64; i++)
    {
        driver->draw2DImage(tileset, core::position2d<int>(((i % 64) * 16), ((i / 64) * 16)), core::rect<int>(0, 0, 16, 16));
    }
}
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Sorry, I have to rewrite your loop because it is bugging me to no end!

Code: Select all

// Render Tiles
// Level is 64x64 tiles.  Tiles are 16x16 pixels.
ITexture *tileset = driver->getTexture("images/tiles.png");
if (tileset != 0)
{
    for (int i = 0; i < 64; i++)
    {
        for(int p = 0; p < 64; p++)
        {
            driver->draw2DImage(tileset, core::position2d<int>(i*16, p*16), core::rect<int>(0, 0, 16, 16));
        }
    }
} 
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Dark_Kilauea wrote:Sorry, I have to rewrite your loop because it is bugging me to no end!

Code: Select all

// Render Tiles
// Level is 64x64 tiles.  Tiles are 16x16 pixels.
ITexture *tileset = driver->getTexture("images/tiles.png");
if (tileset != 0)
{
    for (int i = 0; i < 64; i++)
    {
        for(int p = 0; p < 64; p++)
        {
            driver->draw2DImage(tileset, core::position2d<int>(i*16, p*16), core::rect<int>(0, 0, 16, 16));
        }
    }
} 
Not to really get into it, but I would venture to say that his loop is definitely more optimized.
TheQuestion = 2B || !2B
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

you think a modulo and a division are more optimized than multipliers?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

What are the dimensions of tiles.png and the size of the window?
I can see a bug with direct3d9, it's missing the first pixel of the upper and left edges of the screen when using a 1031x769 window. I tried with non-power of two tiles but my graphics card support npot textures
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

are the dimensions of the tiles correct ???
you write this:

Code: Select all

// Level is 64x64 tiles.  Tiles are 16x16 pixels.
and then this:

Code: Select all

driver->draw2DImage(tileset, core::position2d<int>(((i % 64) * 16), ((i / 64) * 16)), core::rect<int>(0, 0, 16, 16)
so you use a rect from 0,0 to 16,16...
but that means the tiles are 17x17 px !?!?! :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Acki wrote:are the dimensions of the tiles correct ???
you write this:

Code: Select all

// Level is 64x64 tiles.  Tiles are 16x16 pixels.
and then this:

Code: Select all

driver->draw2DImage(tileset, core::position2d<int>(((i % 64) * 16), ((i / 64) * 16)), core::rect<int>(0, 0, 16, 16)
so you use a rect from 0,0 to 16,16...
but that means the tiles are 17x17 px !?!?! :shock:
This is confusing but correct ;-). Irrlicht is not working with pixels but with units - which means you have to think about the borders of images. I also stumpled upon that once, but since I got used to it, it's actually not that bad to work with.

Bitplane: I do often outcomment the npot-support in Irrlicht to test how it will look like on other computers. It can be done in both - the d3d9textures or in the d3d9driver. But if it's a npot-problem then it's not a real bug anyway.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Nalin
Posts: 194
Joined: Thu Mar 30, 2006 12:34 am
Location: Lacey, WA, USA
Contact:

Post by Nalin »

bitplane wrote:What are the dimensions of tiles.png and the size of the window?
I can see a bug with direct3d9, it's missing the first pixel of the upper and left edges of the screen when using a 1031x769 window. I tried with non-power of two tiles but my graphics card support npot textures
tiles.png is 2048x512.

Code: Select all

if ((device = createDevice(video::EDT_OPENGL, core::dimension2d<int>(1200, 805))) == 0)
return false;
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Hello

I'm making a little online 2D game and I have got some weird problems with the 2D too...

With directX9 it works OK on my 8800GT, at work the tiles are scaled on the G33/G31 integrated GPU.
On directX8 it has bizarre lines around the tiles like as if they were 1 pixel too small in height and the other renderer modes are worse.

Maybe this is a known issue (then please redirect me to a post/solution :D )
otherwise I'll post a more detailed bug report here.


Have to say that otherwise it's an excellent engine and really nice to work with, keep up the good work!!
Post Reply