While that’s true, I’m fairly certain what you wrote is essentially what open frameworks implicitly does when you call draw image. From what I can tell, ofImage.draw() calls ofImage.drawSubsection(), which calls ofGlRenderer.draw(), which in turn calls ofTexture.drawSubsection(), which seems pretty similar to what you wrote here. I’m pretty new to OF, so I’m not too sure about this, but is there any real advantage to writing it explicitly in your own code?
Here’s the function from ofTexture.cpp:
void ofTexture::drawSubsection(float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) {
GLfloat px0 = x; // up to you to get the aspect ratio right
GLfloat py0 = y;
GLfloat px1 = w+x;
GLfloat py1 = h+y;
if (texData.bFlipTexture == ofIsVFlipped()){
swap(py0,py1);
}
// for rect mode center, let's do this:
if (ofGetRectMode() == OF_RECTMODE_CENTER){
px0 -= w/2;
py0 -= h/2;
px1 -= w/2;
py1 -= h/2;
}
//we translate our drawing points by our anchor point.
//we still respect ofRectMode so if you have rect mode set to
//OF_RECTMODE_CENTER your anchor will be relative to that.
GLfloat anchorX;
GLfloat anchorY;
if(bAnchorIsPct){
anchorX = anchor.x * w;
anchorY = anchor.y * h;
}else{
anchorX = anchor.x;
anchorY = anchor.y;
}
px0 -= anchorX;
py0 -= anchorY;
px1 -= anchorX;
py1 -= anchorY;
// -------------------------------------------------
// complete hack to remove border artifacts.
// slightly, slightly alters an image, scaling...
// to remove the border.
// we need a better solution for this, but
// to constantly add a 2 pixel border on all uploaded images
// is insane..
GLfloat offsetw = 0.0f;
GLfloat offseth = 0.0f;
if (!ofGLSupportsNPOTTextures() && bTexHackEnabled) {
offsetw = 1.0f / (texData.tex_w);
offseth = 1.0f / (texData.tex_h);
}
// -------------------------------------------------
ofPoint topLeft = getCoordFromPoint(sx, sy);
ofPoint bottomRight = getCoordFromPoint(sx + sw, sy + sh);
GLfloat tx0 = topLeft.x + offsetw;
GLfloat ty0 = topLeft.y + offseth;
GLfloat tx1 = bottomRight.x - offsetw;
GLfloat ty1 = bottomRight.y - offseth;
/*if(z>0 || z<0){
ofPushMatrix();
ofTranslate(0,0,z);
}*/
quad.getVertices()[0].set(px0,py0,z);
quad.getVertices()[1].set(px1,py0,z);
quad.getVertices()[2].set(px1,py1,z);
quad.getVertices()[3].set(px0,py1,z);
quad.getTexCoords()[0].set(tx0,ty0);
quad.getTexCoords()[1].set(tx1,ty0);
quad.getTexCoords()[2].set(tx1,ty1);
quad.getTexCoords()[3].set(tx0,ty1);
// make sure we are on unit 0 - we may change this when setting shader samplers
// before glEnable or else the shader gets confused
/// ps: maybe if bUsingArbTex is enabled we should use glActiveTextureARB?
glActiveTexture(GL_TEXTURE0);
bind();
quad.draw();
unbind();
/*if(z>0 || z<0){
ofPopMatrix();
}*/
}
If you want to draw it in 3D space without passing in a custom width and height, you can cut out all the custom mesh drawing and just do:
ofPushMatrix();
ofTranslate(pt);
ball.draw(0, 0);
ofPopMatrix();
The reason this is probably a better idea than passing in width and height arguments is that it will make things less confusing if you ever want to change the image size for other reasons that are not based on depth.