ofxiPhone viewport settings question

Hi,

Today I got the iPhone 3D Programming, so I can learn OpenGL ES and most of the code is in C++, I am new to all this stuff, so very quickly I ran into my first problem. It is very basic but I cant figure it out.

The first chapter is all about creating a HelloArrow program form scratch that draw a yellow arrow in the center of the screen, so they go trough all the process of setting up the OpenGL ES, and Objective C, and C++, yada yada yada, but ofxiPhone takes care of all that so I skip to the drawing code, and here is were I need advice.

Like the NeHe tutorials they setup the glMatrixMode (projection and modelview) so they draw most of the stuff using small values (eg. 0.4f, 0.5f, 0.866f … ), of course when I draw that I cant see anything because is very tiny

  
  
struct Vertex {  
	float Position[2];  
	float Color[4];  
};  
  
const Vertex Vertices[] = {  
	{{-0.5, -0.866}, {1, 1, 0.5f, 1}},  
	{{ 0.5, -0.866}, {1, 1, 0.5f, 1}},  
	{{0, 1},		 {1, 1, 0.5f, 1}},  
	{{-0.5, -0.866}, {0.5f, 0.5f, 0.5f}},  
	{{ 0.5, -0.866}, {0.5f, 0.5f, 0.5f}},  
	{{0, -0.4f},	 {0.5f, 0.5f, 0.5f}}  
};  
  
  
// in the draw method  
glEnableClientState(GL_VERTEX_ARRAY);  
glEnableClientState(GL_COLOR_ARRAY);  
  
glVertexPointer(2, GL_FLOAT, sizeof(Vertex), &Vertices[0].Position[0]);  
glColorPointer(4, GL_FLOAT, sizeof(Vertex), &Vertices[0].Color[0]);  
  
GLsizei vertexCount = sizeof(Vertices) / sizeof(Vertex);  
glDrawArrays(GL_TRIANGLES, 0, vertexCount);  
  
glDisableClientState(GL_VERTEX_ARRAY);  
glDisableClientState(GL_COLOR_ARRAY);  
  

I can change the values in Vertices[] but I will like to stick with the same measurements as the book, any idea to proceed here? what do I need to change so I can work with the same view as the book

I try seting up the viewport and matrixmode in the setup method, the same way as the example, like this:

  
  
glViewport(0, 0, ofGetWidth(), ofGetHeight());  
glMatrixMode(GL_PROJECTION);  
const float maxX = 2;  
const float maxY = 3;  
glOrthof(-maxX, +maxX, -maxY, +maxY, -1, 1);  
glMatrixMode(GL_MODELVIEW);  
  

But no results, so I guess this changes needs to be apply somewhere else

Any help will be much appreciated

Cheers
rS

hi, yup you’re right about the problem being the coordinate system. OF automatically sets up the view to be 1 unit = 1pixel. If you put those viewsetup matrix code at the beginning of your testApp::draw() you should be able to use the same coordinates as in the examples.

Hi, thanks for the reply

I try using this:

  
  
void testApp::draw(){  
	  
	glViewport(0, 0, ofGetWidth(), ofGetHeight());  
	  
	glMatrixMode(GL_PROJECTION);  
	glLoadIdentity();  
	  
	const float maxX = 2;  
	const float maxY = 3;  
	glOrthof(-maxX, +maxX, -maxY, +maxY, -1, 1);  
	  
	//gluPerspective(45.0f, (GLfloat)ofGetWidth() / (GLfloat)ofGetHeight(), 0.1f, 100.0f);  
	  
	glMatrixMode(GL_MODELVIEW);  
	glLoadIdentity();  
	  
	quad.display();  
}  
  

Like suggested but nothing appears on the screen, and yes I check that the dimentions of the quad are in the range of 0.0 - 1.0

Any ideas?

Cheers
rS

I take it back, it does work! I was doing something wrong somewhere else :stuck_out_tongue:

Cheers
rS