Sign in to follow this  
gaurav khanduja

Dynamic Texture Coloring

Recommended Posts

I have a set of points 128 X 128 with some values ranging from -1 to + 1. I am creating a image using these points and assigning the colors using the values. from 0 to 0.002 I am using red and from 0 to -0.002 i am using blue. values that fall outside the region i am introducing the green component. Once the image is created i am making a texture out of it and using this texture. problem is i need to dynamically change the scale. Suppose in the above set i would like to use red from 0 to 0.001 and blue from -0.001 and then introduce the green component on either side. Is it possible to do when the texture has been created or I need to create another texture. Thanks in advance.

Share this post


Link to post
Share on other sites
Are you asking if an existing texture can be updated? If so, the answer is yes. In the case of OpenGL, you would use glTexSubImage2D or glCopyTexSubImage2D. The former is for sending an update from system memory, the latter for sending an update from the frame buffer (something you rendered with OpenGL). If it's the latter you want, there are faster ways to update textures, like using a PBuffer with a render-to-texture extension.

I'm not sure what the equivalent functions are in Direct3D.

Sean

Share this post


Link to post
Share on other sites
glTexSubImage2D or glCopyTexSubImage2D would require the me to have another texture in the memory, am I right. What I want is only changing the scale of the color as I explained above. Suppose I have two textures of 128 * 128 (created in the same way from two datasets as told in the previous post) and the color have been alloted with different scales.

If I want to bring the color scale to same values in both the textures on the fly, how should I go about it.

Will texture shading or color will help. If yes where I can find how to use it. If no how should I go about it. Thanks

Share this post


Link to post
Share on other sites
Neither of those functions require you to have an extra texture in memory. Typically you have the bytes for the texture in system memory and you call glTexImage2D when creating the texture. This tells OpenGL to make a copy of this data, converting it to the correct internal format and usually storing it in video memory. If you then change the bytes in system memory and want to update the texture OpenGL has stored in video memory, you call glTexSubImage2D. This will let you update the entire texture or just a portion of it, depending on what you want to do.

glCopyTexSubImage2D is similar, but instead of copying the bytes from system memory to video memory, it copies them from video memory to video memory. In the most simplistic case, it copies from the back buffer to your texture. This allows you to render something with OpenGL into the back buffer, copy it into a texture, and then clear the back buffer and use your texture on some object. This technique is often used for impostors, reflection, etc. (though there are extensions that provide faster ways to do it).

If all you want to do is scale the colors in a texture, you may also want to consider just calling glColor() or glMaterial(), depending on whether you have lighting off or on. I believe that whether the texture will be scaled by the current color depends on the texture environment mode (i.e. glTexEnv). There is also a texture environment color, but I haven't played around with that.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this