Jump to content
  • Advertisement
Sign in to follow this  

Mapping rectangular texture to arbitrary convex quadrilateral

This topic is 2148 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 there,

after two days of research and trial and error, I give up and need help.
I'm trying to map a texture (not necessarily quadratic or a size of 2^x) to an arbitrary convex quadrilateral. However, since the OpenGL pipeline divides the quad into two triangles, there is an ugly seam
Original texture:

Texture, if the upper left point is set to (0, 0.5):

Currently, the texture coordinates are mapped in the most naive way:
305             glTexCoord4f(0.0f, 1.0f, 0.0f, 1.0f);306             glVertex3f(_wall_properties.matrix[y][x].first, _wall_properties.matrix[y][x].second, 0.0f);307 308             glTexCoord4f(0.0f, 0.0f, 0.0f,  1.0f );309             glVertex3f(_wall_properties.matrix[y + 1][x].first, _wall_properties.matrix[y + 1][x].second, 0.0f);310 311             glTexCoord4f(1.0f, 0.0f, 0.0f, 1.0f);312             glVertex3f(_wall_properties.matrix[y + 1][x + 1].first, _wall_properties.matrix[y + 1][x + 1].second, 0.0f);313 314             glTexCoord4f(1.0f, 1.0f, 0.0f, 1.0f);315             glVertex3f(_wall_properties.matrix[y][x + 1].first, _wall_properties.matrix[y][x + 1].second, 0.0f);
I have already read tons of stuff on the topic, including Cass' explanation at http://www.xyzw.us/~cass/qcoord/. Strangely, changing the q-coordinate of the textures does not have any effect on the texture. Besides, I wouldn't know, how to calculate the correct q.
I also tried changing the texture matrix following this post: http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl/ with unsatisfying results.

Would a correct texture matrix solve the problem as this post http://blogs.agi.com/insight3d/index.php/2009/11/20/trapezoidal-texture-projection-with-opengl/ proposes? Edited by Kepakiano

Share this post

Link to post
Share on other sites

This thread can be closed.


If someone comes across the same problems and finds this thread, here is what I did:

My previous post suggested that I wanted a perspective projection of the texture onto the quad, which I don't.

This is what I wanted:



-> A rectangular texture mapped onto a quadrilateral via bilinear interpolation. Since OpenGL does not provide any means to do this in the FFP (afaik), it is achieved in a fragment shader using the calculations from this thread: http://www.gamedev.net/topic/538963-interpolation-between-arbitrary-quadrilaterals/#entry4994411

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!