PDA

View Full Version : How to do Texture to an irregular polygon



JMENON
11-14-2009, 07:16 PM
Could anyone tell me how to do texturing on a 2D Pentagon or any irregular polygon.
How do i make texture co ordinates?

marshats
11-15-2009, 10:07 AM
You need to set a (s,t) coordinate with every vertex (x,y,z) that you define. This means use of the glTexCoord* and glVertex* commands. The (s,t) coordinates correspond to your texture; (0,0) is lower left corner and (1,1) is upper right corner.

Details are better explained in Chapter 9 of the Redbook (http://www.glprogramming.com/red/chapter09.html). It may seem daunting to read at first but after understanding this chapter you will be able work with textures. You can get code from this book here. (http://www.opengl.org/resources/code/samples/redbook/) Specifically the sample checker.c would be helpful to look at.

You may get some benefit from running the "texture" example here (http://www.gamedev.net/reference/articles/article839.asp) yourself. It allows you to see the effect of changing the (s,t) and (x,y) parameters interactively.