any tips for making CG render faster?

Member
Posts: 60
Joined: 2009.06
Post: #1
I am working on a simple 2D game with minimal animation. Basically I am drawing circles and triangle sin my window. It is much slower on iPod touch 1G than in the simulator. I am drawing only the portions of the screen that are changing. But it is very slow! My animated object moves very slow. There are two objects which move, one is animated by the acceleormeter and that seems to be responsive. the other one, a small circle, is a ball that just bounces around. that is moving way slower than in the simulator. I'm afraid that will make the gameplay experience different between 1G and 3G and 3GS because of the different speed of the game.

I have a timer which should take care of the issue but like I said, it moves way slower on the device than in the simulator.
Any ideas accepted.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
Definitely should look into using OpenGL Wink

Performance between simulator and device is *wildly* different. The simulator is all software simulation and not at all representative in any way of the performance you will see on any device.
Quote this message in a reply
Member
Posts: 60
Joined: 2009.06
Post: #3
but OpenGL is...hard! Sad
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
OpenGL isn't hard. *Learning* OpenGL can be hard, yes. The learning curve is notoriously steep at first.

Check out:
http://www.71squared.com/iphone-tutorials/
http://www.qooglesearch.com/?source=rmac.../index.php

Basically, for a 2D game with two sprites, in a ridiculously high-level view of things, it boils down to:
Code:
init
    setup OpenGL context (takes a few lines of copy-paste)
    load yer textures (copy-paste a function to do it)

drawFrame

    // setup for frame (takes a few lines)
    clear the frame buffer
    setup yer viewport and projection
    switch to modelview matrix
    clear the matrix to start with a clean slate
    
    // setup the state you want for drawing (takes a few more lines)
    turn on texturing
    enable vertex array
    set generic sprite vertices pointer
    enable texture coordinates
    set generic texture coords pointer
    enable blending
    set blend function
    disable depth testing (optional)
    disable lighting (optional)
    disable fog (optional)
    etc... (optional)
    set color
    
    // draw sprite 1
    set the texture you want to use
    pushmatrix
        translate (optional)
        rotate (optional)
        scale (optional)
        draw yer sprite
    popmatrix
    
    // draw sprite 2
    set the texture you want to use
    pushmatrix
        translate (optional)
        rotate (optional)
        scale (optional)
        draw yer next sprite
    popmatrix
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
Not as hard as you might think, and the payoff is pretty huge once you learn to use it. I'd recommend buying this book (an old version of which is freely available in HTML), and using Xcode's OpenGL ES application template as a starting point when you run through the examples in the book. It's well worth the effort.
Quote this message in a reply
Member
Posts: 60
Joined: 2009.06
Post: #6
thanks for the tips...I should have been more clear and say "integrating OpenGL ES with your app once you have most of the coding done" is hard.
I used Glut in C++ and was able to draw stuff easily. But for the iPhone....first I couldn't get the appropriate libraries, then....is there a way to put all this in your view? Like, can I just replace the CG commands with OpenGL functions?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #7
aerospaceman Wrote:is there a way to put all this in your view? Like, can I just replace the CG commands with OpenGL functions?

More or less. It won't be quite as straightforward as replacing CG commands with GL commands, but shouldn't require you to drastically rearchitect your app either. Again, take a look at the OpenGL ES template in Xcode by creating a blank project from it; it's a fantastic reference for bootstrapping a iPhone OpenGL app. You can ignore/disable the ES2 stuff if you don't want to deal with it (which you almost certainly wouldn't need to at this point).
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #8
It sounds like your problem might not be the graphics. Are your animations and velocities independent of the frame rate? Even though the frame rate will be much lower on the 1g vs 3g the game experience and feel should be almost the same. Also how are you only redrawing a portion of the screen? This may be the problem.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Wave tips 2d water chrisevans1001 1 2,829 Dec 9, 2011 04:12 PM
Last Post: OneSadCookie
  I'm sure it could be faster... MikeD 14 4,568 Apr 23, 2009 08:23 AM
Last Post: warmi
  iPhone filming tips BeyondCloister 11 6,044 Apr 21, 2009 02:36 AM
Last Post: monteboyd
  2nd Generation iPod Touch Faster than iPhone PowerMacX 0 2,111 Nov 23, 2008 10:08 AM
Last Post: PowerMacX