Help with alpha blending
Help with alpha blending
Help with alpha blending
Help with alpha blending
Help with alpha blending
Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending
Help with alpha blending Help with alpha blending
Help with alpha blending
Go Back  Xtreme Visual Basic Talk > > > Help with alpha blending


Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2005, 11:43 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Exclamation Help with alpha blending


I need help on how to use alpha blending using the mirage source engine. There's a picture box which is the main game screen, and I want another picture box which will be a 'hue'. I'm trying to make a day/night system, but i need help with this alpha blending. Can anyone help? I can also post more info if needed. Thanks.
Reply With Quote
  #2  
Old 07-14-2005, 10:08 AM
noi_max's Avatar
noi_maxHelp with alpha blending noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

How about a link to said game engine.

Does this engine have alphablending capabilities built in? Does it include VB source code?

Not sure if I could help you figure out someone elses engine or not, but I did a search using keywords like 'mirage' and 'engine' and couldn't seem to find relevant hits. (Either that or I wasn't sure I got the same thing you're talking about)
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines
Reply With Quote
  #3  
Old 07-14-2005, 01:30 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Default

Yeah, http://www.miragesource.com download the earliest release.

I'm pretty sure it uses it, but as I said, I'm tyring to make a pic hue on the game, making a day/night thing. The source is public domain (after a lot of issues).

Last edited by Temple; 07-14-2005 at 01:57 PM.
Reply With Quote
  #4  
Old 07-14-2005, 03:11 PM
EOB84 EOB84 is offline
Regular
 
Join Date: May 2003
Posts: 76
Default

Rather than using alpha blending for a day and night effect. I would try to use lighting. when I used direct X thas is what I did for day and night. Anyway... I am confused if you are the one using the Alpha blend API or if the "engine" is handling it. If the "engine" is handling it then I don't think many people on this forum will be able to help you. However; if it is VB code you need I can help you. If I remember correctly there was a bit of a trick to get alpha blend to work correctly in VB.
Reply With Quote
  #5  
Old 07-14-2005, 04:12 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Default

That would be great! The client and server is coded in vb and can be edited. If you can help me with this, I'd greatly appreciate it! I need that vb code
Reply With Quote
  #6  
Old 07-14-2005, 04:18 PM
EOB84 EOB84 is offline
Regular
 
Join Date: May 2003
Posts: 76
Default

http://www.mentalis.org/apilist/AlphaBlend.shtml is a good start. It will help you understand Alphablend and provides a code sample if you follow one of the links. Any other questions let me know.
Reply With Quote
  #7  
Old 07-14-2005, 05:32 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Default

I went there, read up, helped, and looked at the example. I tried to set the example on a Timer, but it wouldn't do the alphablend. It apparently only works with form_load(). Am I doing something wrong or is it only usable through form_load (I highly doubt)?
Reply With Quote
  #8  
Old 07-14-2005, 06:17 PM
EOB84 EOB84 is offline
Regular
 
Join Date: May 2003
Posts: 76
Default

I have had this problem before to. When I reviewed my code I saw that I was forgetting to move the BLENDFUNC structure into the BLENDFUNCT long using the RtlMoveMemory API. When looking at the example code it is easy to miss this step.
Reply With Quote
  #9  
Old 07-14-2005, 06:29 PM
EOB84 EOB84 is offline
Regular
 
Join Date: May 2003
Posts: 76
Default

Sorry misunderstood the question... Just add Picture2.Refresh at the very bottom of the timer code.
Reply With Quote
  #10  
Old 07-14-2005, 08:22 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Default

I found a link to exactly what I want however, I followed the tutorial but it doesn't work. Here's the tutorial: http://www.mirageuniverse.com/forums...p?topic=2967.0

Can you guys tell me what I did wrong? I followed the tutorial EXACTLY as it says. Thanks in advanced.
Reply With Quote
  #11  
Old 07-19-2005, 01:13 PM
Temple Temple is offline
Newcomer
 
Join Date: Oct 2004
Posts: 11
Default

Alright guys, I've gotten farther, here's what I have: picBlack is the picture box with the shade of the night. picScreen is the game screen. I have blackamount set so that it increases the opacity of picBlack. I call SquareAlphaBlend which is this:

Quote:
Public Sub SquareAlphaBlend( _
ByVal cSrc_Widht As Integer, _
ByVal cSrc_Height As Integer, _
ByVal cSrc As Long, _
ByVal cSrc_X As Integer, _
ByVal cSrc_Y As Integer, _
ByVal cDest As Long, _
ByVal cDest_X As Integer, _
ByVal cDest_Y As Integer, _
ByVal nLevel As Byte)

Dim LrProps As rBlendProps
Dim LnBlendPtr As Long

LrProps.tBlendAmount = nLevel
CopyMemory LnBlendPtr, LrProps, 4

AlphaBlend cDest, cDest_X, cDest_Y, cSrc_Widht, cSrc_Height, cSrc, cSrc_X, cSrc_Y, cSrc_Widht, cSrc_Height, LnBlendPtr

End Sub
With that said, I have picBlack at x 2000 y 0. When I have it call the function it doesn't work UNLESS picBlack has contact with picScreen. (It has to be touching, like, overlaying with picScreen). Here's the called function with the settings

