Flixel Forums

development => iOS => Topic started by: Dids on Tue, Apr 17, 2012

Title: iPad 3 & Texturebuffer Zooming
Post by: Dids on Tue, Apr 17, 2012
As it stands, flixel-ios doesn't support the new iPad (3), as the previously working iPad solution has been to double the texturebuffer(s), but with the release of the new iPad, that texturebuffer would have to be quadrupled.

Has anyone succeeded in this yet?
Title: Re: iPad 3 & Texturebuffer Zooming
Post by: Dids on Wed, Apr 18, 2012
Well I'll be damned, I actually got it to display correctly (as in, identical to the iPad 1/2 version).

Only thing still screwed up is the touch input.
Title: Re: iPad 3 & Texturebuffer Zooming
Post by: Dids on Wed, Apr 18, 2012
And input's fixed!

For future reference, here's a small how to. You'll have to modify two files, FlxGame.m and FlxTouches.m. Granted, I could've snipped away most of it, but the reason I included entire blocks was so that it's easier to find the parts that you need to modify.

1. Enable textureBufferZoom for when both FlxG.iPad and FlxG.retinaDisplay return true
2. Open up FlxGame.m and search for textureBufferZoom and do the following changes

(these are the modified versions, but shouldn't take long to find & replace)

Code: [Select]
//which way are we oriented?
        if (textureBufferZoom) {
if (FlxG.iPad && FlxG.retinaDisplay)
{
if (gameOrientation == FlxGameOrientationPortrait)
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.width/2/_zoom)
                               height:(int)(glView.bounds.size.height/2/_zoom)
                                 zoom:Zoom];
                else
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.height/2/_zoom)
                               height:(int)(glView.bounds.size.width/2/_zoom)
                                 zoom:Zoom];
}
            else if (!FlxG.iPad && FlxG.retinaDisplay) {
                if (gameOrientation == FlxGameOrientationPortrait)
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.width/_zoom)
                               height:(int)(glView.bounds.size.height/_zoom)
                                 zoom:Zoom];
                else
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.height/_zoom)
                               height:(int)(glView.bounds.size.width/_zoom)
                                 zoom:Zoom];
            } else {
                if (gameOrientation == FlxGameOrientationPortrait)
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.width/_zoom/2)
                               height:(int)(glView.bounds.size.height/_zoom/2)
                                 zoom:Zoom];
                else
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.height/_zoom/2)
                               height:(int)(glView.bounds.size.width/_zoom/2)
                                 zoom:Zoom];
            }
        } else {
            if (FlxG.retinaDisplay && !FlxG.iPad) {
                if (gameOrientation == FlxGameOrientationPortrait)
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.width)
                               height:(int)(glView.bounds.size.height)
                                 zoom:Zoom];
                else
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.height)
                               height:(int)(glView.bounds.size.width)
                                 zoom:Zoom];
            } else {
                if (gameOrientation == FlxGameOrientationPortrait)
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.width/_zoom)
                               height:(int)(glView.bounds.size.height/_zoom)
                                 zoom:Zoom];
                else
                    [FlxG setGameData:self
                                width:(int)(glView.bounds.size.height/_zoom)
                               height:(int)(glView.bounds.size.width/_zoom)
                                 zoom:Zoom];
            }       
        }   

