ITexture to IImage conversions are slow

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

If you really want to understand how an orthographic camera works versus a perspective projection camera, then this is recommend reading: Deriving Projection Matrices.
Ulf wrote: Hehe. I get your point. But I meant that making a 2D game engine with a 2D renderer requires less than a 3D game engine with a 3D renderer. Just purely that a 2D game engine is simpler.
That's quite possible because most 2D engines are built to overcome some of the pitfalls that are common to 2D games using 3D accelerated graphics. Also, if memory is an issue, then most 2D rendering engines will use less memory than a 3D rendering engine for certain things. [/code]
TheQuestion = 2B || !2B
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Ok. I can see that. So, forgive my naivety but, when rendering with an orthographic camera with 3D quads, does that mean that only the plane facing the camera will be rendered (2 triangles per sprite)?
if the plane normal is presented toward the camera, yes. You you created a 3D box, then then normal facing the camera will render that face.

If you really want to create a 2D engine (using the hardware acceleration of modern video cards), you use an orthographic camera (no perspective) and use only textured planes (a simple quad poly). You could think of this as a mario "paper" thing. So your 2D game can have "3D" effects if you like.
I want non power of 2 textures.

I am using non power of 2 textures with IVideoDriver::draw2DImage.
Why? Don't you use an alpha channel? I could do a sprite of 480x240, define a transparent background in photoshop as 512x256. Don't want to use transparency in your sprites?

AS for IRRlicht not doing 2D hardware acceleration, it's more of a hardware related thing. Get back a old 3DFX card. All modern card focus much more on 3D acceleration. Vista/Linux is even GUI accelerated in OpenGL/DX and they still look 2D, but using the 3D hardware acceleration with simple planes to have their GUI drawed.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Halifax wrote: If you really want to understand how an orthographic camera works versus a perspective projection camera, then this is recommend reading: Deriving Projection Matrices.
Thank you Halifax. I'll look.
christianclavet wrote: if the plane normal is presented toward the camera, yes. You you created a 3D box, then then normal facing the camera will render that face.

If you really want to create a 2D engine (using the hardware acceleration of modern video cards), you use an orthographic camera (no perspective) and use only textured planes (a simple quad poly). You could think of this as a mario "paper" thing. So your 2D game can have "3D" effects if you like.
Ok. Thank you Christian.
christianclavet wrote: Why? Don't you use an alpha channel? I could do a sprite of 480x240, define a transparent background in photoshop as 512x256. Don't want to use transparency in your sprites?
Why? Can't I use transparency without power of 2 textures?
I've only testing scaling on them, not transparency.
I'm used to the BitBlit functions in windows where you don't need power of 2 textures for transparency.
christianclavet wrote: AS for IRRlicht not doing 2D hardware acceleration, it's more of a hardware related thing. Get back a old 3DFX card. All modern card focus much more on 3D acceleration. Vista/Linux is even GUI accelerated in OpenGL/DX and they still look 2D, but using the 3D hardware acceleration with simple planes to have their GUI drawed.
Yea I actually know this.. I think I'm just doing so many things at the same time that I've been over thinking and confusing myself sometimes. Hyper! But.. I'm settling in slowly... :?
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ulf wrote:
christianclavet wrote: Why? Don't you use an alpha channel? I could do a sprite of 480x240, define a transparent background in photoshop as 512x256. Don't want to use transparency in your sprites?
Why? Can't I use transparency without power of 2 textures?
I've only testing scaling on them, not transparency.
I'm used to the BitBlit functions in windows where you don't need power of 2 textures for transparency.
You should really try to read those answers with a little more motivation for correct understanding. The described way allows for NPOT sprites on every hardware, i.e. even on such hardware that strictly enforces the POT dimensions. If you just don't want to accept suggestions, you should probably stop asking...
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

hybrid wrote: You should really try to read those answers with a little more motivation for correct understanding. The described way allows for NPOT sprites on every hardware, i.e. even on such hardware that strictly enforces the POT dimensions.
Your statement does confuse me (in relation to christianclavets quote)
christianclavet wrote: Why? Don't you use an alpha channel? I could do a sprite of 480x240, define a transparent background in photoshop as 512x256. Don't want to use transparency in your sprites?


Your quote tells me yes I can use non power of 2 textures when using transparency. From christians quote I thought no I must end up merging it with the power of 2 transparent texture.
hybrid wrote: If you just don't want to accept suggestions, you should probably stop asking...
Gee I don't sense any sarcasm.
Don't get me wrong, I still appreciate all the help you have given me

I can practice more and ask less. I'm just getting into it.
All the terms and links that have been thrown at me have helped though, such as NPOT which I'd never heard of.

.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

I'm not sure if you understand now or not... but I will say anyway:

