Draw map of building on runtime in Android - Canvas or OpenGL? - android

I'm actually implementing a View, which has to draw a floor-plan of a building. I just want to show one floor at the same time but I already got performance issues.
Every floor has x-polygons, which consist out of y-points/edges. I want to draw every point and every edge on my map. In some cases, there are up to 600 points so the drawing takes a lot of time in Canvas.
Is it better to switch to OpenGL? (I don't need any texture, just polygons).

I would say go for OpenGL ES 2.0 if you can't use 2.0 then go for 1.0.
Canvas
Less Code (and more basic and simple programming)
Though Worse Performance
OpenGL ES
More Code
Usually better performance (The more polygons there are, the easier it will be to see that OpenGL ES gives a better performance)
So if we're talking about a small amount of polygons, then Canvas could be able to handle it while still giving a good FPS.
Though be aware that using OpenGL, will require some more "thinking" if you can say it like that. Basically, you need to think about which vertices you want to pack together into VBOs, then less draw calls you have the even better FPS you will get. You also need to know some Matrix and Vector math, probably don't 100% need to, but a lot of thing will get a lot more easier if you do know it.

Related

What is the recommended way to shrink/stretch shapes in Android + OpenGL ES 2.0?

I've been having fun with Android and OpenGL in a little side project meant to learn about it, but now I want to implement some animations and I'm having trouble getting information on how to proceed.
Let's say I have a square with a texture on it. Let's say I want to create it very small, and then gradually stretch it to its normal size. Only that square can be subjected to the effect and nothing else around it. I have this assumption that building a new vertex buffer every time is expensive, and for the animation to be fluid, this would need to happen very frequently. Is that the norm or is there a better way of doing this?
To stretch/scale objects you should use matrices, not recreating vertices.
You can read a tutorial here http://www.learnopengles.com/understanding-opengls-matrices/ or google for another one, there are lots of educational materials on OpenGL ES 2.0.

Map based Android Game. OpenGL-ES or Canvas?

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!

Drawing on bitmap vs directly on canvas

In my application I need to draw a large network (basically, little boxes connected with lines) and the user will be able to zoom and pan it around.
My first option was to draw the network directly to the canvas, but I thought that was not very efficient, because each time a pan event occurs, the drawing process begins again.
So I tried to use a large mutable bitmap and draw my entire network only once (or at least whenever zoom occurs), and blit the necessary areas to the canvas.
My problem is, since the network is rather big, I get OOM exception when creating the bitmap…
What should I do? Draw directly to the canvas? Use several smaller bitmaps?
Thanks,
Direz
My first question to you is how many sprites you have going at once? By far, the fastest mechanism for having many sprites on the screen is to use OpenGL due to the hardware accelleration. The besy way, on Android, I have found to do this is to use the Cocos2d android (not to be confused with the ios version) which is available on Google Projects. You will have to use the IOS documentation in order to understand it though and there are a few decent tutorials to get started with online..in particular, the hello world template here... Www.sketchydroide.com/Blog/p?=8. It is out of date compared to the latest IOS cocos2d but thats to be expected. I have found that the programs run MUCH faster when not connected to an active debugger session in my experiments.
If you want to stick with your current approach or the above is still not fast enough, you are going to have to attempt to cull any drawing which does not appear n the screen meaning a general function of the form "if the sprite's x and y values are outside the bounds of the visible area, dont draw it" which is basically how most tile base games handle the issue.
It sounds like you are doing the drawing manually if you are doing little squares. I think it is more adviseable to go ahead and draw on the canvas but to be very careful about managing your sprite counts and to avoid heavy for loop iteratiins that occur on
the frame update loops where possible. It is rather easy to max out your little handset with drawing operations.
Another option might be to draw the entire bitmap once into memory and then use a copy rectangle operation to transfer the image to the screen without drawing the full bitmap you have created. I think that copy rect should be a fast operation normally but if you are using it to draw the whole screen it seems like overkill and probably wont work as well.
You're probably not going to like this, but if all you're doing is drawing boxes and lines, the efficiency of the canvas is going to be pretty dang high. Are you getting UI lag or something?
One thing I have messed around with is drawing collections of subcomponents that won't change much or at all to a bitmap then rendering (scaling/moving aren't all that expensive if done at the right level) to the canvas can help efficiency. I have tried in the past to create a framework for rendering a tile-like subset of an existing larger image, but did not meet much success. I've made things work, but the code just gets ugly.
Oh, also a quick test to see if the component you are rendering is within the rectangle created by the screen can save you a bunch of processor time.

Android Drawable Drawing Performance?

In my view I have a simple ARGB drawable that takes about 2ms to draw but I can draw the same file as a bitmap in under 0.5ms (just some quick code, I can't really consider it an option). What are the best ways to optimize the drawing speed of a drawable?
It will depend on the number of drawables and how many times each gets drawn. For a small number, use canvas (an exact number will also depend on the device) I would suggest using Canvas as it's a nice higher level approach to drawing.
If you want to crank out a lot of images (think hundreds), I would suggest creating a GLSurfaceView and using openGL to render your images using VBOs tailored to your app. I would also recommend using a texture sheet if you go down this route since you'll get a huge increase in performance at the cost of code complexity.
But this will also depend on that type of app. My background is in game development so I use openGL exclusively for better performance. for a simple app (something along the lines of androidify) Canvas should be fine. If you want a simple tutorial for openGL, I suggest visiting Bergman's series of posts on the topic (google should give you a link for that). It is a nice intro to openGL.

Drawing bitmaps faster on Android canvas or OpenGL

I currently have a game written using the Android canvas. It is completely 2D, and I draw bitmaps as sprites on the canvas, and it technically works, but I have a few features that I need to add that will require drawing many more bitmaps on the screen, and there will be a lot more movement.
The app needs more power.
What is the best way to go from this method of drawing Bitmaps on a canvas to using OpenGL so I can draw them faster?
There are a couple platforms out there in the works for making 2d open gl games:
http://www.rokonandroid.com/
http://www.andengine.org/
Unfortunately neither is as well developed as it's iPhone equivalents (cocos2d-iphone), but they will help you get off the ground faster than trying to interface with openGL right off the bat yourself.
I think you can get good performance out of a canvas.. but it takes a lot of work..
if you start off with a good performance graphics library, then even if you get a lot of things wrong, you probably will still end up with good performance :) lol
there is a competition running for the fastest drawing library... libgdx is currently winning...
https://github.com/libgdx/libgdx/wiki/A-simple-game

Categories

Resources