A couple of questions
A couple of questions
A couple of questions
A couple of questions
A couple of questions
A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions
A couple of questions A couple of questions
A couple of questions
Go Back  Xtreme Visual Basic Talk > > > A couple of questions


Reply
 
Thread Tools Display Modes
  #1  
Old 06-26-2011, 04:50 PM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default A couple of questions


OK so recently I've started work on a small game and when I added a FPS counter I realised my engine is to slow (I'm using the re-draw thing). I decided that BITBLT would be my best bet, I know how to set it all up but what I want to know is:

What do the different paint things do, you know like srcpaint and srcand?

Can I BITBLT a solid colour and maybe have different transparency levels for that colour?

I think the was one more question but I forgot as I started typing, .

Edit.
Is it true that Microsoft are stopping managed Direct X because if they aren't I might have a look into that.

Thank you, in advance.

Last edited by lord_lazy; 06-26-2011 at 04:56 PM. Reason: I found the question
Reply With Quote
  #2  
Old 06-27-2011, 10:55 AM
passel's Avatar
passelA couple of questions passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I thought you were using VB 2008.
BITBLT and raster ops would normally be used by VB6 and earlier.
VB 2008 could use BITBLT (part of the GDI dll, not GDI+ which the .Net languages use), but it will involve unmanaged interOP code.

Probably best, if not going for a more advanced library, to stick with the native .net (GDI+) calls, i.e. using DrawImage instead of BitBlt. A side benefit, is that you don't have to add a bunch of declarations to use GDI+ since interfaces are provided in the .Net language of choice.
If you haven't tried drawing in .Net much yet, I posted my first forrays into graphics in .Net.
Since I was just learning myself, and wrote the code to show some of what I learned to co-workers, I made it somewhat interactive (put it in step mode), so it steps through the code allowing you to see what the instruction is for, what it is doing, at that step, and still be interactive so you can manipulate the image and see what the graphics look like up to that step in the process.
The C# version can be found in post 4, and the VB version in post 5 of this thead.

Not really the basis for a game or 2d engine, just showing a few of the possiblities with a subset of the available graphic commands.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 06-28-2011, 12:23 PM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default

Thank you for your help but right now I am using the built in graphics library but it's to slow for my game (15 FPS) so I looked into BITBLT and that seemed a good idea, are you saying that BITBLT will not work with VB2008+ or just that its better in VB6?
__________________
If me.hungry = true then
raid_fridge()
end if
Reply With Quote
  #4  
Old 06-28-2011, 04:52 PM
snarfblam's Avatar
snarfblamA couple of questions snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

Bitblt will work in VB2008. It was used in VB6 because it was the best option. It's a tiny bit harder to use in .NET, but passel's point is that GDI+ is way easier to use than GDI ever was or will be.

There is a speed difference. GDI is more likely to get hardware support than GDI+. But if you're hitting 15 fps with GDI+, I wouldn't count on Bitblt to fix your problems. You're probably still not going to get a perfect 60 fps with GDI, and for anybody with a less capable PC, it's going to be worse.

Microsoft has dropped support for Managed DirectX in favor of XNA, which is much easier to learn and use, and is portable across multiple platforms. If you're really interested in game programming, it's worth checking out.
__________________
C# _VB.NET _
Reply With Quote
  #5  
Old 06-29-2011, 11:29 AM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default

thank you I heard XNA was coming to vb but i don't know when.
i actually have my heart set on BITBLT, it might not have any effect on my fps but its worth the shot
__________________
If me.hungry = true then
raid_fridge()
end if

Last edited by lord_lazy; 06-29-2011 at 11:45 AM.
Reply With Quote
  #6  
Old 06-29-2011, 03:24 PM
passel's Avatar
passelA couple of questions passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

But you mentioned levels of transparency, and bitblt won't give you that. Bitblt stands for Bit Block Transfer, and it transfers a rectangle of pixels from one area to another.
The bits that make up the pixel in the one area are combined with the bits that make up a pixel in the other area using one or more binary logical operation, specified by the Raster Operation parameter.
For instance SrcCopy will just replace the destination bits with the source bits.
SRCAND will do a binary AND of the source bits and destination bits.

Probably, the slowness of the existing code may be cause by things like constantly using New to create bitmaps over and over, rather than deciding what number of bitmaps you need for buffers, source images, output, etc. and only creating them once and reusing them. There may be other optimizations, such as using the UI thread only for rendering, and using a dedicated non-UI thread for the game logic.

Normally you would be using a bitmap for a backbuffer and then draw that image to the form when done drawing.
The Paint event code then would have a line like:

e.Graphics.DrawImage(bmp,0,0)

in it. You can do a Me.Refresh or Me.Invalidate after the drawing is finished to trigger the Paint Event, but I've found that to be slower than using the following code at the end of your drawing in the back buffer.

Dim G as Graphics = Me.CreateGraphics
G.DrawImage(bmp, 0, 0)
G.Dispose

Using that in place of Me.Refresh at the end of the drawing saved 4ms per frame on one machine that I've tested.

Would you be interested in posting the game that is running slow?
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 06-29-2011 at 03:41 PM.
Reply With Quote
  #7  
Old 06-29-2011, 03:43 PM
Cerian Knight's Avatar
Cerian KnightA couple of questions Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,199
Default

Quote:
Originally Posted by snarfblam View Post
Bitblt was used in VB6 because it was the best option.
I've found the .PaintPicture method is mostly comparable when working with .Picture (but apparently not .Image). I actually found an old post about the subject: Bitblt vs. Paint Picture Speed test
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #8  
Old 06-29-2011, 03:55 PM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default

thank you for the help passel I probably will upload the code later (my internet is being slow) but my drawing technique uses the built in graphics double buffer and auto redraw and when on load i create a bitmap according to the screen size. I then draw everything in paint and use a "me.invalidate" to paint again. this worked fine until i added a frame rate counter (most of my code will be changed so im more than happy to upload it)
Attached Files
File Type: zip game.zippity.zip.zip (239.0 KB, 4 views)
__________________
If me.hungry = true then
raid_fridge()
end if

Last edited by lord_lazy; 06-29-2011 at 04:01 PM.
Reply With Quote
  #9  
Old 06-29-2011, 04:19 PM
passel's Avatar
passelA couple of questions passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Cerian Knight,
We're getting off topic, since this is .Net so .PaintPicture is not applicable, but in any case PaintPicture could actually be faster than bitblt in specialized cases, since PaintPicture worked on the .Picture context if you had the case where you loaded an 8-bit bitmap into the picturebox, the .Picture context would have the 8-bit depth image in it, but the .Image context would have the a screen-depth copy of it, so often would be 24-bit per pixel.
So, bitblt had 3-times the number of bytes to transfer from memory to the video card as PaintPicture did in that situation.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #10  
Old 06-29-2011, 05:35 PM
passel's Avatar
passelA couple of questions passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Well, doing a Me.Invalidate in the FormPaint to get it to loop endlessly I don't think is the way one should expect to do a game loop.
The windows form Timer is a bit erratic for a permanent solution, but for now it can probably help this situation.

Despite what the .Net documentation says, it is likely that if you set your timer interval in the range of 1 to 15 ms, the timer will fire at a multiple of 1/64ths of a second.
So as a quick check, I added a timer, set its interval to 1, and moved all the code you have in the FormPaint into the Tick event. I did a Timer1.Start() at the end of the form load event.

I commented out the following lines in the Form1
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.UpdateStyles()

Since you draw in a memory bitmap, you can DrawImage directly over the contents of the form so you don't need the form to double buffer itself.

But if you do Me.Invalidate, the form will flash because it is cleared before you draw on it in the paint event, so we want to avoid triggering the paint event.

In the code that was moved to the tick event comment out the Me.Invalidate() and replace it with somthing like this:

Dim G as Graphics = Me.CreateGraphics
G.DrawImage(dscrn_b, 0, 0)
G.Dispose()

Doing those changes just about doubled the frame rate (from 26,27 to 51,52) on the machine I was using.

Assuming your timer's base clock is 64hz, you will probably get similar improvement.
Those are the easy changes. Looking at the processing of the code itself would be the next exercise.

You don't need anything in the Form1_Paint event any longer, but if you want you can add the one line:
e.Graphics.DrawImage(dscrn_b,0,0)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #11  
Old 06-30-2011, 11:00 AM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default

wow i ran out of cookies to give but wow, thanks for all your help. i well get to work soon and i didn't really want to work extra on btiblt so its all good

edit.
thank you so much i just tried it and it worked super.
__________________
If me.hungry = true then
raid_fridge()
end if

Last edited by lord_lazy; 06-30-2011 at 03:12 PM. Reason: just tried it now
Reply With Quote
  #12  
Old 06-30-2011, 03:13 PM
lord_lazy lord_lazy is offline
Newcomer
 
Join Date: Nov 2010
Posts: 14
Default

it does blink sometimes its hard to tell maybe first few draws?
also when gained focus but it does do its job brillantly
__________________
If me.hungry = true then
raid_fridge()
end if
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
A couple of questions
A couple of questions
A couple of questions A couple of questions
A couple of questions
A couple of questions
A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions A couple of questions
A couple of questions
A couple of questions
 
A couple of questions
A couple of questions
 
-->