How to fill a hill with a custom texture using OpenGl? -
i trying larn opengl reading various tutorials, looking @ http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1
in tutorial, takes texture stripes:
and wraps around hill like:
her creates vertices , texture coordinates, taking coordinates of top of hill , creating triangle strip
_hillvertices[_nhillvertices] = cgpointmake(pt0.x, 0 + miny); _hilltexcoords[_nhillvertices++] = cgpointmake(pt0.x/512, 1.0f); _hillvertices[_nhillvertices] = cgpointmake(pt1.x, 0 + miny); _hilltexcoords[_nhillvertices++] = cgpointmake(pt1.x/512, 1.0f); _hillvertices[_nhillvertices] = cgpointmake(pt0.x, pt0.y); _hilltexcoords[_nhillvertices++] = cgpointmake(pt0.x/512, 0); _hillvertices[_nhillvertices] = cgpointmake(pt1.x, pt1.y); _hilltexcoords[_nhillvertices++] = cgpointmake(pt1.x/512, 0); my question is, if had same texture stripes, wanted render on hills without distortion ? notice hill image, texture wrapped around hills (so stripes curved), how apply texture straight lines original image ?
i using opengl-es 2.0.
edit.
i tried setting texture-coordinates same vertex coordinates, didn't work out hoped:
the first image shows texture. , sec image effect when applied hills. stripes no longer "wavy", seem much larger original texture, , seem oriented wrong way. how right ? modified code is
_hilltexcoords[tcc++]=cgpointmake(p0.x/512, 0+_miny); _hilltexcoords[tcc++]=cgpointmake(p0.x/512, p0.y/512);
for doing in 3d must understand asking getting 2d screen projection of model(the hill) , applying texture on projection.
the robust way of doing creating stencil buffer , drawing hill onto it. draw fullscreen textured quad using stencil buffer quad drawn stencil true (the hill visible).
pretty much same can done alpha channel. utilize colour mask draw hill alpha channel , utilize blending draw total screen textured quad alpha 1.
if have access shaders utilize fragment shader relative screen coordinates of every fragment top left corner (0,0) , bottom right (1,1) utilize these coordinates image texel instead of using texture coordinates model.
opengl-es opengl-es-2.0
No comments:
Post a Comment