Page 1 of 1

Rendering dynamic textures

Posted: Tue Apr 17, 2007 4:18 pm
by callump
I want to generate a texture in code and then apply that to objects in my scene. Can someone point me to a code fragment that illustrates how in Irrlicht I can:

- use an arbitrary sized block of system memory as a texture

and

- apply a texture scale (in OpenGL terms) so that non-power of two textures appear to fill the texel space correctly.

I thought the render-to-texture example might help but that appears to be not quite what I need.

--Callum

Posted: Wed Apr 18, 2007 1:50 pm
by bigfish
I could be mistaken but I don't think OpenGL lets you use textures that aren't powers of two. You just need to use a texture that's as big as or bigger than the texture you're trying to display and adjust the texture coordinates of the polygon so it only renders the portion of the texture that you're using.

Posted: Wed Apr 18, 2007 2:11 pm
by callump
Yep - that's why I need to be able to scale the texture. If my dynamic texture is 200x100, I create an OpenGL texture that is 256x128, render into a 200x100 portion of it and use OpenGL to scale this portion up to fill the polygon I'm texturing.

Posted: Wed Apr 18, 2007 2:40 pm
by kburkhart84
bigfish wrote:I could be mistaken but I don't think OpenGL lets you use textures that aren't powers of two. You just need to use a texture that's as big as or bigger than the texture you're trying to display and adjust the texture coordinates of the polygon so it only renders the portion of the texture that you're using.
Actually, for some time now OGL has support for non power of two textures. Depending on the video card, it may be slower though. Some older cards don't support it though. It's still better to use the PO2 textures because they are better supported and quicker.

OP: Why can't you just use a correctly sized texture from the start instead of trying to resize it later??

Posted: Wed Apr 18, 2007 2:43 pm
by SilentBob
If the graphics card supports non-power-of2 then you can use it in opengl.
Check for GL_ARB_texture_non_power_of_two.

To scale - you could always just adjust the texture coords - 200.0f/256.0f

As for dynamic uploading - I'm not sure how to do it in Irrlicht.
In plain OpenGL, after you've created your texture with glGenTextures(...) and glTexImage2D(...)
you can update part / all of that texture by using glTexSubImage2D

Posted: Wed Apr 18, 2007 4:21 pm
by hybrid
In order to create a texture from some memory block you create an IImage from that area and create the texture from the image. If you just want to access the memory later on you can skip this part and directly lock() and unlock() the texture. This gives you the raw memory pointer. Upon unlocking the texture update occurs.
Texture scaling is possible via the texture matrix. Just set the texture matrix to a scale matrix with the required scales.
NPOT textures are supported by Irrlicht, but there's no automatic fall-back. So you have to query the driver for NPOT capability and pass the correctly sized texture depending on the return value.

Posted: Wed Apr 18, 2007 5:36 pm
by callump
Thanks hybrid - that gives me somewhere to start.