OpenWindow MP_Graphics3DWindow cohabitation

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
jmg49
Messages : 153
Inscription : mer. 26/févr./2014 8:53

OpenWindow MP_Graphics3DWindow cohabitation

Message par jmg49 »

Bonjour,

j'essaie de créer une fenêtre avec des gadgets et un ecran pour afficher un starfield,

j'utilise la lib MP3D pour le starfield car c'est le plus simple,

au moment d'interchanger les buffers graphiques, ma fenêtre et mes gadgets ne sont plus visibles.... si j'enlève les MP_RenderWolrd et MP_Flip()

je vois bien ma fenêtre avec mes texts et boutons ....

connaissez vous un moyen de faire fonctionner les deux en même temps ?

je mets le source , un patcher pour fichier .exe (ou autre) , vous entrez votre offset en décimal ainsi que la valeur décimale à affecter .

Merci, edit : amélioration , j'ai le starfield dessous la fenetre principale .....si je la bouge, je le vois

Code : Tout sélectionner


IncludeFile "fmodex-min.pbi"

#FMOD_OPENMEMORY  = $00000800


Enumeration
  #chiptune
  #scroll
  #wmain
  #wmain2
EndEnumeration

Structure FMOD_CREATESOUNDEXINFO
  cbsize.i      
  length.i       
  params.i[32]   
EndStructure

Global fmodsystem.i, Channel.i, i.i, j.i
Global Dim Sounds(1)
Define szFile.s
Define szOut.s
Define dwSize.l
Define lFF.l
Define Text_offsetV.i 

InitSprite()
EP_InitFXLib() 


MP_Graphics3DWindow(150,50,450,170,"", #PB_Window_ScreenCentered| #PB_Window_BorderLess)
OpenWindow(#wmain,150,50,500,360,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit", #PB_Window_ScreenCentered)
;

SetWindowColor(#wmain,RGB(14, 10, 100))

;OpenWindowedScreen(WindowID(0),10,120,480,180)









Text_File = TextGadget(#PB_Any, 150, 15, 290, 20, "", #PB_Text_Border)
Text_f1= TextGadget(#PB_Any, 50, 20, 30, 20, "File")
SetGadgetColor(Text_f1,#PB_Gadget_FrontColor,RGB(154, 154, 154))
SetGadgetColor(Text_f1,#PB_Gadget_BackColor,RGB(14, 10, 100))


Text_offsetC= TextGadget(#PB_Any, 50, 50, 90, 20, "Decimal Offset :")
SetGadgetColor(Text_offsetC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_offsetC,#PB_Gadget_FrontColor,RGB(154, 154, 154))

Text_offsetV= EditorGadget(#PB_Any, 150, 45, 90, 20)

Text_valueC=TextGadget(#PB_Any, 50, 80, 90, 20, "Decimal Value :")
SetGadgetColor(Text_valueC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_valueC,#PB_Gadget_FrontColor,RGB(154, 154, 154))


Text_valueV =EditorGadget(#PB_Any, 150, 75, 90, 20)
Button_SelectFile = ButtonGadget(#PB_Any, 50, 320, 140, 20, "Select File")
Button_PatchFile = ButtonGadget(#PB_Any, 310, 320, 140, 20, "Patch File")


EP_Init2DStars(200,7,1.3,0,0,640,480)
EP_2DStarsColor(1,RGB(255,0,0))
EP_2DStarsColor(2,RGB(0,255,0))



Procedure FMOD_DataSectionLoadSound(SoundId, SoundLocStart, SoundLocEnd)   
  Protected exinfo.FMOD_CREATESOUNDEXINFO
  
  exinfo\cbSize = SizeOf(FMOD_CREATESOUNDEXINFO)
  exinfo\Length = SoundLocEnd - SoundLocStart 
  
  FMOD_System_CreateStream(FmodSystem, SoundLocStart, #FMOD_SOFTWARE | #FMOD_OPENMEMORY, @exinfo, @Sounds(SoundId))
EndProcedure



Procedure.l Patch(file.s,location.l,byte.b)
  If OpenFile(0,file)
    FileSeek(0,location)
    WriteData(0,@byte,1)
    CloseFile(0)
    ProcedureReturn 1
  EndIf
EndProcedure





;----------------Init sound First Part-------------------------------------------------
first:

FMOD_System_Create(@fmodsystem)
FMOD_System_Init(fmodsystem, 32, #FMOD_INIT_NORMAL, 0)
FMOD_DataSectionLoadSound(0, ?chiptune, ?endchiptune)

FMOD_System_PlaySound(fmodsystem, #FMOD_CHANNEL_FREE, Sounds(0), 0, @channel)





Repeat
  
  ;event=WindowEvent()
      EP_2DStarsDraw()   

  Select WindowEvent()

    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case Button_SelectFile
          szFile = OpenFileRequester("Select file to patch", "", "*.*", 0)
          If szFile
            SetGadgetText(Text_File, szFile)
          Else
          EndIf
          
          
        Case Button_PatchFile      
          offValue=  Val(GetGadgetText(Text_offsetV))
          byteValue = Val(GetGadgetText(Text_valueV))
          
          
          
          
          
         ; Debug offValue           
        ; Debug byteValue
          
          Patch(szFile, offValue, byteValue )
          
          
          MessageRequester("Info"," File patched successfully ! ...")
          
          
          
          
      EndSelect
  EndSelect
  
  
 MP_RenderWorld() 
 MP_Flip ()       
  
Until GetAsyncKeyState_(#VK_ESCAPE)  



DataSection
  chiptune:
  IncludeBinary "chiptune1.mp3"
  endchiptune:
EndDataSection



edit : avec :

Code : Tout sélectionner

hwnd =OpenWindow(#wmain,150,50,500,360,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit", #PB_Window_ScreenCentered)
MP_ScreenToHandle(hwnd)

la lib MP prend bien la fenêtre entière comme écran pour afficher le starfield,

donc j'ouvre une 2 ème fenêtre et je bind la lib MP avec celle-ci , c'est mieux j'ai bien le starfield où je le veux mais les gadgets de la première ne s'affichent pas ...
hwnd =OpenWindow(#wmain,150,50,500,360,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit", #PB_Window_ScreenCentered)

hwnd2= OpenWindow(#wmain2,150,50,480,180,"", #PB_Window_ScreenCentered | #PB_Window_BorderLess)

MP_ScreenToHandle(hwnd2)

1ère fenetre plus 1 OpenWindowedScreen(WindowID(#wmain),10,120,480,180) : bien placé mais erreur mémoire quand MP_flip()

Image
[/img]

avec
hwnd =OpenWindow(#wmain,150,50,500,360,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit", #PB_Window_ScreenCentered)

hwnd2= OpenWindow(#wmain2,150,50,480,180,"", #PB_Window_ScreenCentered | #PB_Window_BorderLess)

MP_ScreenToHandle(hwnd2)
Starfield ok , mais plus de gadgets ...

Image
[/img]
jmg49
Messages : 153
Inscription : mer. 26/févr./2014 8:53

Re: OpenWindow MP_Graphics3DWindow cohabitation

Message par jmg49 »

On avance doucement, beaucoup mieux, il fallait que j'affiche les gadgets avant l'autre écran , le starfield est bien là , mais il se place derrière la fenêtre quand je clic sur un bouton ...


Image
[/img]

Code : Tout sélectionner


IncludeFile "fmodex-min.pbi"

#FMOD_OPENMEMORY  = $00000800


Enumeration
  #chiptune
  #scroll
  #wmain
  #wmain2
  
EndEnumeration

Structure FMOD_CREATESOUNDEXINFO
  cbsize.i      
  length.i       
  params.i[32]   
EndStructure

Global fmodsystem.i, Channel.i, i.i, j.i
Global Dim Sounds(1)
Define szFile.s
Define szOut.s
Define dwSize.l
Define lFF.l
Define Text_offsetV.i 

xpos=650
ypos=350

xpos2=660
ypos2=470

width=500
height=360


width2=480
height2=180



InitSprite()
EP_InitFXLib() 



hwnd =OpenWindow(#wmain,xpos,ypos,width,height,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit",#PB_Window_BorderLess )
SetWindowColor(#wmain,RGB(14, 10, 100))


Text_File = TextGadget(#PB_Any, 150, 15, 290, 20, "", #PB_Text_Border)
Text_f1= TextGadget(#PB_Any, 50, 20, 30, 20, "File")
SetGadgetColor(Text_f1,#PB_Gadget_FrontColor,RGB(154, 154, 154))
SetGadgetColor(Text_f1,#PB_Gadget_BackColor,RGB(14, 10, 100))


Text_offsetC= TextGadget(#PB_Any, 50, 50, 90, 20, "Decimal Offset :")
SetGadgetColor(Text_offsetC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_offsetC,#PB_Gadget_FrontColor,RGB(154, 154, 154))

Text_offsetV= EditorGadget(#PB_Any, 150, 45, 90, 20)

Text_valueC=TextGadget(#PB_Any, 50, 80, 90, 20, "Decimal Value :")
SetGadgetColor(Text_valueC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_valueC,#PB_Gadget_FrontColor,RGB(154, 154, 154))


Text_valueV =EditorGadget(#PB_Any, 150, 75, 90, 20)
Button_SelectFile = ButtonGadget(#PB_Any, 50, 320, 140, 20, "Select File")
Button_PatchFile = ButtonGadget(#PB_Any, 310, 320, 140, 20, "Patch File")









hwnd2= OpenWindow(#wmain2,xpos2,ypos2,width2,height2,"",  #PB_Window_BorderLess)








MP_ScreenToHandle(hwnd2)








EP_Init2DStars(200,7,1.3,0,0,640,480)
EP_2DStarsColor(1,RGB(255,0,0))
EP_2DStarsColor(2,RGB(0,255,0))



Procedure FMOD_DataSectionLoadSound(SoundId, SoundLocStart, SoundLocEnd)   
  Protected exinfo.FMOD_CREATESOUNDEXINFO
  
  exinfo\cbSize = SizeOf(FMOD_CREATESOUNDEXINFO)
  exinfo\Length = SoundLocEnd - SoundLocStart 
  
  FMOD_System_CreateStream(FmodSystem, SoundLocStart, #FMOD_SOFTWARE | #FMOD_OPENMEMORY, @exinfo, @Sounds(SoundId))
EndProcedure



Procedure.l Patch(file.s,location.l,byte.b)
  If OpenFile(0,file)
    FileSeek(0,location)
    WriteData(0,@byte,1)
    CloseFile(0)
    ProcedureReturn 1
  EndIf
EndProcedure





;----------------Init sound First Part-------------------------------------------------
first:

FMOD_System_Create(@fmodsystem)
FMOD_System_Init(fmodsystem, 32, #FMOD_INIT_NORMAL, 0)
FMOD_DataSectionLoadSound(0, ?chiptune, ?endchiptune)

FMOD_System_PlaySound(fmodsystem, #FMOD_CHANNEL_FREE, Sounds(0), 0, @channel)





Repeat
  
  ;event=WindowEvent()
      EP_2DStarsDraw()   

  Select WindowEvent()

    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case Button_SelectFile
          szFile = OpenFileRequester("Select file to patch", "", "*.*", 0)
          If szFile
            SetGadgetText(Text_File, szFile)
          Else
          EndIf
          
          
        Case Button_PatchFile      
          offValue=  Val(GetGadgetText(Text_offsetV))
          byteValue = Val(GetGadgetText(Text_valueV))
          
          
          
          
          
         ; Debug offValue           
        ; Debug byteValue
          
          Patch(szFile, offValue, byteValue )
          
          
          MessageRequester("Info"," File patched successfully ! ...")
          
          
          
          
      EndSelect
  EndSelect
  
  
 MP_RenderWorld() 
 MP_Flip ()       
  
Until GetAsyncKeyState_(#VK_ESCAPE)  



DataSection
  chiptune:
  IncludeBinary "chiptune1.mp3"
  endchiptune:
EndDataSection


Avatar de l’utilisateur
Zorro
Messages : 2186
Inscription : mar. 31/mai/2016 9:06

Re: OpenWindow MP_Graphics3DWindow cohabitation

Message par Zorro »

Tu peux faire comme ça éventuellement , (sans Librairie)

Code : Tout sélectionner


; Starfield
; By Dobro
; purebasic 4.00
#Police=1
#etoile=100

Enumeration ; les Gadgets		
		#Gadget_bouton1
		#Gadget_bouton2
		#sortie
EndEnumeration


Declare create_etoile3D()
;-creation etoiles
Structure etoile
		x.i
		Y.i 
		z.f
		pas.i
		couleur.i
EndStructure
Global Dim etoile.etoile(1000)



If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
		MessageBox_ (0,"Can't open DirectX 7 or later", "blahhhh", #MB_ICONINFORMATION|#MB_OK)
		End
EndIf
; ***********************************
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
ExamineDesktops()
Global EcranX =800 ; DesktopWidth(0) ; GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
Global EcranY =200 ; DesktopHeight(0) ;GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, 800, 600 , "hello",  #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered ) 
WindowID = WindowID(1) 
If OpenWindowedScreen(WindowID,0,200,EcranX,EcranY,0,0,0) = 0  ; l'emplacement de l'ecran
		End 
EndIf

ButtonGadget(#Gadget_bouton1, 50,500,100,30 ,"bouton1 exemple")
ButtonGadget(#Gadget_bouton2, 250,500,100,30 ,"bouton2 exemple")
TextGadget(#sortie,400,10,100,30,"")
SetFrameRate(60) 


create_etoile3D() ; precalcul de la position des etoiles dans une matrice 3D


Repeat 
		Event=WaitWindowEvent(10)   
		Select Event
				Case #PB_Event_Gadget ; on a cliqué un gadget ??
				Select EventGadget()						
						Case #Gadget_bouton1						
						SetGadgetText(#sortie, "bouton1")
						Case #Gadget_bouton2						
						SetGadgetText(#sortie, "bouton2")
				EndSelect
		EndSelect
		
		
		; *** Focale (transformation 3D->2D) ***
		;x' = (FOCALE * x) / z
		;Y' = (FOCALE * y) / z 
		;FOCALE représente la distance se trouvant entre le regard de l'utilisateur et la scène 3D.
		;Plus cette constante sera proche de 0, Plus le regard sera loin de la scène. 
		; ***********************************
		Speed=3
		FOCALE=300
		
		For i=1 To 1000
				etoile(i)\z=etoile(i)\z-Speed
				If etoile(i)\z<=1
						etoile(i)\z=1000   
				EndIf 
				
				; ********** projection ********************************
				xProjected = (FOCALE * etoile(i)\x) / etoile(i)\z+EcranX/2
				yProjected  = (FOCALE * etoile(i)\Y) / etoile(i)\z+ EcranY/2
				DisplayTransparentSprite(#etoile+i, xProjected,yProjected)
				; ****************************************************
				
		Next i
		
		
		
		
		
		FlipBuffers():; affiche l'ecran
		ClearScreen(RGB(0, 0, 0)) :;efface l'ecran
		
Until Event=#PB_Event_CloseWindow 

Procedure create_etoile3D()
		;-Creation des 1000 etoiles 3D
		;By Dobro
		For i=1 To 1000
				etoile(i)\x=-EcranX/2 + (Random(EcranX) + 1) 
				etoile(i)\Y=-EcranY/2 + (Random(EcranY) + 1) 
				etoile(i)\z=Random(1000)+1
				etoile(i)\pas=(Random(3)+1)*2
				etoile(i)\couleur=RGB(Random(255),Random(255),Random(255)) ; couleur des etoiles
				CreateSprite(#etoile+i,2,2)
				StartDrawing(SpriteOutput(#etoile+i))
						Circle(2,2,4,etoile(i)\couleur)
				StopDrawing()
		Next i
		
		
EndProcedure



Avatar de l’utilisateur
Zorro
Messages : 2186
Inscription : mar. 31/mai/2016 9:06

Re: OpenWindow MP_Graphics3DWindow cohabitation

Message par Zorro »

j'ai reedité le code ;)
jmg49
Messages : 153
Inscription : mer. 26/févr./2014 8:53

Re: OpenWindow MP_Graphics3DWindow cohabitation

Message par jmg49 »

Merci ça fonctionne très bien ,

j'ai fixé les différents problèmes de mon code :

- EditorGadget ne s'afficher plus après la séquence de fade-in sur les fenêtres et l' API API AnimateWindow_() , conservé juste pour la fenêtre sans editors
- Ajout d'un simple WindowEvent() en début de la boucle principale pour conserver le starfield quand on clique sur les bouttons
- Ajout SetWindowPos_(WindowID(#wmain2),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) après la séquence OpenRequester pour rappeler le starfield une fois l'opération terminée

Code : Tout sélectionner


IncludeFile "fmodex-min.pbi"

#FMOD_OPENMEMORY  = $00000800
#AW_BLEND = $80000  

Enumeration
  #chiptune
  #scroll
  #wmain
  #wmain2
  
EndEnumeration

Structure FMOD_CREATESOUNDEXINFO
  cbsize.i      
  length.i       
  params.i[32]   
EndStructure

Global fmodsystem.i, Channel.i, i.i, j.i
Global Dim Sounds(1)
Define szFile.s
Define szOut.s
Define dwSize.l
Define lFF.l
Define Text_offsetV.i 

xpos=650
ypos=350

xpos2=660
ypos2=470

width=500
height=360


width2=480
height2=180

EP_InitFXLib() 

;------------------Init Windows and gadgets -------------------------------------------------------

hwnd =OpenWindow(#wmain,xpos,ypos,width,height,"Single .EXE Dynamic patcher Jmg@2017 Esc to quit",#PB_Window_BorderLess )
SetWindowColor(#wmain,RGB(14, 10, 100))


Text_File = TextGadget(#PB_Any, 150, 15, 290, 20, "", #PB_Text_Border)
Text_f1= TextGadget(#PB_Any, 50, 20, 30, 20, "File")
SetGadgetColor(Text_f1,#PB_Gadget_FrontColor,RGB(154, 154, 154))
SetGadgetColor(Text_f1,#PB_Gadget_BackColor,RGB(14, 10, 100))

Text_offsetC= TextGadget(#PB_Any, 50, 53, 90, 20, "Decimal Offset :")
SetGadgetColor(Text_offsetC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_offsetC,#PB_Gadget_FrontColor,RGB(154, 154, 154))

Text_valueC=TextGadget(#PB_Any, 50, 83, 90, 20, "Decimal Value :")
SetGadgetColor(Text_valueC,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_valueC,#PB_Gadget_FrontColor,RGB(154, 154, 154))

Button_SelectFile = ButtonGadget(#PB_Any, 50, 320, 140, 20, "Select File")
Button_PatchFile = ButtonGadget(#PB_Any, 310, 320, 140, 20, "Patch File")

Text_offsetV= EditorGadget(#PB_Any, 150, 50, 90, 20)
SetGadgetColor(Text_offsetV,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_offsetV,#PB_Gadget_FrontColor,RGB(154, 154, 154))

Text_valueV =EditorGadget(#PB_Any, 150, 80, 90, 20)
SetGadgetColor(Text_valueV,#PB_Gadget_BackColor,RGB(14, 10, 100))
SetGadgetColor(Text_valueV,#PB_Gadget_FrontColor,RGB(154, 154, 154))


hwnd2= OpenWindow(#wmain2,xpos2,ypos2,width2,height2,"",  #PB_Window_BorderLess | #PB_Window_Invisible )
SetWindowColor(#wmain2, RGB(0, 0, 0))

MP_ScreenToHandle(hwnd2)  ; set MPlib to handle hwnd2 screen


EP_Init2DStars(200,7,1.3,0,0,640,480)
EP_2DStarsColor(1,RGB(255,0,0))
EP_2DStarsColor(2,RGB(0,255,0))
EP_CatchFont16(1,?font,?endfont)
EP_SetScrollText(1, " Press ESC to Exit....")
EP_Create16Scroll(1, 1, 1, 75)
EP_SetScroll16Speed(1, 3)

Procedure FMOD_DataSectionLoadSound(SoundId, SoundLocStart, SoundLocEnd)   ; extract .mp3 from DataSection directly to memory
  Protected exinfo.FMOD_CREATESOUNDEXINFO
  
  exinfo\cbSize = SizeOf(FMOD_CREATESOUNDEXINFO)
  exinfo\Length = SoundLocEnd - SoundLocStart 
  
  FMOD_System_CreateStream(FmodSystem, SoundLocStart, #FMOD_SOFTWARE | #FMOD_OPENMEMORY, @exinfo, @Sounds(SoundId))
EndProcedure


Procedure.l Patch(file.s,location.l,byte.b)
  If OpenFile(0,file)
    FileSeek(0,location)
    WriteData(0,@byte,1)
    CloseFile(0)
    ProcedureReturn 1
  EndIf
EndProcedure





;----------------Init sound ------------------------------------------------------------------------


FMOD_System_Create(@fmodsystem)
FMOD_System_Init(fmodsystem, 32, #FMOD_INIT_NORMAL, 0)
FMOD_DataSectionLoadSound(0, ?chiptune, ?endchiptune)

FMOD_System_PlaySound(fmodsystem, #FMOD_CHANNEL_FREE, Sounds(0), 0, @channel)

;--------------------------------------------------------------------------------------------------






AnimateWindow_(WindowID(#wmain2),800,#AW_BLEND) ; fade in window#2
HideWindow(#wmain2, #False)


;-------------------------------------------------------------------------------------------------- 

Repeat
  
  WindowEvent()
  
  EP_2DStarsDraw()   
  EP_Move16Scroll(1)
  MP_VSync(1)
  Select WindowEvent()
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
        Case Button_SelectFile
          szFile = OpenFileRequester("Select file to patch", "", "*.*", 0)
          If szFile
            SetGadgetText(Text_File, szFile)
            SetWindowPos_(WindowID(#wmain2),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE) 
          Else
          EndIf
          
          
        Case Button_PatchFile      
          offValue=  Val(GetGadgetText(Text_offsetV))
          byteValue = Val(GetGadgetText(Text_valueV))
          
          
          Patch(szFile, offValue, byteValue )
          
          
          MessageRequester("Info"," File patched successfully ! ...")
          
          
      EndSelect
  EndSelect
  
  
  
  MP_RenderWorld() 
  MP_Flip ()       
  
Until GetAsyncKeyState_(#VK_ESCAPE)  



DataSection
  chiptune:
  IncludeBinary "chiptune1.mp3"
  endchiptune:
  font:
  IncludeBinary "fnt1.bmp"
  endfont:
EndDataSection



Répondre