| 
        
          | 
              
                
                
                
               
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Mar 29 2003 :  2:37:54 PM     
 |  
                      | Nope -- I got tricky and added in Direct3D to the mix.  You can't actually draw in 3D, granted, (at least, I havent tried) but you can create two triangles and texture them.  Direct3D also does the alphablending for me. 
 
 |  
                      |  |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Mar 30 2003 :  10:47:43 AM       
 |  
                      | Ah, there are two different examples of using direct 3D in the Files section here at VB gamer if you haven't looked yet.  But since you have it working already, then you don't need them  |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Apr 13 2003 :  10:38:22 AM     
 |  
                      | I feel like I've run into a brick wall.  I'm using GetLockedArray() to get a pointer to the [backbuffer's] surface memory, and so far all that works.  Changes are reflected in the surface, as they should be.
 
 The problem is that I cannot obtain the 'true' color of a pixel, nor specify my own color.  This is because I cannot determine the RGB of the pixel -- it's in a format that I don't know how to change.  How can I convert the raw data into a usable RGB format?
 
 Mind as well hit two birds with one stone...  Is there a 'darkening' formula I can use?  Just changing the RGB of a pixel to a lower value doesn't darken it; it changes the color completely.
 
 Thanks!
 Amrazek
 |  
                      |  |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - May 30 2003 :  3:18:16 PM     
 |  
                      | I put this project off a little bit, for lack of understanding, but my interest has been rekindled.  So far, I've got the code to set the correct color implemented and working, but the second part is returning a color back to its original state.  I've lost the source for this project, but I had added a few capabilites to my general game engine that will allow me to rebuild it in about a half hour.  I've got a couple theories going; I'll add a reply on anything that I've found. 
 -Amrazek
 |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Jun 03 2003 :  9:47:54 PM     
 |  
                      | I'm having difficulty returning the color of a pixel...  I just can't seem to figure out how to change the DirectDraw long value back into RGB... 
 
 |  
                      |  |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 04 2003 :  09:41:41 AM       
 |  
                      | Look at that link I provided in my last message.  For GetLockedArray(), I think you are supposed to use an array of Bytes. |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Jun 04 2003 :  6:16:12 PM     
 |  
                      | I've got the changing my RGB color into a DXRGB color conversion working.  However, I cannot change a DXRGB color back into RGB...  I've tried .ColorGetRed / Blue / Green, but that requires a value of 0-255.  As I understand it, the values in GetLockedArray ARE up to 255, but it's in a different format...  There are 3 bytes per pixel...  Unless...  Just maybe...  I've got an idea.  I'll have to go check it out right now.
 
 -Amrazek
 |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Jun 04 2003 :  9:26:57 PM     
 |  
                      | My hopeful idea didn't work...  I was thinking that .GetLockedArray returned the width of the surface * 3, for BGR...  However, .ColorGetRed/Green/Blue didn't work...  Red returned 1, the others returned 0.  Frustrating  |  
                      |  |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 04 2003 :  9:55:51 PM       
 |  
                      | .GetColorRed/Green/Blue expects a LONG,  the data from the byte array is a BYTE.   If you are in 16bit mode, two bytes make a color for each pixel, in 24bit mode, then its 3 bytes to a pixel, and in 32 bit mode, its 4 bytes to a pixel. 
 A 32bit example would look something like this after you use GetLockedArray
 
   Dim B(0 to 3) as Byte, L as Long
 B(0)= LckdArray(0+0,0)
 B(1)= LckdArray(0+1,0)
 B(2)= LckdArray(0+2,0)
 B(3)= LckdArray(0+3,0)
 CopyMemory(L, B(0), 4)   Debug.Print dx.ColorGetRed(L)
 Debug.Print dx.ColorGetGreen(L)
 Debug.Print dx.ColorGetBlue(L)
 
 
 
 A 16bit example would be only two bytes to the byte array, B(0 to 1), and then copymemory would be CopyMemory(L, B(0)), 2).
 
 Of course, there are faster ways to do this.  I'm just trying to show you how the bytes are arranged.  The pixel at location (0,0) would be LckdArray(0,0), LckdArray(1,0), LckdArray(2,0), LckdArray(3,0),  the pixel at location (1,0) would be LckdArray(4,0), LckdArray(5,0), LckdArray(6,0), LckdArray(7,0).
 |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Jun 06 2003 :  10:47:13 PM     
 |  
                      | I believe I understand now -- didn't know that it was only 2 bytes and that you could use CopyMemory to combine them.  That helps a lot =) 
 However, the value returned is still incorrect...  Perhaps I need to do some kind of a conversion on it?
 |  
                      |  |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 07 2003 :  12:30:19 PM       
 |  
                      | Try using some solid color surfaces first to help you get a better idea of how the bytes are laid out in the byte array.  You could try an all blue surface, and then output a few bytes in HEX, then you could easily combine them with the windows Calculator to see how things are organized.  For example, if you use Debug.print to get something like this...  0 1F 0 1F,  you would use the number "001F001F" in Calculator to convert to a binary of "0000 0001 1111 0000 0000 0001 1111", and that would show you the color is only using 6 Bits.  If you explore a bit more, you'll understand how things are packed together. |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts |  |  
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 15 2003 :  12:16:08 AM       
 |  
                      | Did you write the "GetColor" functions in the GfxEngine class?   A value of "h31" should translate to value of "1.0" in 16 bit color. |  
                      |  |  |  
                | AmrazekSquire
 
  
 
                40 Posts | 
                    
                      |  Posted - Jun 15 2003 :  12:51:58 AM     
 |  
                      | Hmm...  Interesting...  I'll post the portion of GfxEngine that contains that: 
   Public Function GetColorRed(lngDXColor As Long) As Single
 GetColorRed = DX.ColorGetRed(lngDXColor)
 End Function
 
 Public Function GetColorGreen(lngDXColor As Long) As Single
 GetColorGreen = DX.ColorGetGreen(lngDXColor)
 End Function
 
 Public Function GetColorBlue(lngDXColor As Long) As Single
 GetColorBlue = DX.ColorGetBlue(lngDXColor)
 End Function
 
 
 That looks alright to me...  Perhaps something in the initialize sub is wrong?
 
   Private Sub DDInit(ByRef myForm As Long, ByRef iScreenWidth As Integer, ByRef _
 iScreenHeight As Integer, ByRef iBPP As Integer, ByRef _
 iColorKey As Integer, ByRef bUseVideoMemory As Boolean, _
 ByRef bytFontRed As Byte, ByRef bytFontGreen As Byte, _
 ByRef bytFontBlue As Byte, ByRef bSetFontTransparent As _
 Boolean, ByRef iBackBufferCount As Integer, ByRef _
 bGammaController As Boolean, ByRef bytGammaRed As Byte, _
 ByRef bytGammaGreen As Byte, ByRef bytGammaBlue As Byte)
 On Error Resume Next
 
 Set DX = New DirectX7
 Set DD = DX.DirectDrawCreate("")
 
 Call DD.SetCooperativeLevel(myForm, DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE)
 
 DD.SetDisplayMode iScreenWidth, iScreenHeight, iBPP, 0, DDSDM_DEFAULT
 
 Ddsd1.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
 If Not bSetFontTransparent = True Then
 Ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_SYSTEMMEMORY
 Else
 Ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
 End If
 
 Ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_3DDEVICE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX Or DDSCAPS_VIDEOMEMORY
 Ddsd1.lBackBufferCount = iBackBufferCount
 Set ddsFront = DD.CreateSurface(Ddsd1)
 InitializeLighting
 
 If bGammaController Then
 Set GammaController = ddsFront.GetDirectDrawGammaControl
 GammaController.GetGammaRamp DDSGR_DEFAULT, OriginalRamp
 End If
 
 Dim Caps As DDSCAPS2
 If Not bUseVideoMemory = True Then
 Caps.lCaps = DDSCAPS_BACKBUFFER Or DDSCAPS_SYSTEMMEMORY
 Else
 Caps.lCaps = DDSCAPS_BACKBUFFER
 End If
 
 Set ddsBack = ddsFront.GetAttachedSurface(Caps)
 ddsBack.GetSurfaceDesc Ddsd2
 
 Set D3D = DD.GetDirect3D
 Set DEV = D3D.CreateDevice("IID_IDirect3DHALDevice", ddsBack)
 
 
 DDSetFont "Calligraphic 421 BT", 12, RGB(bytFontRed, bytFontGreen, bytFontBlue)
 
 If bSetFontTransparent Then
 ddsBack.SetFontTransparency True
 End If
 
 With Screen
 .nWidth = iScreenWidth
 .nHeight = iScreenHeight
 .nBPP = iBPP
 
 .bytFontRed = bytFontRed
 .bytFontGreen = bytFontGreen
 .bytFontBlue = bytFontBlue
 .bFontTransparent = bSetFontTransparent
 
 .iColorKey = iColorKey
 .bUseVideoMemory = bUseVideoMemory
 
 .iBackBufferCount = iBackBufferCount
 .bGammaController = bGammaController
 .bytGammaRed = bytGammaRed
 .bytGammaGreen = bytGammaGreen
 .bytGammaBlue = bytGammaBlue
 End With
 
 If bGammaController Then
 SetGamma bytGammaRed, bytGammaGreen, bytGammaBlue
 End If
 
 
 
 Also of note: I'm using 2 backbuffers, and am using the gamma controller.  BPP = 16, and the ColorKey is black.  Another thing: GfxEngine is actually a whole DirectDraw engine I wrote, and is a DLL.
 
 This is more difficult than I initially thought...
  Oh well, much knowledge to be gained. 
 -Amrazek
 |  
                      |  |  |  
                
                
                
               |  |