100% Pure Brain Sugar 10¢ Contact
 
« Back from the Bing
A Riddle »

Porting a Fixed-Function Game to a Programmable Pipeline: Part 3

By Jeff | Published: June 12, 2010

Crush the Castle: iPhoneI’m porting Crush the Castle from a fixed-function, OpenGL 1 renderer to a programmable, OpenGL 2 renderer. In the last couple of posts I described how I separated my initial fixed-function renderer into three distinct classes:

  1. An abstract Renderer interface that the game itself talks to
  2. A concrete implementation of the Renderer interface that uses fixed-function OpenGL 1 (RendererGLES1)
  3. Another implementation of Renderer that uses programmable OpenGL 2 (RendererGLES2)

Today I’d like to show you what I had to do to port the fixed-function version of the renderer to use the programmable pipeline in OpenGL ES 2.0.

More Power, More Responsibility

The good news about a programmable rendering pipeline is that it offers far greater power. With a fixed-function pipeline you can only do what the API lets you do. If the API supports bump mapping, you can do bump mapping. If the API supports fog, you can apply fog. But with a programmable pipeline, your engine can render anything that you can code. You’re in total control of how every vertex and pixel is displayed.

The bad news about a programmable pipeline is that it requires a lot more work. Fixed-function pipelines do a lot for you. Call glRotate(), for example, and OpenGL will set up a rotation matrix for you and concatenate it with the existing matrix. Request that a light be applied to your models and suddenly they’re glowing with the sunset. Not so in a programmable pipeline. If you want to see sunlight, you’ve got to code it. If you want transform matrices (and believe me, you do), you’ve got to program them.

So a programmable pipeline offers more power. But it also puts more responsibility on you, the programmer.

This is even more true in OpenGL ES 2.0—the rendering API that the iPad and later iPhones/iPod Touches use. All new versions of OpenGL add support for vertex and fragment programs. But the “ES” version of OpenGL 2.0—the mobile, stripped-down version—not only adds this support, it strips out support for anything else.

This is the hardest part about moving from a fixed function renderer to a programmable renderer on the iPhone/iPad. The move to shaders takes away some of the functionality that OpenGL ES 1.0 provided.

Changes from OpenGL ES 1.0 to OpenGL ES 2.0

The biggest changes that I encountered when moving Crush the Castle from version 1 to version 2 of OpenGL ES involved how vertex attributes are sent to the hardware, the self-management of matrices, and of course, programming the actual shaders. Here’s a list of all the changes I had to make to my fixed-function renderer. A lot of these might not make sense now, but I’ll talk about them all in more detail later.

  • Implemented my own 4×4 matrix class with support for translation, rotation, scaling, and concatenation
  • Implemented my own orthographic and perspective projection math
  • Created a class to implement matrix stacks
  • Replaced occasional calls to glColor4f() (used to apply a single color to all vertices in a draw call) with a vertex program “uniform” variable
  • Got rid of glEnableClientState() calls
  • Converted gl*Pointer() calls (like glVertexPointer() and glTexCoordPointer()) to glVertexAttribPointer() calls
  • Added the loading, compiling, linking, validating, and using of vertex and fragment shaders

Some features stayed just the same.

  • Texture creation, loading, and binding
  • Alpha blending settings
  • Vertex buffer object creation with glBufferData() and the like
  • Setting the viewport with glViewport()
  • glGetError()
  • glClear(), glClearColor(), and the like
  • glDrawArrays() and glDrawElements()

Now Crush the Castle does not use every feature in OpenGL ES 1. No doubt there are many other fixed-function features that I would have needed to convert if I had been using them. So mileage may vary. But these are the ones I had to convert, and next time I’ll go into more detail about what I had to do to convert each one.

Be Sociable, Share!
  • Tweet
This entry was posted in Crush the Castle, iPhone, programming. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
« Back from the Bing
A Riddle »

