Seite 1 von 1

DCs von Images & Sprites ermitteln

Verfasst: 10.04.2006 07:34
von blbltheworm
Hallo zusammen,
ich würde gerne ein wenig mit BitBlt rumspielen.
Momentan weiß ich aber nur, wie man an den DC von Gadgets kommt.
Wie sieht das mit den DCs von Images & Sprites aus??
Bzw. kann man mit BitBlt überhaupt auf Sprites zugreifen??

Verfasst: 10.04.2006 12:15
von ABBKlaus
Hi,

soweit ich weiss liefert der Befehl StartDrawing einen DC zurück.

Code: Alles auswählen

DC=StartDrawing(ImageOutput())
MfG Klaus

Verfasst: 12.04.2006 20:33
von blbltheworm
Und wenn ich jetzt vonn einen Image in ein anderes malen möchte??
2x StartDrawing aufrufen geht ja nicht.

Verfasst: 13.04.2006 16:15
von ABBKlaus
nun ja irgendwie geht das schon :

Code: Alles auswählen

DC1=SpriteOutput(1)
DC2=SpriteOutput(2)
StartDrawing(DC1)
  ; zeichenoperationen hier
StopDrawing()

StartDrawing(DC2)
  ; zeichenoperationen hier
StopDrawing()
PS: BitBlt müsste auch ausserhalb von StartDrawing() / StopDrawing() funktionieren

MfG Klaus

Verfasst: 13.04.2006 17:04
von Deeem2031
ABBKlaus hat geschrieben:

Code: Alles auswählen

DC1=SpriteOutput(1)
DC2=SpriteOutput(2)
StartDrawing(DC1)
  ; zeichenoperationen hier
StopDrawing()

StartDrawing(DC2)
  ; zeichenoperationen hier
StopDrawing()
So geht das 100%ig nicht, weil SpriteOutput() kein DC zurückgibt, sondern eine Struktur, die wie folgt aussieht:

Code: Alles auswählen

  Structure DrawingInfoStruct
  	Type.l    ; Type of the DC
  	Window.l  ; Window associated to the DC (if any)
  	DC.l      ; DC
  	ReleaseProcedure.l ; Address to a procedure to release the DC when StopDrawing() is called 
  	PixelBuffer.l      ; Address of the memory pixel buffer (DirectX)
  	Pitch.l            ; Pitch
  	Width.l
  	Height.l
  	Depth.l
  EndStructure
Sprich du musst das DC aus der Struktur auslesen.

Verfasst: 15.04.2006 20:46
von blbltheworm
OK, geht es auch einfacher als so:

Code: Alles auswählen

  LoadSprite(0, "pic.bmp")
  tmpMem=AllocateMemory(SizeOf(DrawingInfoStruct))
  tmpMem=SpriteOutput(0)
  
  CopyMemory(tmpMem,@sInfo1,SizeOf(DrawingInfoStruct))

  Debug "Type: " + Str(sInfo1\Type)
  Debug "Window: " + Str(sInfo1\Window)
  Debug "DC: " + Str(sInfo1\DC)
  Debug "Width: " + Str(sInfo1\Width)
  Debug "Height: " + Str(sInfo1\Height)
Denn einfach

Code: Alles auswählen

@sInfo1=SpriteOutput(0)
geht nicht.

Und wie komm ich an den DC von Images??

Anmerkung:
nach SpriteOutput(0) tut DisplaySprite nicht mehr

Verfasst: 15.04.2006 23:59
von ABBKlaus
nun in etwa so :

Code: Alles auswählen

Procedure.s X_GetLastError()
  err=GetLastError_()
  buffer.l=0
  ferr=FormatMessage_(#FORMAT_MESSAGE_ALLOCATE_BUFFER|#FORMAT_MESSAGE_FROM_SYSTEM,0,err,GetUserDefaultLangID_(),@buffer,0,0)
  If buffer<>0
    errormsg$=PeekS(buffer)
    LocalFree_(buffer)
    errormsg$=RemoveString(errormsg$,Chr(13)+Chr(10))
    ProcedureReturn errormsg$
  EndIf
EndProcedure

Structure DRAWINGINFO
  Type.l    ; Type of the DC 
  Window.l  ; Window associated to the DC (if any) 
  DC.l      ; DC 
  ReleaseProcedure.l ; Address to a procedure to release the DC when StopDrawing() is called 
  PixelBuffer.l      ; Address of the memory pixel buffer (DirectX) 
  Pitch.l            ; Pitch 
  Width.l 
  Height.l 
  Depth.l 
EndStructure 

#Window_Main=0
If OpenWindow(#Window_Main,0,0,200,200,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered,"Windowtest")
  If CreateGadgetList(WindowID(#Window_Main))
    ImageGadget(1,0,0,100,100,0)
    ButtonGadget(2,10,110,30,20,"45°",#PB_Button_Toggle)
    SetTimer_(WindowID(#Window_Main),1,300,0) 
  EndIf 
EndIf 

img1=CreateImage(#PB_Any,100,100)
img2=CreateImage(#PB_Any,100,100)

UseImage(img1)
*struc1.DRAWINGINFO=ImageOutput()
Debug PeekL(*struc1+8)
DC1=StartDrawing(*struc1) 
  Debug DC1
  ; zeichenoperationen hier 
  Line(0,0,100,100,#White)
StopDrawing() 
Debug PeekL(*struc1+8)

UseImage(img2)
*struc2.DRAWINGINFO=ImageOutput()
Debug PeekL(*struc2+8)
DC2=StartDrawing(*struc2) 
  Debug DC2
  ; zeichenoperationen hier 
  Line(100,0,-100,100,#White)
StopDrawing() 
Debug PeekL(*struc2+8)
 
SetGadgetState(1,UseImage(img1))

Repeat 
  WindowEvent=WaitWindowEvent()
  EventType=EventType()
  EventGadgetID=EventGadgetID()
  Select WindowEvent
    Case #PB_Event_Gadget
      Select EventType
        Case #PB_EventType_LeftClick
          Select EventGadgetID
            Case 1 ; Image
              Debug "ImageGadget"
              index+1
              If index>1
                index=0
              EndIf
              Select index
                Case 0
                  SetGadgetState(1,UseImage(img1))
                Case 1
                  SetGadgetState(1,UseImage(img2))
              EndSelect
            Case 2 ; Button
              res=BitBlt_(DC2,0,0,100,100,DC1,0,0,#SRCCOPY)
              If res=0
                Debug Str(res)+" "+X_GetLastError()
              EndIf
          EndSelect
      EndSelect
  EndSelect
Until WindowEvent=#PB_Event_CloseWindow
PS: der bitblt funktioniert nicht !?

Verfasst: 22.04.2006 15:46
von FGK
@ABBKlaus

ich vermute das BitBlt_ nicht geht weil man
entgegen Spriteoutput() mit ImageOutput() das hDC erhällt.
D.h. nur für Sprites brauchst du die Stuktur DrawingInfo

Code: Alles auswählen

hDC  = StartDrawing(ImageOutput())
sollte also den hDC des Images liefern


Gruß FGK

[EDIT]

Habs auf meine Weise ausprobiert und ging auch nicht! Hmmm :oops:

[EDIT2]

Hab im Archiv gelesen die hDC sind nur bis StopDrawing() gültig?!