Jump to content

  • Log In with Google      Sign In   
  • Create Account


glOrtho not working?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 blueshogun96   Crossbones+   -  Reputation: 674

Like
0Likes
Like

Posted 09 February 2013 - 07:31 PM

I started writing a totally new OpenGL  game for iOS a few days ago, and I cannot get 2D working to save my life.  3D works fine (using a customized implementation of gluPerspective), but 2D just won't.  I've done a 2D game for iOS before, and I didn't have any problems.  Now, no matter what I do, nothing renders.

 

My code:

 

Initialization:

// 2. Create a Context
    EAGLContext *context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1] autorelease];
    [EAGLContext setCurrentContext:context];
    
    // 3. Create a View
    GLView *glView = [[[GLView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
    [self.view addSubview:glView];
    
    // 4. Create a Renderbuffer
    GLuint renderbuffer;
    glGenRenderbuffers(1, &renderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)glView.layer];
    
    // 5. Create a Framebuffer
    GLuint framebuffer;
    glGenFramebuffers(1, &framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 320, 480 );
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
    
    GLuint depthBuffer;
    glGenRenderbuffers( 1, &depthBuffer );
    glBindRenderbuffer( GL_RENDERBUFFER, depthBuffer );
    glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 320, 480 );
    glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer );
    
    glBindRenderbuffer( GL_RENDERBUFFER, renderbuffer );
    
    GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
    if( status != GL_FRAMEBUFFER_COMPLETE )
    {
        NSLog( @"Error completing FBO! %x", status );
    }
    
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    glClearDepthf( 1.0f );
    
    glDisable( GL_CULL_FACE );
    glDisable( GL_LIGHT0 );

 

 

Rendering:

-(void) drawView:(id)sender
{
    glViewport( 0, 0, 320, 480 );
    glMatrixMode( GL_PROJECTION );
    glOrthof( 0, 320, 0, 480, -1, 1);
    
    glClearColor( 0.0f, 0.5f, 0.0f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
  
    draw_quad( 0, 50, 50, 300, 300 );
    
    [[EAGLContext currentContext] presentRenderbuffer:GL_RENDERBUFFER];
}

void draw_quad( GLuint texture, float x, float y, float w, float h )
{
	float vertices[] = { x, y, x+w, y, x+w, y+h, x, y+h };
	float tex[] = { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };

	glBindTexture( GL_TEXTURE_2D, texture );

	glTexCoordPointer( 2, GL_FLOAT, 0, tex );
	glVertexPointer( 2, GL_FLOAT, sizeof(float)*2, vertices );
	glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );

	spf++;
}

 

Majority of this code I'm reusing, but I don't see what the problem is.  Arrgh, iOS is a complete NIGHTMARE to work with (problems at every corner for me).  I hate to say it, but PS2 was more straight forward than iOS.  This really sucks.  Any ideas?  Thanks.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 9732

Like
0Likes
Like

Posted 09 February 2013 - 10:11 PM

OpenGL/OpenGL ES are the pain, not iOS.  Bind-to-modify is a design flaw from the early 90’s that they have refused to fix for compatibility reasons.

Your own headaches are compounded by the fact that you are using OpenGL ES 1.0 instead of OpenGL ES 2.0.  Learning how to handle OpenGL’s quirks, such as modifying your lighting system to deal with the fact that they modify the lights you set by the current model-view matrix, and only once (sigh), is a lot harder than learning shaders.  No joke.

 

Anyway, firstly you need to disable lighting.  You didn’t call ::glDisable( GL_LIGHTING ).

 

Secondly, you should be glad you are on iOS because there is a large toolset to help you debug this.

Firstly, only code using a real device.  This is a simple fact of life.

Secondly, once you are on a real device, you can take a screenshot and step through to see what is happening.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 blueshogun96   Crossbones+   -  Reputation: 674

Like
0Likes
Like

Posted 10 February 2013 - 10:05 AM

OpenGL/OpenGL ES are the pain, not iOS.  Bind-to-modify is a design flaw from the early 90’s that they have refused to fix for compatibility reasons.

Your own headaches are compounded by the fact that you are using OpenGL ES 1.0 instead of OpenGL ES 2.0.  Learning how to handle OpenGL’s quirks, such as modifying your lighting system to deal with the fact that they modify the lights you set by the current model-view matrix, and only once (sigh), is a lot harder than learning shaders.  No joke.

 

Anyway, firstly you need to disable lighting.  You didn’t call ::glDisable( GL_LIGHTING ).

 

Secondly, you should be glad you are on iOS because there is a large toolset to help you debug this.

Firstly, only code using a real device.  This is a simple fact of life.

Secondly, once you are on a real device, you can take a screenshot and step through to see what is happening.

 

 

L. Spiro

I beg to differ.  I've never had any serious problems out of OpenGL until I started on iOS.  I'm using OpenGL ES 1.1 simply because I don't have an OpenGL ES 2.0 compatible iOS device (can't afford one atm).  I tried disabling lighting with glDisable( GL_LIGHTING ); still doesn't work.  Even when I got 3D working, it didn't make a difference.  And whether I use a real device or the simulator, I get the same results.  I still don't see what I'm doing wrong here.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#4 L. Spiro   Crossbones+   -  Reputation: 9732

Like
1Likes
Like

Posted 11 February 2013 - 07:18 PM

The same code on any other device will yield the same results.  The problem is your code, not iOS.

And I told you to use a real device for debugging purposes.

I told you to Capture an OpenGL ES Frame.

As in, run the project on a real device, go to Xcode, select Product->Debug->Capture OpenGL ES Frame.

Now you can single-step through every OpenGL ES call, or just the render calls, and see everything about the context and look for what could be wrong.

 

Look:

frame_capture.png

 

You should count your blessings that you are on iOS.  There is no such feature on Android™.

If you can’t figure it out on your own after doing this, go to the draw call that you think should be drawing a quad and post a screenshot.

 

 

L. Spiro


Edited by L. Spiro, 11 February 2013 - 07:20 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 blueshogun96   Crossbones+   -  Reputation: 674

Like
0Likes
Like

Posted 14 February 2013 - 07:30 PM

Oh, wow, I didn't know you could do that!  Thanks, I'll try that right away.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#6 mhagain   Crossbones+   -  Reputation: 6354

Like
0Likes
Like

Posted 14 February 2013 - 08:02 PM

Here's your problem:

 

    glMatrixMode( GL_PROJECTION );
    glOrthof( 0, 320, 0, 480, -1, 1);

 

glOrtho doesn't load the generated ortho matrix onto the stack; what it does is take the current matrix and multiplies it by the generated ortho matrix (http://www.khronos.org/opengles/sdk/1.1/docs/man/).  So instead you do:

 

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity ()
    glOrthof( 0, 320, 0, 480, -1, 1);

 

And it works!


Edited by mhagain, 14 February 2013 - 08:02 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 blueshogun96   Crossbones+   -  Reputation: 674

Like
0Likes
Like

Posted 14 February 2013 - 08:49 PM

This functionality isn't supported on my iPod 1st Generation... =(


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#8 blueshogun96   Crossbones+   -  Reputation: 674

Like
0Likes
Like

Posted 14 February 2013 - 08:53 PM

mhagain, tried it.  Still isn't working. =(


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS