OpenGL ES 2.0/iOS - Quad Warp shader, glMultMatrixf alternative

Hi!

I’m trying to implement proper ( homography based ) quad warping
in the app for iOS. Since I’m using shaders in the project I have to set render to openGL ES2.0 and
unfortunately, after that the code that used to work under fixed pipeline fails, since
vital glMultMatrixf method is not available in ES 2.0…

void Quad::draw(ofFbo *fbo){

vector <ofPoint> src;
src.clear();
src.push_back(ofPoint(0,0));
src.push_back(ofPoint(fbo->getWidth(),0));
src.push_back(ofPoint(fbo->getWidth(),fbo->getHeight()));
src.push_back(ofPoint(0,fbo->getHeight()));

ofPushMatrix();
findHomography(src, points, matrix);
ofSetColor(255,255,255);

glMultMatrixf(matrix);  // <----------  WON'T WORK in openGL ES 2.0

fbo->draw(0,0);
ofPopMatrix(); }

Given that all homography matrix calculations are ok the challenge is to write proper vertex/fragment shader
to take advantage of the provided 4x4 matrix and distort ofFbo accordingly.
Any hits how to approach the problem would be much appreciated, since I’m
still quite new to shaders :smile: !

Cheers!

You should be able to use ofMultMatrix(matrix) in place of glMultMatrixf. Just make sure your matrix is a oF order matrix (see [ofMatrix4x4.h][1] for more info)

You could use https://github.com/julapy/ofxQuadWarp though! Tried and tested Quadwarping on iOS.
[1]: https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/math/ofMatrix4x4.h

1 Like

Hi!

Thanks @danoli3 for the hint !
I’ve checked ofxQuadWarp example and it seems that it still assumes the use of glMultMatrixf:

//======================== get our quad warp matrix.

ofMatrix4x4 mat = warper.getMatrix();

//======================== use the matrix to transform our fbo.

glPushMatrix();
glMultMatrixf( mat.getPtr() );
{
    fbo.draw( 0, 0 );
}
glPopMatrix();

Could you be so kind and post the code you’ve successfully used on iOS (are you sure you’re using ES 2.0 renderer via setting window->enableRendererES2(); in main.mm ? That’s the bit that makes the matrix stack operations obsolete )
Thanks !

@danoli3 - indeed just using ofMultMatrix() solved the problem, thanks :slight_smile: !

1 Like