Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-03-2011, 03:20 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 59
kend0g187 is on a distinguished road
Default openGL ES how to get perspective view?

I'm trying to draw a simple cube, rotated 45 deg about y-axis. My drawing code looks like this:

Code:
- (void) Draw:
{
	// Set the viewport
	//glFrustumf( -1.0, 1.0, -1.0/(backingWidth/backingHeight), 1.0/(backingWidth/backingHeight), 0.01, 10.0 );
	glViewport ( 0, 0, backingWidth, backingHeight );
	
	// Clear the color buffer
	glClear ( GL_COLOR_BUFFER_BIT );
	
	if( [context API] == kEAGLRenderingAPIOpenGLES2 )
		[self DrawES2];
	else 
		[self DrawES1];
	
	glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(GLubyte), GL_UNSIGNED_BYTE, indices);
}
	
- (void) DrawES2
{	
	// Use the program object
	glUseProgram ( programObject );
	
	// Load the vertex data
	glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
	glEnableVertexAttribArray ( 0 );
	
	// Load transformation matrix
	GLint mvpLoc = glGetUniformLocation( programObject, "u_mvpMatrix" );
	glUniformMatrix4fv( mvpLoc, 1, GL_FALSE, yRotation );
}

- (void) DrawES1
{	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glRotatef( 45, 0, 1, 0 );
	
	glVertexPointer(3, GL_FLOAT, 0, vVertices);
	glEnableClientState(GL_VERTEX_ARRAY);
	glColor4f(1.0, 0.0, 0.0, 1.0);
}
What I get is something like this:

What I want is something like this:


When I uncomment the glFrustum line I get no change in ES1 version and app crashes in ES2 version. I'm new to OpenGL so I guess I could be doing something really wrong, but how do I get a perspective view so that the cube looks right?
kend0g187 is offline   Reply With Quote
Reply

Bookmarks

Tags
glfrustum, glfrustumf, opengl, perspective

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 370
12 members and 358 guests
condor304, dansparrow, dre, ilmman, LezB44, michelle, Objective Zero, samdanielblr, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:40 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0