GDI+ problem?
-
Hi, I'm currently working on a 2D game engine for my RPG. Now the work on the physics engine is almost done, but the graphics are seems to be the biggest problem. I'm using VB 2008 and for the graphics - GDI+ . Almost all of the objects in my game are *png images, with smooth shadows and so on... I'm drawing the objects using two methods: the first one sets the drawing priority so that no one player can step on the head of other players. The second one is the loop that draws all the objects(players and textures) on the playground, that loop uses the GDI+ Graphics.DrawImage function and all this code looks like this: 'this subroutine sets the draw priority: Sub SetObjDrawPriority() For i = 0 To UBound(HBD) Select Case HBD(i).booIsAlive Case True intDrawPriority(i) = HBD(i).intTop End Select Next Array.Sort(intDrawPriority) End Sub Sub DrawAllObjects(ByVal e As System.Windows.Forms.PaintEventArgs) Try SetObjDrawPriority() For i = 0 To UBound(HBD) For i2 = 0 To UBound(HBD) If HBD(i2).intTop = intDrawPriority(i) Then e.Graphics.DrawImage(HBD(i2).bmpFace, HBD(i2).intLeft, _ HBD(i2).intDrawTop, HBD(i2).intWidth, HBD(i2).intObjDrawHeight) End If Next Next Catch ex As Exception End Try End Sub If I use *bmp texture for the objects with this size: 51 x 86 I can move simultaneously more than 200 objects on the visible area of the screen which is great, but If I replace the *bmp with *png images(with the same size: 51 x 86) the performance goes so bad that I can move normally less than 40 objects! Please tell me whats wrong. Is there any problem with the GDI+? I heard that GDI+ is wery slow and most of the programmers avoid it. I think that the code is pretty simple, but anyway maybe I'm wrong, please tell me how to optimize the code in case to get better performance. Thank you.
-
Hi, I'm currently working on a 2D game engine for my RPG. Now the work on the physics engine is almost done, but the graphics are seems to be the biggest problem. I'm using VB 2008 and for the graphics - GDI+ . Almost all of the objects in my game are *png images, with smooth shadows and so on... I'm drawing the objects using two methods: the first one sets the drawing priority so that no one player can step on the head of other players. The second one is the loop that draws all the objects(players and textures) on the playground, that loop uses the GDI+ Graphics.DrawImage function and all this code looks like this: 'this subroutine sets the draw priority: Sub SetObjDrawPriority() For i = 0 To UBound(HBD) Select Case HBD(i).booIsAlive Case True intDrawPriority(i) = HBD(i).intTop End Select Next Array.Sort(intDrawPriority) End Sub Sub DrawAllObjects(ByVal e As System.Windows.Forms.PaintEventArgs) Try SetObjDrawPriority() For i = 0 To UBound(HBD) For i2 = 0 To UBound(HBD) If HBD(i2).intTop = intDrawPriority(i) Then e.Graphics.DrawImage(HBD(i2).bmpFace, HBD(i2).intLeft, _ HBD(i2).intDrawTop, HBD(i2).intWidth, HBD(i2).intObjDrawHeight) End If Next Next Catch ex As Exception End Try End Sub If I use *bmp texture for the objects with this size: 51 x 86 I can move simultaneously more than 200 objects on the visible area of the screen which is great, but If I replace the *bmp with *png images(with the same size: 51 x 86) the performance goes so bad that I can move normally less than 40 objects! Please tell me whats wrong. Is there any problem with the GDI+? I heard that GDI+ is wery slow and most of the programmers avoid it. I think that the code is pretty simple, but anyway maybe I'm wrong, please tell me how to optimize the code in case to get better performance. Thank you.
Maybe because png pic´s are compressed?
-
Hi, I'm currently working on a 2D game engine for my RPG. Now the work on the physics engine is almost done, but the graphics are seems to be the biggest problem. I'm using VB 2008 and for the graphics - GDI+ . Almost all of the objects in my game are *png images, with smooth shadows and so on... I'm drawing the objects using two methods: the first one sets the drawing priority so that no one player can step on the head of other players. The second one is the loop that draws all the objects(players and textures) on the playground, that loop uses the GDI+ Graphics.DrawImage function and all this code looks like this: 'this subroutine sets the draw priority: Sub SetObjDrawPriority() For i = 0 To UBound(HBD) Select Case HBD(i).booIsAlive Case True intDrawPriority(i) = HBD(i).intTop End Select Next Array.Sort(intDrawPriority) End Sub Sub DrawAllObjects(ByVal e As System.Windows.Forms.PaintEventArgs) Try SetObjDrawPriority() For i = 0 To UBound(HBD) For i2 = 0 To UBound(HBD) If HBD(i2).intTop = intDrawPriority(i) Then e.Graphics.DrawImage(HBD(i2).bmpFace, HBD(i2).intLeft, _ HBD(i2).intDrawTop, HBD(i2).intWidth, HBD(i2).intObjDrawHeight) End If Next Next Catch ex As Exception End Try End Sub If I use *bmp texture for the objects with this size: 51 x 86 I can move simultaneously more than 200 objects on the visible area of the screen which is great, but If I replace the *bmp with *png images(with the same size: 51 x 86) the performance goes so bad that I can move normally less than 40 objects! Please tell me whats wrong. Is there any problem with the GDI+? I heard that GDI+ is wery slow and most of the programmers avoid it. I think that the code is pretty simple, but anyway maybe I'm wrong, please tell me how to optimize the code in case to get better performance. Thank you.
PNG's are compressed images. They have to be uncompressed to draw them. If you're requiring that kind of performance, look into the XNA Framework.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hi, I'm currently working on a 2D game engine for my RPG. Now the work on the physics engine is almost done, but the graphics are seems to be the biggest problem. I'm using VB 2008 and for the graphics - GDI+ . Almost all of the objects in my game are *png images, with smooth shadows and so on... I'm drawing the objects using two methods: the first one sets the drawing priority so that no one player can step on the head of other players. The second one is the loop that draws all the objects(players and textures) on the playground, that loop uses the GDI+ Graphics.DrawImage function and all this code looks like this: 'this subroutine sets the draw priority: Sub SetObjDrawPriority() For i = 0 To UBound(HBD) Select Case HBD(i).booIsAlive Case True intDrawPriority(i) = HBD(i).intTop End Select Next Array.Sort(intDrawPriority) End Sub Sub DrawAllObjects(ByVal e As System.Windows.Forms.PaintEventArgs) Try SetObjDrawPriority() For i = 0 To UBound(HBD) For i2 = 0 To UBound(HBD) If HBD(i2).intTop = intDrawPriority(i) Then e.Graphics.DrawImage(HBD(i2).bmpFace, HBD(i2).intLeft, _ HBD(i2).intDrawTop, HBD(i2).intWidth, HBD(i2).intObjDrawHeight) End If Next Next Catch ex As Exception End Try End Sub If I use *bmp texture for the objects with this size: 51 x 86 I can move simultaneously more than 200 objects on the visible area of the screen which is great, but If I replace the *bmp with *png images(with the same size: 51 x 86) the performance goes so bad that I can move normally less than 40 objects! Please tell me whats wrong. Is there any problem with the GDI+? I heard that GDI+ is wery slow and most of the programmers avoid it. I think that the code is pretty simple, but anyway maybe I'm wrong, please tell me how to optimize the code in case to get better performance. Thank you.
-
I've never heard before that PNG is compressed is there an uncompressed PNG format? I'm currently learning C++ but I'm only on the beginning so I can't move that fast to XNA, cause as I know XNA requires C++ or C#.
O.G.I. wrote:
I'm currently learning C++ but I'm only on the beginning so I can't move that fast to XNA, cause as I know XNA requires C++ or C#.
Nothing like trial by fire right? You could always give a try and post questions when you get stuck. Ping compression details
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
I've never heard before that PNG is compressed is there an uncompressed PNG format? I'm currently learning C++ but I'm only on the beginning so I can't move that fast to XNA, cause as I know XNA requires C++ or C#.
Hi, I don't see where the image's fileformat would be relevant, assuming you load the images into memory once (hence outside your drawing methods), which turns them into uncompressed bitmaps anyway, e.g. using
Bitmap bm=Bitmap.FromFile(filepath);
or something similar with FromSream. (example is C# syntax!). PS: I strongly object to your code swallowing exceptions; if you (think you) need a try-catch, then do something useful with the exception, e.g. display it's Exception.ToString(). [ADDED]And if there is a very specific exception that you rightfully want to ignore, add a catch for that specific exception and insert a comment as to why it is OK to ignore it; then leave the more general catch out, or put some code in it. [/ADDED] :)Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
modified on Thursday, June 25, 2009 10:44 AM