Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  fastest way to draw 2D images  (Read 5549 times)
0 Members and 1 Guest are viewing this topic.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Posted 2009-08-07 17:03:57 »

I'm starting to adventure myself with android, and I've ported a small game I've made, but I'm not sure if I am doing the drawing stuff in the fastest way.

I am loading my sprites in Bitmap s . Then I have my gameview (which extends View) with a loop which calls invalidate(),  and in the onDraw(Canvas c) I render everything (first the background bitmap then all the other stuff, about 50 bitmaps (15x15)).

I believe this is the simplest way to do it, but I am sure there are other (maybe better) ways to do it ... are there ?

Offline Ranger
« Reply #1 - Posted 2009-08-07 21:47:37 »

The better (performance wise) way is to use OpenGL ES.  Tongue  But, IMO, coding in OpenGL ES is horrible if you're only doing 2D.  So if you don't have any performance problems, I'd say you have the best way.

At the Google I/O they discussed this stuff.  I recommend watching the presentation:  http://www.youtube.com/watch?v=U4Bk5rmIpic  It's an hour long, so make sure you have enough time spare.  Smiley
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2009-08-07 21:49:15 »

You can create a canvas backed by OpenGL pretty easily - that seems pretty performant.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ranger
« Reply #3 - Posted 2009-08-08 02:30:10 »

You can create a canvas backed by OpenGL pretty easily - that seems pretty performant.

Kev

Hey Kev,  Can you please explain what you mean by this?  Can I call canvas.drawLine(x1,y1,x2,y2) and have it run on the OpenGL chip?  Thanks.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #4 - Posted 2009-08-08 03:11:23 »

Thanks you guys.
I do have some problems but I'm not sure why .

I have 30 FPS (which is the ideal for the game) but sometimes the framerate just drops strangely to ~20 then raises again to 30 fps . I tried deactivating physics and AI, and left only the rendering, but it still happens.
I'm using the onKeyDown/Up for input.

Have u been thru this ? I've read all the Android threads here and it seems is none of the problems you had so far .
By the way, I'm running only in the emulator. I still don't have a device Sad , but I'm buying me one in September.


Hey Kev,  Can you please explain what you mean by this?  Can I call canvas.drawLine(x1,y1,x2,y2) and have it run on the OpenGL chip?  Thanks.

That would be awesome !

Thanks again folks !

Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2009-08-08 04:58:25 »

I'm pretty sure the fastest way to draw a 2D image is glDrawTexiOES. I couldn't get it to work though. Does anyone have any sample code with it working? I'd really like to see a working example. Supposedly you do something like:

1  
2  
3  
4  
5  
6  
7  
if (gl instanceof GL11 && gl instanceof GL11Ext) {
   ((GL11)gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, new int[] {0, 0, width, height}, 0);
   .
   .
   .
   ((GL11Ext)gl).glDrawTexiOES(0, 0, 0, 64, 64);
}




On a somewhat related topic, has anyone been able to draw tinted images? I can draw images with varying alpha, but the rgb is ignored (I always get the image with its normal colors).

Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2009-08-08 07:29:09 »

You can go:

1  
Canvas canvas = new Canvas(gl);


And then use that canvas to draw to the GL context. It works but I'm not sure how performant it is (see bend hero).

Kev

Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #7 - Posted 2009-08-08 14:33:17 »

You can go:

1  
Canvas canvas = new Canvas(gl);


And then use that canvas to draw to the GL context. It works but I'm not sure how performant it is (see bend hero).

Kev

Thanks Kev. I will test that when I get home tomorrow .

Do you know what might cause the problem with random stalls I described in my last post ?
I was thinking, maybe it is related to the way I do the game loop, using delayed messages . I learned to do like that looking your "cross plataform framework" (Applet-Android-iPhone) . Come to think of it, most of what I've learned of Android I learned with your code . Thanks for that !

anyway thanks guys for the feedback.


Offline Ranger
« Reply #8 - Posted 2009-08-08 22:39:19 »

You can go:

1  
Canvas canvas = new Canvas(gl);


And then use that canvas to draw to the GL context. It works but I'm not sure how performant it is (see bend hero).

Kev

Tried to stick some canvas calls in the middle of my existing game, it didn't like it (tried draw line and draw text):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
08-09 08:31:11.142: INFO/DEBUG(32): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-09 08:31:11.142: INFO/DEBUG(32): Build fingerprint: 'htc-dream_stg/dream_stg/dream/trout:1.5/CRC28/150708:user/ota-rel-keys,release-keys'
08-09 08:31:11.142: INFO/DEBUG(32): pid: 1564, tid: 1576  >>> com.craigsrace.pinkslipracing <<<
08-09 08:31:11.142: INFO/DEBUG(32): signal 11 (SIGSEGV), fault addr 00000024
08-09 08:31:11.152: INFO/DEBUG(32):  r0 00070478  r1 0019b2bc  r2 0019b2e4  r3 00000000
08-09 08:31:11.152: INFO/DEBUG(32):  r4 00000000  r5 0019b270  r6 ac12736c  r7 0019b2e4
08-09 08:31:11.152: INFO/DEBUG(32):  r8 00070478  r9 00000000  10 00000000  fp 0000000a
08-09 08:31:11.152: INFO/DEBUG(32):  ip ac052c50  sp 45187c70  lr ac052e68  pc ac052c6c  cpsr 60000010
08-09 08:31:11.322: INFO/DEBUG(32):          #00  pc 00052c6c  /system/lib/libsgl.so
08-09 08:31:11.332: INFO/DEBUG(32):          #01  pc 00052e64  /system/lib/libsgl.so
08-09 08:31:11.352: INFO/DEBUG(32):          #02  pc 00054100  /system/lib/libsgl.so
08-09 08:31:11.352: INFO/DEBUG(32):          #03  pc 0003ebd0  /system/lib/libandroid_runtime.so
08-09 08:31:11.352: INFO/DEBUG(32):          #04  pc 0000e3b4  /system/lib/libdvm.so
08-09 08:31:11.372: INFO/DEBUG(32): stack:
08-09 08:31:11.372: INFO/DEBUG(32):     45187c30  45187cd7  
08-09 08:31:11.372: INFO/DEBUG(32):     45187c34  00000000  
08-09 08:31:11.372: INFO/DEBUG(32):     45187c38  00000000  
08-09 08:31:11.372: INFO/DEBUG(32):     45187c3c  415499e8  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c40  41816edc  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c44  001f4c0c  [heap]
08-09 08:31:11.382: INFO/DEBUG(32):     45187c48  45187cbc  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c4c  00010000  [heap]
08-09 08:31:11.382: INFO/DEBUG(32):     45187c50  00000000  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c54  00000000  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c58  00000001  
08-09 08:31:11.382: INFO/DEBUG(32):     45187c5c  45925ccc  
08-09 08:31:11.392: INFO/DEBUG(32):     45187c60  45902180  
08-09 08:31:11.392: INFO/DEBUG(32):     45187c64  afe2e10c  /system/lib/libc.so
08-09 08:31:11.392: INFO/DEBUG(32):     45187c68  df002777  
08-09 08:31:11.392: INFO/DEBUG(32):     45187c6c  e3a070ad  
08-09 08:31:11.392: INFO/DEBUG(32): #00 45187c70  45187cbc  
08-09 08:31:11.392: INFO/DEBUG(32):     45187c74  00000000  
08-09 08:31:11.402: INFO/DEBUG(32):     45187c78  45925d44  
08-09 08:31:11.402: INFO/DEBUG(32):     45187c7c  00010000  [heap]
08-09 08:31:11.402: INFO/DEBUG(32):     45187c80  00010000  [heap]
08-09 08:31:11.402: INFO/DEBUG(32):     45187c84  afe2e078  /system/lib/libc.so
08-09 08:31:11.402: INFO/DEBUG(32):     45187c88  45187c90  
08-09 08:31:11.402: INFO/DEBUG(32):     45187c8c  80533888  /system/lib/libhgl.so
08-09 08:31:11.402: INFO/DEBUG(32):     45187c90  00000000  
08-09 08:31:11.412: INFO/DEBUG(32):     45187c94  00070478  [heap]
08-09 08:31:11.412: INFO/DEBUG(32):     45187c98  0019b270  [heap]
08-09 08:31:11.412: INFO/DEBUG(32):     45187c9c  ac12736c  
08-09 08:31:11.412: INFO/DEBUG(32):     45187ca0  0019b2e4  [heap]
08-09 08:31:11.422: INFO/DEBUG(32):     45187ca4  0019b270  [heap]
08-09 08:31:11.422: INFO/DEBUG(32):     45187ca8  431754e8  
08-09 08:31:11.422: INFO/DEBUG(32):     45187cac  0019b2bc  [heap]
08-09 08:31:11.422: INFO/DEBUG(32):     45187cb0  0000000a  
08-09 08:31:11.422: INFO/DEBUG(32):     45187cb4  ac052e68  /system/lib/libsgl.so
08-09 08:31:11.422: INFO/DEBUG(32): #01 45187cb8  00000014  
08-09 08:31:11.432: INFO/DEBUG(32):     45187cbc  00010000  [heap]
08-09 08:31:11.432: INFO/DEBUG(32):     45187cc0  00010000  [heap]
08-09 08:31:11.432: INFO/DEBUG(32):     45187cc4  00000000  
08-09 08:31:11.432: INFO/DEBUG(32):     45187cc8  45925ccc  
08-09 08:31:11.432: INFO/DEBUG(32):     45187ccc  00000004  
08-09 08:31:11.442: INFO/DEBUG(32):     45187cd0  00000000  
08-09 08:31:11.442: INFO/DEBUG(32):     45187cd4  ac054024  /system/lib/libsgl.so
08-09 08:31:11.442: INFO/DEBUG(32):     45187cd8  0019b270  [heap]
08-09 08:31:11.442: INFO/DEBUG(32):     45187cdc  00000000  
08-09 08:31:11.442: INFO/DEBUG(32):     45187ce0  00000000  
08-09 08:31:11.442: INFO/DEBUG(32):     45187ce4  00000000  
08-09 08:31:11.442: INFO/DEBUG(32):     45187ce8  001e0f38  [heap]
08-09 08:31:11.452: INFO/DEBUG(32):     45187cec  ac054104  /system/lib/libsgl.so
08-09 08:31:12.482: INFO/DEBUG(32): debuggerd committing suicide to free the zombie!
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #9 - Posted 2009-08-08 22:47:00 »