Code: [Select]
//redundant on iphone (not ipad), since we only bind one framebuffer
    if (textureBufferZoom) {
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

if (FlxG.iPad && FlxG.retinaDisplay)
glOrthof(0, backingHeight/4, backingWidth/4, 0, -1, 1);
else
glOrthof(0, backingHeight/2, backingWidth/2, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        //flip and shift...
        glScalef(-1.0, 1.0, 1.0);

if (FlxG.iPad && FlxG.retinaDisplay)
glTranslatef(-backingHeight/4, 0, 0);
else
glTranslatef(-backingHeight/2, 0, 0);
    }

Code: [Select]
if (textureBufferZoom && FlxG.iPad && FlxG.retinaDisplay)
{
glDisable(GL_BLEND);
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, frameBuffer);
        glPushMatrix();
       
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrthof(0, backingWidth/2, backingHeight/2, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
       
        glViewport(0, 0, backingWidth, backingHeight);
       
        switch (gameOrientation) {
            case FlxGameOrientationPortrait:
                glTranslatef(backingWidth/2/2, backingHeight/2/2, 0);
                glRotatef(actualAngle, 0, 0, 1);
                glTranslatef(-backingWidth/2/2, -backingHeight/2/2, 0);
                break;
            default:
            case FlxGameOrientationLandscape:
                glTranslatef(backingWidth/2/2, backingHeight/2/2, 0);
                glRotatef(-90+actualAngle, 0, 0, 1);
                glTranslatef(-backingHeight/2/2, -backingWidth/2/2, 0);
                break;
        }
       
        glTranslatef(FlxG.quake.x*2, FlxG.quake.y*2, 0);
       
        glClear(GL_COLOR_BUFFER_BIT);
       
        [FlxObject unbind];
       
        //     glDisableClientState(GL_COLOR_ARRAY);
        //     glEnableClientState(GL_VERTEX_ARRAY);
        //     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glBindTexture(GL_TEXTURE_2D, renderTexture);
        glVertexPointer(2, GL_SHORT, 4*sizeof(GLshort), &renderVerticesUVs[0]);
        glTexCoordPointer(2, GL_SHORT, 4*sizeof(GLshort), &renderVerticesUVs[2]);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
       
        //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glBindTexture(GL_TEXTURE_2D, 0);
        glEnableClientState(GL_COLOR_ARRAY);
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, blackColors);
        glVertexPointer(2, GL_SHORT, sizeof(GLshort)*2, blackVertices);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
        glDisableClientState(GL_COLOR_ARRAY);
       
        //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glPopMatrix();
       
        glEnable(GL_BLEND);
}
    else if (textureBufferZoom) {
        glDisable(GL_BLEND);
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, frameBuffer);
        glPushMatrix();
       
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrthof(0, backingWidth/2, backingHeight/2, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
       
        glViewport(0, 0, backingWidth, backingHeight);
       
        switch (gameOrientation) {
            case FlxGameOrientationPortrait:
                glTranslatef(backingWidth/2/2, backingHeight/2/2, 0);
                glRotatef(actualAngle, 0, 0, 1);
                glTranslatef(-backingWidth/2/2, -backingHeight/2/2, 0);
                break;
            default:
            case FlxGameOrientationLandscape:
                glTranslatef(backingWidth/2/2, backingHeight/2/2, 0);
                glRotatef(-90+actualAngle, 0, 0, 1);
                glTranslatef(-backingHeight/2/2, -backingWidth/2/2, 0);
                break;
        }
       
        glTranslatef(FlxG.quake.x*2, FlxG.quake.y*2, 0);
       
        glClear(GL_COLOR_BUFFER_BIT);
       
        [FlxObject unbind];
       
        //     glDisableClientState(GL_COLOR_ARRAY);
        //     glEnableClientState(GL_VERTEX_ARRAY);
        //     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glBindTexture(GL_TEXTURE_2D, renderTexture);
        glVertexPointer(2, GL_SHORT, 4*sizeof(GLshort), &renderVerticesUVs[0]);
        glTexCoordPointer(2, GL_SHORT, 4*sizeof(GLshort), &renderVerticesUVs[2]);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
       
        //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glBindTexture(GL_TEXTURE_2D, 0);
        glEnableClientState(GL_COLOR_ARRAY);
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, blackColors);
        glVertexPointer(2, GL_SHORT, sizeof(GLshort)*2, blackVertices);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
        glDisableClientState(GL_COLOR_ARRAY);
       
        //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
        glPopMatrix();
       
        glEnable(GL_BLEND);
    }

And finally in FlxTouches
Code: [Select]
if (FlxG.game.textureBufferZoom)
  {
  if (FlxG.iPad && FlxG.retinaDisplay)
  {
  p.x /= 4;
  p.y /= 4;
  }
  else
  {
  p.x /= 2;
  p.y /= 2;
  }
}
  return p;
Title: Re: iPad 3 & Texturebuffer Zooming
Post by: test84 on Wed, Apr 18, 2012
Nice. May I ask what was base of your flixel code? Did you port flixel yourself or it was Canabalt's or what?
Title: Re: iPad 3 & Texturebuffer Zooming
Post by: Dids on Wed, Apr 18, 2012
It's based on the original (and old) flixel-ios code on Github. Since then, I've had to modify it quite a bit to support Game Center (there's still orientation issues) and to fix all of the warnings.
Title: Re: iPad 3 & Texturebuffer Zooming
Post by: initials on Wed, Apr 18, 2012
Thanks for posting this.