Quote:
Call SquareAlphaBlend(512, 384, frmMirage.picBlack.hdc, 0, 0, TexthDC, 0, 0, blackamount)
Anybody know why it has to be overlaying? I'm having a world of troubles Thanks in advance.
Reply With Quote
  #12  
Old 07-19-2005, 01:50 PM
noi_max's Avatar
noi_maxHelp with alpha blending noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

Overlaying is the essence of alphablending - or how much one pic blends with the other.

So if your black square was alphablending with the main screen at say 15%, it would make the entire scene seem slightly darker.

Alphablending using API is a pretty slow process, so blending an entire screens worth in every frame could have the whole program slow down considerably.

The best alternatives I can think of is using hardware gamma control in DirectDraw (DirectX7) or accelerated 2-D graphics for alphablending in DirectX Graphics(DirectX8)

The latter being a much higher learning curve.

Alphablending using standard API works ok if you're only blending an image, say the size of a sprite. (maybe 32x32)

You may want to post your project (in a zip file) to allow others to help you without having to register on the web page you linked just to get the engine. Just a thought.
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines
Reply With Quote
  #13  
Old 07-24-2005, 09:37 PM
enanhawk enanhawk is offline
Newcomer
 
Join Date: Jul 2005
Posts: 1
Default

Hi. Ok well me and temple know each other and yeah we are working on this together. I got a command to work so that when you press Command2 button it alphablends picture1 (night) onto picscreen (the game screen).

The problem is that I think picScreen keeps writing over the alphablend right after it blends in. PicScreen is always being drawn on to. Is there any way to keep the alphablend always over picScreen so that picscreen doesn't keep on writing over the alphablend? I tried some tricks where you set picture1 autoredraw = true and then put picture1.refresh under the alphablend command. But nothing worked still. At this point Im pulling off ny day and night script with a semi transparent form but i do not exactly write that, so I really want to get this to work. Let me post the code here.

'Just to clear it up, picScreen = Game Screen which always is being drawn on. It uses DX7 and DirectDraw for the engine Mirage Source. picture1 = the picture that alphablends onto picscreen. Not 100% which variables are for alphablend on the declarations but that doesn't really matter. It only works once then picScreen redraws over picture1.

Code:
Option Explicit Const AC_SRC_OVER = &H0 Private Type BLENDFUNCTION BlendOp As Byte BlendFlags As Byte SourceConstantAlpha As Byte AlphaFormat As Byte End Type Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function AlphaBlend Lib "msimg32.dll" ( _ ByVal hdcDest As Long, _ ByVal nXOriginDest As Long, ByVal nYOriginDest As Long, _ ByVal nWidthDest As Long, ByVal nHeightDest As Long, _ ByVal hdcSrc As Long, _ ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, _ ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, _ ByVal BLENDFUNCT As Long) As Long Dim BF As BLENDFUNCTION, lBF As Long Dim i As Byte 'Use strong typed variable, not variant, _ so the vbruntime won't have to do a type conversion Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Private Const HWND_TOPMOST = -1 Private Declare Function SetWindowPos Lib "user32" _ (ByVal hwnd As Long, ByVal _ hWndInsertAfter As Long, ByVal x As Long, ByVal y As _ Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags _ As Long) As Long Private Sub Command2_Click() If (i <= 250) Then i = i + 25.5 Else i = 0 End If Label1.Caption = i With BF .BlendOp = AC_SRC_OVER .BlendFlags = 0 .SourceConstantAlpha = i .AlphaFormat = 0 End With 'copy the BLENDFUNCTION-structure to a Long RtlMoveMemory lBF, BF, 4 'AlphaBlend the picture from Picture1 over the picture of Picture2 AlphaBlend picScreen.hdc, 0, 0, picScreen.ScaleWidth, picScreen.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, lBF Picture1.Refresh 'call refresh to show changes we've made, use this if autoredraw is set to true End Sub Private Sub Form_Load() 'Set the graphics mode to persistent Picture1.AutoRedraw = True 'API uses pixels Picture1.ScaleMode = vbPixels 'set the parameters With BF .BlendOp = AC_SRC_OVER .BlendFlags = 0 .SourceConstantAlpha = 25 .AlphaFormat = 0 End With End Sub




Sorry if the declarations are a lot. I forgot which script allows alphablend im sure it is somewhere but yeah some of those variables are to help draw picScreen. For some facts this is Mirage Source (www.miragesource.com) and it runs on DX7 aka. DirectDraw. I would do gamma control with DX7 DIrect Draw but I heard for one some computers may not run it well and second I had a bit of a problem getting it to work. I hope someone can maybe figure out a script or soemthing I am missing that will keep the alphablend over picScreen so that picScreen does not wipe out the alphablend. I did something with my alternate day and night script (semi transparent form) where I put in a code that keeps it at top (keeps picScreen from pushing it away). So not sure if that can be done with this. Hope someone can help, sorry for talking so much but I would like everyone know all the details so I do not sound like a looser saying HELP IM STUCK :|

Last edited by Iceplug; 07-25-2005 at 08:30 AM. Reason: Added vb Tags
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
Help with alpha blending
Help with alpha blending
Help with alpha blending Help with alpha blending
Help with alpha blending
Help with alpha blending
Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending Help with alpha blending
Help with alpha blending
Help with alpha blending
 
Help with alpha blending
Help with alpha blending
 
-->