Draw Circle and triangle using the same viewport?

Hi,

I want to draw circle and triangle on the same surface using the same viewport. Currently I am able to draw them using the different viewport.

Below is the code used to draw circle and triangle using the different viewport.


CGRect rect = theView.bounds; 
	
	Vertex3D    vertex1 = Vertex3DMake(0.1, 0.0, -3.0);
	Vertex3D    vertex2 = Vertex3DMake(0.2, 0.1, -3.0);
	Vertex3D    vertex3 = Vertex3DMake(0.2, -0.1, -3.0);
    Triangle3D  triangle = Triangle3DMake(vertex1, vertex2, vertex3);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrthof(-1.0f, 1.0f, -1.0 / (rect.size.width / rect.size.height), 1.0 / (rect.size.width / rect.size.height), 0.01, 10000.0);
	glViewport(0, 0, rect.size.width, rect.size.height); 
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0.4, 0.4, 0.4, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glClear(GL_COLOR_BUFFER_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColor4f(0.2, 0.2, 0.4, 1.0);
    glVertexPointer(3, GL_FLOAT, 0, &triangle);
    glDrawArrays(GL_TRIANGLES, 0, 9);
    glDisableClientState(GL_VERTEX_ARRAY);
	
	//Print the vertices for outer circle.
	/*for(int i = 0; i < 720; i++)
	{
		NSLog(@"Outside Vertex Array => %f",verticesOC[i]);
	}*/
	
	//Load the vertex of outer circle and draw it
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//CGRect rect = theView.bounds; 
	glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
	glViewport(0, 0, rect.size.width, rect.size.height);  
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glEnableClientState(GL_VERTEX_ARRAY);
	glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
	glVertexPointer(2, GL_FLOAT, 0, verticesOC);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 360);
	glDisableClientState(GL_VERTEX_ARRAY);
	
	//Print the vertices for inner circle.
	/*for(int i = 0; i < 720; i++)
	{
		NSLog(@"Inside Vertex Array => %f",verticesIC[i]);
	}*/	
	
	//Load the vertex of inner circle and draw it.
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
	glViewport(0, 0, rect.size.width, rect.size.height);  
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glEnableClientState(GL_VERTEX_ARRAY);
	glColor4f(0.4f, 0.4f, 0.4f, 1.0f);
	glVertexPointer(2, GL_FLOAT, 0, verticesIC);
	glDrawArrays(GL_TRIANGLE_FAN, 0, 360);
	glDisableClientState(GL_VERTEX_ARRAY);
}

Moreover, I would also like to put some animation on triangle only and not on all the objects on the same surface. How to go about that ?

Hope to get a reply soon.

I am trying to do this on iphone.

Thanks & Regards
Sunil

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.