Hi. I’m new to Openframeworks and OpenGL ES, and am hoping someone can point me in the right direction. I need to use a texture for the fill of a 2d shape. I am thinking the best way would be to use the shape as a mask for an image…but have failed in trying to implement this. If anyone knows of a good way to do this, I would have endless thanks.
Hey, unfortunately your code won’t work because for each vertex you also need to supply texture coordinates, i.e. what point in the texture corresponds to that vertex, and then the pixels of the texture (texels) are interpolated across each face. If the texture you are using is a RECT texture (Default) then you give the uv coordinates in pixels, if the texture you are using is TEXTURE_2D then you give normalized uv coordinates (0…1). I think currently there is no way of doing this using ofBeginShape() / ofEndShape.
With opengl, you would do this with an accompanying glTexCoord call for each (or multiple) glVertex calls. E.g. (draw a fullscreen quad with a texture)
of course another problem is, that the above method (opengl immediate mode) will not work in opengl es, you need to use vertex arrays. But I have a wrapper for vertex arrays which should do the trick
One last thing to point out though, is that ofBeginShape() does triangulation for you, I.e. you just give the outline of a complex shape, and it will create all required vertices / faces. MSAShape3D does not do that, it merely stores all the data you give it in vertex arrays, so you will need to determine the triangulation yourself.