Is there a way to decide up front based on the expected complexity of a game/app in the planning phase whether to use regular Canvas drawing in a SurfaceView or to go with OpenGL?
I've been playing around with a Canvas and only need 2D movement, and on a fairly new phone I'm getting pretty decent performance with a bunch of primitive objects and a few bitmaps running around the screen on a solid background.
Is it fair to say that if I'm going to be drawing background images and increasing the number of objects being moved and drawn on top of them that I should go straight to OpenGL?
All I can say is that it depends on how many sprites you're gonna use. Chris Pruett from Google has also documented this part very well.
Google I/O 2009 and Google I/O 2010.
Below is a picture from one of his slides that are related to your topic:
With that knowledge, you should go with OpenGL using the draw_texture extension. Remember to query out the string and check if draw_texture is supported on the actual device.
For further information that are related to game development in general, see this.
SurfaceView
A GLSurfaceView is a SurfaceView that you can render into with OpenGL.
Choosing between them is simple:
If you're familiar with OpenGL and need what it provides, use a
GLSurfaceView. Otherwise, use a SurfaceView. OpenGL is low-level. If
you're not already familiar with it, it's an undertaking to learn. If
you only need 2D drawing, SurfaceView uses the high-level, reasonably
high-performance Canvas. It's very easy to work with.
Unless you have a strong reason to use a GLSurfaceView, you should use
a regular SurfaceView. I would suggest that if you don't already know
that you need GL, then you probably don't.
OpenGL
OpenGL would be able to handle the rotations and scaling easily.
Honestly, you would probably need to learn a lot of OpenGL to do this,
specifically related to the topics of:
Geometry Lighting (or just disabling it) Picking (selecting geometry
to draw on it) Pixel Maps Texture Mapping Mipmapping Also, learning
OpenGL for this might be overkill, and you would have to be pretty
good at it to make it efficient.
Instead, I would recommend using the graphic components of a game
library built on top of openGL, such as:
Cocos2d
libgdx
Any of the engines listed here
Source
Difference between SurfaceView and GLSurfaceView in Android
Android: Canvas vs OpenGL
Related
I have done some reading on OpenGl ES for Android. I know that I could make a game with the canvas API, but I would like to experiment with OpenGl ES first.
From here I can see two options: Use a game engine or develop my OpenGl ES from the ground up.
The coder/math person that I am is pushing me to the harder option(second option). The way I want to start on this journey is by creating a mesh and manipulating it with various transformations. I will worry about the textures later on. I've learned that I could develop my mesh using outside software such as Blender or LibGdx. However, I would like to learn to develop it with the android API. Do you think this is possible? Will it be very taxing for the android system to process many meshes and transform them? I think It will.
Should I just stick to the game engine way, and forget the "from the ground up mindset".
I also just found out about the replica island source code. Perhaps, I should start reading it and tweaking it on my own.
One more thing, from what I see, I have several options when developing graphics on android using OpenGl ES. Create the 3D model meshes or use sprites(such as replica island). Are there any other ways of doing this?
It all depends on the complexity of the game.
If it's on the simpler side, you could very well 'start from scratch'. I'm pretty sure, you'll end up creating something similar to replica island. For a complex game, you'll be near (as we're from moon) unity on the other extreme. We're talking about hundreds of thousands of man-hours.
As far as creating the meshes is concerned, OpenGL(ES) can only render the meshes.
Unless it's a very primitive mesh or one which can be modelled mathematically with a few equations (less likely for a game), you'll have to create them in blender, maya etc.
For a first timer, I suggest reusing an existing game/engine.
The transition from rendering meshes, then applying textures, then using lighting and shadows etc has a decent learning curve.
Trust me, even with this approach the coder/Math person will have enough on his plate.
I want to make a "2d game" using graphics from the ressources for the characters.
Now I'm asking myself what is the best solution.
I was searching a lot in the net finding the two different options.
A) Creating a custom view, adding it to the layout showing a AnimationDrawable or
B) Using the SurfaceView directly painting on it
Whereas a) is usually called slow and unperformant for games I tried to find a solution for b).
But so far all tutorials are only made with one image moving around on the surfaceView or animating geometric shapes (which isn't really what I had in mind).
Finding tutorials for "how to draw AnimationDrawable on SurfaceView" are very rare.
So I thought I might load all animation frames of my character into an array drawing each call the right one on the SurfaceView. But that sounds like a lot of overhead to me. Should I abandon the SurfaceView?
Has anyone a good idea what would be the best way to animate - lets say 10 characters + "background" on my screen?
You have (at least) three options:
Draw on SurfaceView surface with a Canvas. This will use software rendering and be relatively slow.
Instead of a SurfaceView, draw on a custom View with a Canvas. This will be hardware accelerated, with some limitations.
Draw on SurfaceView surface with OpenGL ES. This will be hardware accelerated, but you have to figure out how GLES works.
You should also consider (4) use an open-source 2D game engine and don't worry about what it's actually doing.
If you want an example, Android Breakout is a simple but complete 2D game written for GLES and GLSurfaceView. A more evolved set of EGL/GLES helpers can be found in Grafika, which uses GLSurfaceView, SurfaceView, and TextureView to accomplish various things. It also demonstrates the use of the hardware scaler to improve efficiency on larger displays.
Long description of the Android graphics architecture is available here.
Okay, I'm not sure this is the best option but I found a tutorial for using "Sprite Sheets".
http://www.edu4java.com/en/androidgame/androidgame4.html
So far this seems to be a good solution. OpenGL seemed a bit too much to me but perhaps I'm not good at Shader Language etc.
So if anyone finds a better solution, please let me know.
I'm developing a client for LBS service and I need to implement some 2D and 3D graphics.
As I read, standard package android.graphics is better for 2D grahics and drawing simple objects, and opengl es is better for 3D and it works faster. Unfortunatelly, I did'n find anything alse about their differences. Does anybody konow more about differences between drawing with OpenGL ES and with android.graphics?
OpenGL will give you full control over the graphics that you are using. You will not have many limitations long term on what you would like to do. You can make a good 3D game on an Android using OpenGL, as you can render large amounts of polys and overlay 2D graphics on top of those. It is a great deal of work, though.
Regular old OpenGL is my favorite, and I'd hate to have to use any of the frameworks mentioned in other answers, but I've been working with 3D graphics for many years. I can see why others would recommend them.
If you haven't done 3D graphics before, you have a steep learning curve in front of you. If you don't take the time to learn the underlying math and rendering concepts, you will struggle with it long term.
I love the reference pages from Khronos
Also, the Android developer site has some nice reference.
The main difference is that OpenGL is much faster compared to Canvas (The Android 2D graphics drawing surface). Although hardware acceleration is enabled for Canvas since honeycomb, it is a bit tricky to use it effectively.
Canvas does make life easier though. It's easy to use and simple to understand even for someone new to Computer Graphics.
In the end it will depend on what you need to do. If you need the fancy stuff like Geometry, Lighting etc then you should definitely go for OpenGL. Besides, If you need 3D then OpenGL is your only option since Canvas only supports 2D graphics.
Bare bones OpenGL is very tedious to use in my opinion so I would suggest a framework such as the ones mentioned here.
Hope this helps.
I am planning to make an android game. The game doesn't include a lot of movement. It will be like custom maps that user can switch between, maybe zoom in and out, select parts of the land, draw some objects on the map. User should also have a dashboard to manage his game . It will NOT include objects moving like cars/people.
I am new to both Canvas and OpenGL-ES developing but i feel that OpenGL-ES includes a lot more that what i need.. but just little skeptic if Canvas would be good enough to fulfill my requirements.
So, what would you advise me to do?
Thanks in advance.
Adel
I would say it's a difficult one to answer as it's virtually impossible for anyone but yourself (as the game designer) to know which one your particular game would require.
However, I would say, personally, I would go with openGL ES 2.0. I spent months designing a game (and even longer writing it) only to find that canvas wasn't powerful enough. Granted it did have 'moving objects' but not a huge amount of them - and it ended up with a lot of jerky movement that I just couldn't eliminate, so I am in the process of re-coding it with openGL ES 2.0.
I would say, look at some examples of games written with Canvas / Surfaceview and judge to the best of your ability which one you think you should go with.
Bear in mind while making this decision, that if you think Canvas / Surfaceview would be good enough, then go for it, however even if it is, are you going to be creating more demanding games later down the line? If so, then like I said above, I would just jump straight into openGL ES 2.0.
Canvas = simpler coding, worse performance
Open GL ES 2.0 = more demanding coding, but potential for much better performance.
Just my opinion!
I'm currently playing around with 2D graphics in android and have been using a plain old SurfaceView to draw Drawables and Bitmaps to the screen. This has been working alright, but there's a little stutter in the sprite movement, and I'm wondering the feasibility to do a real time (but not terrible fast) game with this.
I know GLSurfaceView exists which uses OpenGL, but I'm curious as to the extent to which this makes a difference. Is a plain SurfaceView hardware accelerated, or do I need to use OpenGL? What type of speed difference could I expect from switching to OpenGL, and how much altering of code would it require to switch (the game logic is all in a separate object that provides an ordered array of drawables to the SurfaceView)?
As far as I can tell, you have to use openGL to get HW acceleration. But don't take is for granted and wait for other answers ^^
If it really is the case, the speedup should be quite important. Any 2D application should work at at very least 20 fps (generally less polygons than 3D applications)
it would take a substantial amount of code, but 1) as a first attempt, you could try with only 1 square VBO and change the matrix each time and 2) your rendering seems already quite encapsulated so it should simplify things a lot.
SurfaceView is not hardware accelerated in default.
if you want to get HW acceleration
use GLSurfaceView, which use opengl and is hardware accelerated.
Hardware acceleration is possible for a regular SurfaceView since 3.0.
http://developer.android.com/guide/topics/graphics/hardware-accel.html