I'd expect it to be an either or thing. The Canvas is going to assume it's in control of the GL state all the time.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #10 - Posted 2009-08-11 01:16:09 »

At the Google I/O they discussed this stuff.  I recommend watching the presentation:  http://www.youtube.com/watch?v=U4Bk5rmIpic  It's an hour long, so make sure you have enough time spare.  Smiley

I just watched the video, and though I  took a while to get used to guy speaking (he speaks really fast for me, a non-native speaker) it's definitely worth the time, and it indeed helped.
What causes the random stalls in my game is the garbage collector . That should have been obvious , but I just realized it when he said "never allocate!" .

Well now I just have to find a way to avoid the "new"...

cheers

Offline Nate

« JGO Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #11 - Posted 2009-08-17 19:57:05 »

I'm pretty sure the fastest way to draw a 2D image is glDrawTexiOES.

I got glDrawTexiOES to work. I don't see a noticeable difference between using glDrawArrays. Actually, I swapped my particle system from glDrawArrays to glDrawTexiOES and lost 1 or 2 FPS. It may be faster just drawing one image, but not by much.

Offline Ranger
« Reply #12 - Posted 2009-08-17 23:34:45 »

I got glDrawTexiOES to work. I don't see a noticeable difference between using glDrawArrays. Actually, I swapped my particle system from glDrawArrays to glDrawTexiOES and lost 1 or 2 FPS. It may be faster just drawing one image, but not by much.

Interesting.  And, please correct me if I'm wrong, but glDrawTexiOES is not guaranteed to be supported by all Android phones, while glDrawArrays is.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (136 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!