Jump to content
  • Advertisement
Sign in to follow this  
brett01

OpenGL Filling a quad in a texture

This topic is 3320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have four points of 2d texture coordinates inside a texture and I need to fill the quad formed by these four points in the texture.That is I need to update the texture array at those pixels.I actually use openGL to be specific.Can someone suggest an easy way of doing it?? Thanks & Regards, brett.

Share this post


Link to post
Share on other sites
Advertisement
The 4 corners are presumably given as relative texture co-ordinates. So convert them into absolute (pixel) co-ordinates and use glTexSubImage2D for pixel replacement.

Look e.g. here for the section "Replacing All or Part of a Texture Image".

Share this post


Link to post
Share on other sites
Thank you very much.But Its for a rectangle(that is parallel to the texture in both height and width,I think so??)But my rectangle may be rotated.All i have is four points.

[Edited by - brett01 on August 13, 2009 3:22:29 PM]

Share this post


Link to post
Share on other sites
In such a case you can compute the including axis-aligned rectangle (i.e. build pairs of the maxs and mins of the x and y co-ordintaes of the points), allocate a buffer for texels, preset it with the original texture data inside the axis-aligned rectangle, iterate the texels and transform their position back. Do nothing if they fall outside the substitution rectangle, otherwise do some pixel interpolation and store the result into the target rectangle at the untransformed position. Then use glTexSubImage2D as usual.

This is not the most efficient way (especially for very long or very small substitutions), but should show the principal way. However, you can improve the agorithm by using scanline iteration instead of rectangular iteration through the target area.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!