The point about non-power-of-two textures, is that while they may work fine on *your* video card, they may not work on other people's, not all cards support them (or in the case of mine, it does, but they are rendered horribly). So you probably *should* use power of two textures, and as Christian said you can use transparency to pad out all your graphics to a POT level.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

xDan wrote: I'm not sure if you understand now or not... but I will say anyway
Thanks.
xDan wrote: The point about non-power-of-two textures, is that while they may work fine on *your* video card, they may not work on other people's, not all cards support them (or in the case of mine, it does, but they are rendered horribly). So you probably *should* use power of two textures, and as Christian said you can use transparency to pad out all your graphics to a POT level.
I think I do now (understand).

So in effect I MUST use power of 2 textures to ENSURE they will draw properly on ALL video cards. And ... Christian was telling me that I can actually make my sprites (characters, tiles etc) non power of 2 if I want, but I'll have to put it in a power of 2 texture anyway when I draw it (that is if I want to make sure it works on all video cards).
I hope I got it!

So, .. actually I could do it like this if wanted:

I can have a non power of 2 image (bits) inside a power of 2 texture. Then when I want to draw it, I can still draw a non power of 2 section (rectangle) from the power of 2 texture.. and that will work on all video cards.
Am I right? :shock:

*EDIT* From what I understand so far it's because the power of 2 thing is just for transformation. You can always blit a single pixel from it but there could be issues with translation to the viewport or it's bounding box since it's actually from a 3D space or it may be rotated.
Something like that??

Thanks for all your help.
Everyone.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, you still didn't get it. This is not at all about blitting single pixels, but fast rendering. If you really want to draw pixel-wise, you can do whatever you want. Nothing will be really fast. But if you want to get accelerated rendering, you have to obey to the hw restrictions. And most of the gfx cards require you to put POT textures to get hw acceleration. Otherwise, the texture lookup needs to be made in sw and is slow.
So the solution is that you simply put the non-POT sprite into a texture with POT dimensions, where the non-used area is simply transparent. Then you can render the texture as-is, giving the gfx card a full POT texture, but still get the sprite as desired in some smaller NPOT size.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

I wrote: I can have a non power of 2 image (bits) inside a power of 2 texture. Then when I want to draw it, I can still draw a non power of 2 section (rectangle) from the power of 2 texture.. and that will work on all video cards.
Am I right?
hybrid wrote: No, you still didn't get it.
Hmmm. So I can't do that. .... .... I'm not gonna ask more.
It is getting less understood by me.
hybrid wrote: This is not at all about blitting single pixels, but fast rendering.
I was saying/asking if the need for power of 2 for some hardware was so the hardware can do transfrormations properly/accurately. I didn't say this is about pixels.
hybrid wrote: So the solution is that you simply put the non-POT sprite into a texture with POT dimensions, where the non-used area is simply transparent. Then you can render the texture as-is, giving the gfx card a full POT texture, but still get the sprite as desired in some smaller NPOT size.
Yea. I guess this is where I'm still making it complicated in my own head!
Cause I'm thinking, but I want to draw sections of the texture (not the whole texture). So I can't draw it "wholly" as is.
If my sprite is non power of 2 but sitting inside a larger power of 2 texture (with the sprite fixed to the top left corner of the transparent texture for example), then when I break up my "frames" inside my texture for drawing, all of them are going to be non power of 2, and the right and bottom sections of my texture will be somewhat unused. So I'll be sending the power of 2 texture to be drawn, but I'll be telling it to draw just a non power of 2 section of it.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

You got the bit about how you should make your sprites correct I think. As long as it works who cares why eh?? :)

Power of two is nothing to do with the transformations. Its only about storing/accessing the texture. If the texture is on the video card, then you will still have problems with non POT even by accessing the texture pixel-by-pixel.

Although, unless you are using a pixel shader, it makes no sense to talk about acessing the texture pixel by pixel as all rendering on the graphics card is done using triangles. The only way *you* would render pixel by pixel would be if you were doing software rendering. (So I guess Irrlicht's software renderer might not have these POT problems - but if you are doing software rendering with 2D graphics in Irrlicht you may as well forget Irrlicht or even C++ and use something a lot simpler!!)

> So I'll be sending the power of 2 texture to be drawn, but I'll be telling it to draw just a non power of 2 section of it.

yeah, that's fine I think. As long as the texture is power of two, then when rendering a quad you can set the UV coordinates to whereever you like within the texture. Have a 1024x1024 texture or something and pack it with all your animation frames.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

xDan wrote: yeah, that's fine I think. As long as the texture is power of two, then when rendering a quad you can set the UV coordinates to whereever you like within the texture. Have a 1024x1024 texture or something and pack it with all your animation frames.
Ok. Thanks xDan. That's what I really wanted to know.

You seem to know something but you don't have this huge ego. Thanks.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Post Reply