Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
i have a big problem with my game in vb.net. i have a background picture in a panel, its 800*1200. i have many link label and picture so when i scroll down or anything, the game become slow like hell. if i put off the picture, the speed is ok. So any idea to draw the big picture faster than making it the background picture of a panel ?
  • *Experts*
Posted

Dont forget to set DoubleBuffering and two other styles which will improve the drawing:

Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)

You can find a lot of info on those in MSDN. basically double buffering is drawing in memory first and then copying the result to the screen.

  • *Experts*
Posted
As far as I know, UserPaint and whatnot has no effect when used directly on the surface of a form. I believe you will have to subclass (simply Override WndProc) and capture the WM_PAINT message.
  • *Experts*
Posted
AllPaintingInWmPaint tells the application to ignore the WM_ERASEBKGND which will lower the flicker, and it should only be set if UserPaint is set. This would mean that it does work :), I could be wrong and its never too late to learn.
  • *Experts*
Posted
Well, I haven't tested on a form, but the other day when making an analog clock control (a UserControl), settings those styles did nothing to the flicker. When I subclassed for WM_PAINT and doublebuffered myself (with a temporary Graphics object and Bitmap) it was totally flickerless.
  • *Experts*
Posted
You create a bitmap object, a graphics object for that bitmap. Then you draw using that Graphics object onto that bitmap and finally draw and present the bitmap when its finished.
Posted (edited)

That's it? And without using SetStyle, the Image will be "blitted" to the screen; DoubleBuffed?

 

It does not work.

Bitmap b=new Bitmap(wbb.Bmp.Size.Width, wbb.Bmp.Size.Height);
Graphics g= Graphics.FromImage(b);
g.DrawImage(wbb.Bmp, new Rectangle(0,0, wbb.Bmp.Width, wbb.Bmp.Height));
e.Graphics.DrawImage(b, wbb.Bounds, wbb.ClipBounds, GraphicsUnit.Pixel);
g.Dispose();

Edited by aewarnick
C#
  • *Experts*
Posted
That's sort of half right. You need two objects.
Bitmap b = new Bitmap(wbb.Bmp.Size.Width, wbb.Bmp.Size.Height);
Graphics db = Graphics.FromImage(b); // double buffer
Graphics g = Me.CreateGraphics();
// draw your stuff on db, the backbuffer
g.DrawImage(db, /* etc */); // show the memory bitmap

Something like that.

  • *Experts*
Posted

Im assuming you trying to do that with a panel because you were mentioning it. If you want to do that for a panel you need to inherit a control from a panel, apply those styles in the constructor and use that control instead of the original panel. You have to do it like this becasue SetStyle is protected method.

If you are using a form then what is your excat code?

Posted

its in my sub load form1

...

Dim g as Graphics = me.createGraphics

Dim mybitmap as new bitmap("c:\carte.jpg")

g.drawimage(myBitmap, 0, 0)

g.dispose()

me.setstyle(controlstyles.doublebuffer,true)

me.setstyle(controlStyles.UserPaint, true)

...

 

ok here is the problem i have

 

when i add this

me.setstyles.(Controlstyles.allpaintinginwmpaint, true)

the picture dont show

 

and when i scroll down the rest of the picture isnt there

i imagine i have to redraw image each time i scroll

 

 

and even if my control over the form have transparent backcolor, their backcolor appeir has the form backcolor.

Posted

That's the problem with me.CreateGraphics(), it is not automatically updated when the screen is redrawn. If you want it to "stick" you must draw in a paint event or better yet an overriden OnPaint of the Form or the Panel.

 

Then you use the SetStyle.DoubleBuffer procedure. That is the easiest way to do it.

C#
Posted
when i use onPaint or paint, it become as slow as if i was using a background image of the form.i guess the only way i can make it fast enough would be to repaint the picture but only when i use the scroll of the form. but i cant find that event. i guess il have to build a new scrollbar instead of the automatic scroll of the form
Posted

VolteFace, this did not work. Still flickers the same.

Bitmap b=new Bitmap(wbb.Bmp.Size.Width, wbb.Bmp.Size.Height);
Graphics g= Graphics.FromImage(b);
g.DrawImage(wbb.Bmp, new Rectangle(0,0, wbb.Bmp.Width, wbb.Bmp.Height));
Graphics gg=this.CreateGraphics();
gg.DrawImage(b, wbb.Bounds, wbb.ClipBounds, GraphicsUnit.Pixel);
g.Dispose();
gg.Dispose();

NeOBz, Code in OnPaint should not be slow if you do it right. It should only paint part of the picture and Form when you scroll.

C#
Posted

I dont understand... when i use Onpaint its still slow. its only a 800*1212 picture. How can a computer play games like unreal smothly and not being able to show only one stupid picture. Well it can show it but when i click on control on the form, its too slow.

How could i use my graphics card power to print this picture so my processor stay fast enough for other jobs ?

  • *Experts*
Posted

Commercial games dont use GDI for games :).

If you want to use the graphics card you have to look into a graphics API like DirectX, which uses graphics hardware. GDI is not hardware accelerated.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...