how do i use glFrustum on iOS?

Hello~I try to use ofxCv on iOS.
I have error when I try to use ofVideoGrabber.

/Users/azuremous/Documents/work/openframework/of_preRelease_v007_iphone/apps/now/pattern/…/…/…/addons/ofxCv/libs/ofxCv/src/Calibration.cpp:60: error: ‘glFrustum’ was not declared in this scope

glFrustum looks like declaration on glew.h.
I already try to add header “…/…/…/libs/glew/include/”. But it didn’t work.
any Ideas? :frowning:

i was just talking with arturo, and he thinks that glFrustum does not exist on iOS. i thought it just needed a different include.

so you want to do something like this instead:

  
  
void ofFrustum(...) {  
	glMatrixMode(GL_PROJECTION);  
	ofMatrix4x4 matrix;  
	matrix.makeFrustumMatrix(...);  
	glLoadMatrixf(matrix.getPtr());  
	glMatrixMode(GL_MODELVIEW);  
}  
  

and call ofFrustrum() instead of glFrustum().

Thx!!! I fixed Calibration.cpp as you said:

  
  
void Intrinsics::loadProjectionMatrix(float nearDist, float farDist) const {  
		glViewport(0, 0, imageSize.width, imageSize.height);  
		glMatrixMode(GL_PROJECTION);  
		glLoadIdentity();  
		float w = imageSize.width;  
		float h = imageSize.height;  
		float fx = cameraMatrix.at<double>(0, 0);  
		float fy = cameraMatrix.at<double>(1, 1);  
		float cx = principalPoint.x;  
		float cy = principalPoint.y;  
        /*  
		glFrustum(  
			nearDist * (-cx) / fx, nearDist * (w - cx) / fx,  
			nearDist * (cy - h) / fy, nearDist * (cy) / fy,  
			nearDist, farDist);*/  
          
        ofMatrix4x4 matrix;  
        matrix.makeFrustumMatrix(nearDist * (-cx) / fx, nearDist * (w - cx) / fx, nearDist * (cy - h) / fy, nearDist * (cy) / fy, nearDist, farDist);  
        glLoadMatrixf(matrix.getPtr());  
          
		glMatrixMode(GL_MODELVIEW);  
		glLoadIdentity();  
		gluLookAt(  
			0, 0, 0,  
			0, 0, 1,  
			0, -1, 0);  
	}  
  

And I got new error.

/Users/azuremous/Documents/work/openframework/of_preRelease_v007_iphone/apps/lab/contoursColor
/…/…/…/addons/ofxCv/libs/ofxCv/src/Helpers.cpp:216: error: ‘glPushAttrib’ was not declared in this scope
/Users/azuremous/Documents/work/openframework/of_preRelease_v007_iphone/apps/lab/contoursColor
/…/…/…/addons/ofxCv/libs/ofxCv/src/Helpers.cpp:229: error: ‘glPopAttrib’ was not declared in this scope

  
  
void drawHighlightString(string text, int x, int y, ofColor background, ofColor foreground) {  
		vector<string> lines = ofSplitString(text, "\n");  
		int textLength = 0;  
		for(int i = 0; i < lines.size(); i++) {  
			// tabs are not rendered  
			int tabs = count(lines[i].begin(), lines[i].end(), '\t');  
			int curLength = lines[i].length() - tabs;  
			// after the first line, everything is indented with one space  
			if(i > 0) {  
				curLength++;  
			}  
			if(curLength > textLength) {  
				textLength = curLength;  
			}  
		}  
		  
		int padding = 4;  
		int fontSize = 8;  
		float leading = 1.7;  
		int height = lines.size() * fontSize * leading - 1;  
		int width = textLength * fontSize;  
	  
        GLbitfield mask = GL_DEPTH_BUFFER_BIT;  
          
		glPushAttrib(GL_DEPTH_BUFFER_BIT);   
		glDisable(GL_DEPTH_TEST);  
		ofPushStyle();  
		ofSetColor(background);  
		ofFill();  
		ofRect(x, y, width + 2 * padding, height + 2 * padding);  
		ofSetColor(foreground);  
		ofNoFill();  
		ofPushMatrix();  
		ofTranslate(padding, padding);  
		ofDrawBitmapString(text, x + 1, y + fontSize + 2);  
		ofPopMatrix();  
		ofPopStyle();  
		glPopAttrib();  
	}  
  
  

And I searched forum for this problem.
http://forum.openframeworks.cc/t/of-and-iphone-os-4.0/4185/30

glPushAttrib, glPopAttrib they can’t use on iOS?
Is there any other way to use this like glFrustum?

there is glFrustum on the iphone, but for some weird reason it’s called glFrustumf.

This is a snippet how we are using it in a current project:

  
  
        glMatrixMode(GL_PROJECTION);  
	glLoadIdentity();  
	double xmin, xmax, ymin, ymax;  
	ymax = nearClip * tan(fov * M_PI / 360.0);  
	ymin = -ymax;  
	double aspect = viewport.width/viewport.height;  
	xmin = ymin * aspect;  
	xmax = ymax * aspect;  
	glFrustumf(xmin, xmax, ymin, ymax, nearClip, farClip);  
  

Thanks your reply. :slight_smile: Is there glPushAttrib and glPopAttrib on iPhone? like glFrustum as a different name
I couldn’t find it.

no, AFAIK there is no glPush and glPopAttributes. You will have to keep track of the states manually…

wow, glFrustumf! nice. that helps.

also regarding push/pop, i think this will be handled internally by OF in the future anyway. for example, your projection matrix stack in normal GL only carries 2 elements, which is kind of ridiculous. this obviously needs to be wrapped.