2 Comments

  1. George
    Posted October 7, 2010 at 1:20 am | Permalink

    Thanks for this nice post. However I love to play multiplayer mmorpg online and haven’t used any gaming application on mobile yet. Anyways you are doing great job though. Keep it up.

    Reply
  2. Dan
    Posted May 23, 2012 at 6:24 am | Permalink

    I enjoyed this series posts. I’d be interested to see the final implementation if you’d be willing to share it!

    Reply

Post a Comment Cancel reply

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Holy Ghost Stories
Punch
by
Jeff Wofford
  • Recent Posts

    • The Video Game Industry Will Crash in 2013
    • The New Black
    • Finding C. S. Lewis’s Essays
    • What is Ethics?
    • SimCity to License Blizzard’s LocalServer™ Technology
    • When Game Development Stinks
    • An Invitation Back to Faith
    • The Four Moral Cultures
    • In Praise of Modern Board Games
    • Hitting a Dead End with FlasCC
    • My Top Ten Least Favorite Ethical Arguments
    • Suitors: A new, free card game for 2 to 4 players
    • The Sorry State of C++ Portability
    • The Sorry State of Game Portability
    • Come Play House of Shadows!
    • Elvis in Wonderland: An Example Game Pitch Document
    • I Cannot Read on My iPad
    • The Final Solution to the Travelling Salesman Problem
    • Angry Birds “Cloned” Crush the Castle, and That’s Okay
    • How Diablo 3′s Networked Standalone Campaign Secures the Auction House
  • Recent Comments

    • BenTennyson on How to Get Your Game Idea Made into a Game
    • Jeff on The Video Game Industry Will Crash in 2013
    • Jimbo on The Video Game Industry Will Crash in 2013
    • The Founder on How to Get Your Game Idea Made into a Game
    • Paul Liddell on How to Get Your Game Idea Made into a Game
  • Categories

    • blogging (3)
    • books (13)
    • culture (8)
    • employment (3)
    • ethics (6)
    • faith (35)
      • Bible (3)
    • family (7)
    • fiction (6)
    • games (53)
      • board games (2)
      • Crush the Castle (6)
      • House of Shadows (1)
    • iPhone (14)
    • language (1)
    • Mac (4)
    • music (4)
    • Phit (6)
    • politics (5)
    • productivity (8)
    • programming (35)
    • science (2)
    • technology (30)
    • thinking (13)
    • Uncategorized (7)
    • writing (15)
  • Archives

    • May 2013 (2)
    • April 2013 (1)
    • March 2013 (3)
    • January 2013 (4)
    • December 2012 (1)
    • November 2012 (1)
    • October 2012 (3)
    • August 2012 (1)
    • July 2012 (1)
    • June 2012 (4)
    • May 2012 (3)
    • April 2012 (2)
    • March 2012 (3)
    • October 2011 (7)
    • September 2011 (3)
    • August 2011 (3)
    • July 2011 (2)
    • May 2011 (1)
    • January 2011 (2)
    • June 2010 (4)
    • May 2010 (2)
    • April 2010 (1)
    • February 2010 (1)
    • January 2010 (3)
    • December 2009 (8)
    • November 2009 (2)
    • October 2009 (2)
    • September 2009 (1)
    • June 2009 (10)
    • May 2009 (5)
    • January 2009 (1)
    • December 2008 (2)
    • November 2008 (3)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (1)
    • July 2008 (1)
    • June 2008 (2)
    • May 2008 (8)
    • April 2008 (3)
    • November 2007 (1)
    • October 2007 (2)
    • August 2007 (5)
    • July 2007 (4)
    • June 2007 (8)
    • March 2007 (1)
    • November 2006 (3)
    • April 2006 (1)
    • March 2006 (1)
  • RSS Links

    • All posts
    • All comments
  • Meta

    • Log in
Copyright © 2013 Jeff Wofford. All rights reserved. Powered by WordPress. Built on the Thematic Theme Framework.