Drawing lots of things.

So I'm new to android development and Ouya development as well, but well acquainted to Java.

I've made a simple game that randomly generates a level with ~200 different objects. Each one draws a rectangle to the canvas. Unfortunately, when that number of objects (200) exceeds around 70, the framerate starts to drop. At 200 objects, it drops by about 12 frames. I also tried drawing half of them as a bitmap, and framerate dropped to 5fps.

So my question - is this generally a problem on Android and should I try to learn OpenGL, or is it possible to fix this without jumping into OpenGL?

Comments

  • PuzzlPuzzl Posts: 98Member
    Hi HiroLord, there are many engines/wrappers around leveraging OpenGL. You don't need to learn OpenGL, just leverage it.
  • HiroLordHiroLord Posts: 54Member
    Should Android be able to handle drawing around 200 rectangles on screen though? Or is drawing that much a problem?
  • Killa_MaakiKilla_Maaki Posts: 504Member
    Drawing in Android is not at all optimized for realtime gaming - it's meant for mostly static GUIs.
    You'll want to look into switching to OpenGL - it will be WAY faster.
    You didn't remember the plot of the Doctor Who movie because there was none; Just a bunch of plot holes strung together.
  • SpoonThumbSpoonThumb Posts: 426Member
    As Killa_Maaki says, the android drawing system is really designed such that things are drawn once and then not redrawn unless they change or really have to be redrawn. That's fine for apps, where you have textview and imageview widgets that don't really move around, but it really does not work so well for games

    I wrote my own engine in android using OpenGL, and it can handle about 10k triangles before performance starts to drop. It dips below 30fps around 20k triangles. I would recommend using a pre-existing engine though. There are a number build on top of android, or written in java, such as LibGDX, that might be just what you're after
  • HiroLordHiroLord Posts: 54Member
    I've decided I do want to start learning OpenGL, the problem is that I can't find ANY decent tutorials online that work with OpenGL 2. Any that are halfway decent are using 1.x. Does anyone have any suggestions about where to start?
  • ShushShush Posts: 178Member
    The first thing you need to know is that OpenGL ES 2.0 uses shaders for just about everything, OpenGL ES 1.1 uses the fixed function pipeline, (i.e. dedicated hardware found on old or weak GPU architectures), to do all of their Transform and Lighting. (*Note* OpenGL 2 is not the same thing as OpenGL ES 2.0, make sure you get your terminology right when searching).

    What this means for you, is that you need to learn about shaders, OpenGL ES 2.0 only supports Vertex Shaders and Fragment Shaders; you can think of it like this, Vertex Shaders do the Transformation of Vertices from Model/World space to View/Screen space and Fragment Shaders do the Lighting of the Screen space pixels covered by the primitives represented by your on Screen Vertices, (hence the term Transform and Lighting). In reality it's not as clear cut and dry as that, as different parts of the rendering pipeline can be shuffled around, but it's a good place to start.

    The other thing you need to decide is whether you're going to implement OpenGL ES 2.0 in Java or using Native code, (C++), the links I have provided for you are mainly Java although I personally do everything in C++ for performance. Some of these links are also API/Architecture specific, but don't worry about that, the Shader specific bits is what makes them useful.

    http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
    http://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf
    http://glslstudio.com/primer/
    http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/
    http://www.raywenderlich.com/10862/how-to-create-cool-effects-with-custom-shaders-in-opengl-es-2-0-and-cocos2d-2-x
    http://www.raywenderlich.com/3664/opengl-es-2-0-for-iphone-tutorial
Sign In or Register to comment.