Rendering dynamic textures

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
callump
Posts: 7
Joined: Tue Apr 17, 2007 4:14 pm

Rendering dynamic textures

Post 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
bigfish
Posts: 19
Joined: Fri Mar 23, 2007 6:18 pm

Post 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.
callump
Posts: 7
Joined: Tue Apr 17, 2007 4:14 pm

Post 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.
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post 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??
SilentBob
Posts: 3
Joined: Thu Mar 08, 2007 12:11 pm

Post 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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post 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.
callump
Posts: 7
Joined: Tue Apr 17, 2007 4:14 pm

Post by callump »

Thanks hybrid - that gives me somewhere to start.
Post Reply