Textures for the fill of a shape || Using shapes as masks

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.

I’ve been trying to do something similar to this thread, but am not sure if this is applicable when using ofBeginShape().

This is what I’m currently trying. The only thing it seems to do is darken the color of my shape… (similar to the above thread)

void LandscapeEditor::draw(){  
	// get current ground background  
	ofTexture& tex = background->getTextureReference();  
	ofCurveVertex(MIDDLE_POSITION, 0);  
	// draw curves between points  
	for(int i = 0; i < landPoints.size(); i++) {  
		LandPoint *point = landPoints[i];  
		ofCurveVertex(point->middleX, point->middleY);  

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)

glTexCoord2f(0, 0);  
glVertex3f(0, 0);  
glTexCoord2f(1, 0);  
glVertex3f(ofGetWith(), 0);  
glTexCoord2f(1, 1);  
glVertex3f(ofGetWith(), ofGetHeight());  
glTexCoord2f(0, 1);  
glVertex3f(0, ofGetHeight());  

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 :wink:


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.

hope that helps!

Wow. Thanks for the all the great information. I’m going to take another crack with your suggestions and see how far I can get.