Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. GDI+ problem?

GDI+ problem?

Scheduled Pinned Locked Moved Visual Basic
graphicsgame-devcsswinformsdata-structures
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    O G I
    wrote on last edited by
    #1

    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.

    T D O 3 Replies Last reply
    0
    • O O G I

      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.

      T Offline
      T Offline
      Thomas Krojer
      wrote on last edited by
      #2

      Maybe because png pic´s are compressed?

      1 Reply Last reply
      0
      • O O G I

        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.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • O O G I

          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.

          O Offline
          O Offline
          O G I
          wrote on last edited by
          #4

          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#.

          J L 2 Replies Last reply
          0
          • O O G I

            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#.

            J Offline
            J Offline
            Jon_Boy
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • O O G I

              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#.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups