Publié : dim. 01/oct./2006 19:11
Ta pas mis mon BumpMapping2D
@++

@++

Code : Tout sélectionner
Macro BGR(Blue,Green,Red)
RGB(Blue,Green,Red)
EndMacro
Procedure OpenScreen2DFX(SizeX.l,SizeY.l)
Global *SCREEN.l = AllocateMemory((SizeX*SizeY)*4)
Global *Blur_byte.b = AllocateMemory(SizeX*SizeY)
Global ScreenX.l = SizeX
Global ScreenY.l = SizeY
Global TransparentColor.l = 0
Global DB.l,DBP.l,PF.l
If *SCREEN=0 Or *Blur_byte=0
MessageRequester("erreur","pas assez de mémoire vive, "+Str( ((SizeX*SizeY)*4)+(SizeX*SizeY) )+" bytes" )
EndIf
If InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or OpenScreen(SizeX,SizeY,32,"")=0
MessageRequester("erreur","pb directx")
EndIf
StartDrawing(ScreenOutput())
DB = DrawingBuffer()
DBP = DrawingBufferPixelFormat()
Select DBP
Case #PB_PixelFormat_8Bits : PF=1
Case #PB_PixelFormat_15Bits : PF=2
Case #PB_PixelFormat_16Bits : PF=2
Case #PB_PixelFormat_24Bits_RGB : PF=3
Case #PB_PixelFormat_24Bits_BGR : PF=3
Case #PB_PixelFormat_32Bits_RGB : PF=4
Case #PB_PixelFormat_32Bits_BGR : PF=4
EndSelect
StopDrawing()
EndProcedure
Procedure FlipBuffers2DFX()
Protected Color.l
StartDrawing(ScreenOutput())
DB = DrawingBuffer()
For Y = 0 To ScreenY-1
For x = 0 To ScreenX-1
Color = PeekL(*SCREEN+ (x*PF) + ScreenX * (Y*PF))
PokeL(DB + (x*PF) + ScreenX * (Y*PF),Color)
If Color<>TransparentColor
PokeB(*Blur_byte+x+ScreenX*Y,1)
EndIf
If Color=TransparentColor
PokeB(*Blur_byte+x+ScreenX*Y,0)
EndIf
Next
Next
StopDrawing()
FlipBuffers()
EndProcedure
Procedure BlurPixel(x.l,Y.l,offset.l=1)
Protected _11.l,_12.l,_13.l,_14.l,_15.l,_16.l,_17.l,_18.l
Protected _21.l,_22.l,_23.l,_24.l,_25.l,_26.l,_27.l,_28.l
Protected Myn.f,r.l,v.l,b.l
If x>0 And Y>0 And x<ScreenX-1 And Y<ScreenY-1
_11 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y-1)*PF))
r+Red(_11) : v+Green(_11) : b+Blue(_11)
_12 = PeekL(*SCREEN+ ((x)*PF) + ScreenX * ((Y-1)*PF))
r+Red(_12) : v+Green(_12) : b+Blue(_12)
_13 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y-1)*PF))
r+Red(_13) : v+Green(_13) : b+Blue(_13)
_14 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y)*PF))
r+Red(_14) : v+Green(_14) : b+Blue(_14)
_15 = PeekL(*SCREEN+ ((x+1)*PF) + ScreenX * ((Y+1)*PF))
r+Red(_15) : v+Green(_15) : b+Blue(_15)
_16 = PeekL(*SCREEN+ ((x)*PF) + ScreenX * ((Y+1)*PF))
r+Red(_16) : v+Green(_16) : b+Blue(_16)
_17 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y+1)*PF))
r+Red(_17) : v+Green(_17) : b+Blue(_17)
_18 = PeekL(*SCREEN+ ((x-1)*PF) + ScreenX * ((Y)*PF))
r+Red(_18) : v+Green(_18) : b+Blue(_18)
r/8 : v/8 : b/8
r-offset
v-offset
b-offset
If r<10 : r=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0) : EndIf
If v<10 : v=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0) : EndIf
If b<10 : b=TransparentColor : PokeL(*Blur_byte+x+ScreenX*Y,0): EndIf
If Y>2
Myn = BGR(r,v,b): PokeL(*SCREEN+ (x*PF) + ScreenX * ((Y-2)*PF),Myn)
EndIf
PokeB(*Blur_byte+x+ScreenX*(Y),1)
;PokeB(*Blur_byte+(x-1)+ScreenX*(Y-1),1)
PokeB(*Blur_byte+(x)+ScreenX*(Y-1),1)
;PokeB(*Blur_byte+(x+1)+ScreenX*(Y-1),1)
PokeB(*Blur_byte+(x+1)+ScreenX*(Y),1)
;PokeB(*Blur_byte+(x+1)+ScreenX*(Y+1),1)
PokeB(*Blur_byte+(x)+ScreenX*(Y+1),1)
;PokeB(*Blur_byte+(x-1)+ScreenX*(Y+1),1)
PokeB(*Blur_byte+(x-1)+ScreenX*(Y),1)
EndIf
EndProcedure
Procedure FastPixel(x.l,Y.l,Color.l)
If x=>0 And x<ScreenX-1 And Y=>0 And Y<ScreenY-1
PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Color)
PokeB(*Blur_byte+x+ScreenX*Y,1)
EndIf
EndProcedure
Procedure ClearScreen2DFX(Color.l)
For Y = 0 To ScreenY-1
For x = 0 To ScreenX-1
If PeekL(*SCREEN+ ((x)*4) + ScreenX * ((Y)*4)) = TransparentColor
PokeL( *SCREEN+ ((x)*4) + ScreenX * ((Y)*4),0)
PokeB(*Blur_byte+x+ScreenX*Y,0)
EndIf
Next
Next
EndProcedure
Procedure lineXY2DFX(x1.f,y1.f,x2.f,y2.f,Couleur.l)
Shared dx.f,dy.f,xincr.l,yincr.l,x.l,Y.l,erreur.f
If x1<>0 And y1<>0 And x2<>0 And y2<>0
dx = Abs(x2-x1)
dy = Abs(y2-y1)
If x1<x2
xincr = 1
Else
xincr = -1
EndIf
If y1<y2
yincr = 1
Else
yincr = -1
EndIf
;/* Trace de ligne */
x = x1
Y = y1
If dx>dy
erreur = dx/2 ; /* c'est plus esthetique comme ca */
For i= 0 To dx
x = x+xincr;
erreur = erreur+dy
If erreur > dx
erreur = erreur - dx
Y = Y+yincr
EndIf
If x>0 And x<ScreenX-1 And Y>0 And Y<ScreenY-1
PokeB(*Blur_byte+x+ScreenX*Y,1)
PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Couleur)
EndIf
Next i
Else
erreur = dy/2; /* c'est plus esthetique comme ca */
For i=0 To dy
Y = Y + yincr
erreur = erreur + dx
If erreur>dy
erreur = erreur - dy
x = x + xincr
EndIf
If x>0 And x<ScreenX-1 And Y>0 And Y<ScreenY-1
PokeB(*Blur_byte+x+ScreenX*Y,1)
PokeL(*SCREEN+ (x*PF) + ScreenX * (Y*PF),Couleur)
EndIf
Next i
EndIf
EndIf
EndProcedure
Procedure Circle2DFX(x.f,Y.f,Radius.l,Couleur.l)
For i = 0 To 360
Tx.l = x+Radius*Cos(i*#PI/180)
Ty.l = Y+Radius*Sin(i*#PI/180)
If Tx>0 And Tx<ScreenX-1 And Ty>0 And Ty<ScreenY-1
PokeL(*SCREEN+ (Tx*PF) + ScreenX * (Ty*PF),Couleur)
EndIf
Next
EndProcedure
OpenScreen2DFX(640,480)
Repeat
ExamineKeyboard() : ExamineMouse()
ClearScreen2DFX(BGR(0,0,0))
a.f+1
b.f+1
P1x = 200 + 80 * Cos(a*#PI/180)
P1y = 200 + 80 * Sin(a*#PI/180)
P2x = 320 + 120 * Cos(-b*#PI/180)
P2y = 240 + 80 * Sin(-b*#PI/180)
P3x = 320 + 80 * Cos(b*#PI/180)
P3y = 320 + 80 * Sin(b*#PI/180)
; For i = 1 To 10
; Circle2DFX(MouseX(),MouseY(),i,BGR(255-(i*25),255-(i*25),255))
; Next
;
For i = -2 To 2
lineXY2DFX(P1x+i,P1y+i,P2x+i,P2y+i,BGR(Random(255),0,0))
lineXY2DFX(P2x+i,P2y+i,P3x+i,P3y+i,BGR(0,Random(255),0))
lineXY2DFX(P3x+i,P3y+i,P1x+i,P1y+i,BGR(0,0,128+Random(128)))
Next
If DelayToBlur.l <ElapsedMilliseconds()
DelayToBlur = ElapsedMilliseconds()+75
For Y = 0 To ScreenY-1
For x = 0 To ScreenX-1
If PeekB(*Blur_byte+x+ScreenX*Y)<>0
BlurPixel(x,Y,Random(10))
EndIf
Next
Next
EndIf
FlipBuffers2DFX()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
Code : Tout sélectionner
#w = 480;320
#h = 360;240
#x = 0
#y = 0
If OpenWindow(0, 0, 0, #w + 1, #h + 1, "Pixel manipulation", #PB_Window_ScreenCentered | #PB_Window_SystemMenu) And InitSprite()
If OpenWindowedScreen(WindowID(0), 0, 0, #w + 1, #h + 1, 0, 0, 0) = 0
MessageRequester("Attention", "Impossible de créer l'écran")
End
EndIf
Else
MessageRequester("Attention", "Impossible de créer la fenêtre ou d'initialiser les sprites")
End
EndIf
; InitSprite()
InitKeyboard()
KeyboardMode(1)
; If OpenScreen(320, 240, 32, "") = 0
; If OpenScreen(320, 240, 24, "") = 0
; MessageRequester("", "Echec de la création du screen")
; EndIf
; EndIf
Global blue, coef = 100, add = -4
ProcedureDLL.f GameTimer(mode); mode=0 init , mode=1 close , mode=2 get time between two call of function (in ms) , mode=3 get fps , n'appeler qu'une seule fois le mode 2 et 3 dans une boucle
Shared _GT_DevCaps.TIMECAPS, StartTime.l, time.l, frames.l, fps.l
If mode = 0
timeGetDevCaps_(_GT_DevCaps, SizeOf(TIMECAPS))
timeBeginPeriod_(_GT_DevCaps\wPeriodMin)
StartTime = timeGetTime_()
time = StartTime
ElseIf mode = 1
timeEndPeriod_(_GT_DevCaps\wPeriodMin)
ElseIf mode = 2
multiplicator.f = StartTime
StartTime = timeGetTime_()
ProcedureReturn StartTime - multiplicator
ElseIf mode = 3
If timeGetTime_() - time >= 1000
time = timeGetTime_()
FPS = Frames - 1
Frames = 1
Else
Frames+1
EndIf
ProcedureReturn fps
EndIf
EndProcedure
Procedure.l start_drawing_to_buffer() ;---------(pour commancer le dessin sur Buffer)
Global PF.l
Global modec.l
Global DB.l
Global DBP.l
If StartDrawing(ScreenOutput())
DB = DrawingBuffer()
DBP = DrawingBufferPixelFormat()
Select DBP
Case #PB_PixelFormat_8Bits : PF=1:modec = -1; 1 octet par pixel, palettisé
Case #PB_PixelFormat_15Bits : PF=2:modec = 0; 2 octets par pixel
Case #PB_PixelFormat_16Bits : PF=2:modec = 0; 2 octets par pixel
Case #PB_PixelFormat_24Bits_RGB : PF=3:modec = 1; 3 octets par pixel (RRGGBB)
Case #PB_PixelFormat_24Bits_BGR : PF=3:modec = 2; 3 octets par pixel (BBGGRR)
Case #PB_PixelFormat_32Bits_RGB : PF=4:modec = 1; 4 octets par pixel (RRGGBB)
Case #PB_PixelFormat_32Bits_BGR : PF=4:modec = 2; 4 octets par pixel (BBGGRR)
EndSelect
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure.l convert_type_color_buffer(couleur.l) ;-----(pour les Conversions RRGGBB to BBGGRR) incomplet !!!
If modec = -1
;........
c.l = couleur
EndIf
If modec = 0
;........
c.l = couleur
EndIf
If modec = 1
;........
c.l = couleur
EndIf
If modec = 2
R.l = Red(couleur)
G.l = Green(couleur)
B.l = Blue(couleur)
If blue = 2
c.l = RGB(G,R,B)
ElseIf blue = 0
c.l = RGB(B,G,R)
ElseIf blue = 1
c = couleur
Else
c = (R + G + B) / 3
r1.d = ((100 - coef) * G + coef * R) / 100
g1.d = ((100 - coef) * R + coef * B) / 100
b1.d = ((100 - coef) * B + coef * G) / 100
c = RGB(r1, g1, b1)
EndIf
;c.l = couleur
EndIf
ProcedureReturn c.L
EndProcedure
Procedure draw_pixel_buffer(X.l , Y.l , Color.l) ;-----(dessine un pixel sur le Buffer)
Color = convert_type_color_buffer(Color)
PokeL(DB + (X * PF) + DrawingBufferPitch()* ( Y ) , Color )
EndProcedure
Dim screen(#w + 1, #h + 1)
GameTimer(0)
x = #w / 2
y = #h / 2
Structure Blob
x.l
y.l
angle.l
vit.l
dvit.l
ddvit.l
rot.l
drot.l
ddrot.l
EndStructure
Dim Blob.Blob(20)
For blob = 0 To 20
Blob(blob)\x = #w / 2
Blob(blob)\y = #h / 2
Next
total = 2
div.d = 6.5
rand.f = 5
fps = -1
Repeat
event = WaitWindowEvent(1)
ExamineKeyboard()
Delay(1)
If KeyboardReleased(#PB_Key_F1)
fps = -fps
EndIf
If KeyboardPushed(#PB_Key_Up)
total + 1
If total > 20 : total = 20 : EndIf
ElseIf KeyboardPushed(#PB_Key_Down)
total - 1
If total < 1 : total = 1 : EndIf
EndIf
If KeyboardPushed(#PB_Key_Right)
div + 0.1
If div > 10 : div = 10 : EndIf
ElseIf KeyboardPushed(#PB_Key_Left)
div - 0.1
If div < 5.5 : div = 5.5 : EndIf
EndIf
If KeyboardPushed(#PB_Key_A)
rand + 0.2
If rand > 10 : rand = 10 : EndIf
ElseIf KeyboardPushed(#PB_Key_Z)
rand - 0.2
If rand < 0 : rand = 0 : EndIf
EndIf
coef + add
SetWindowTitle(0, "Pixel manipulation - div=" + StrD(div, 1) + " - rand=" + StrF(rand, 1))
If coef = 0 Or coef = 100 : add = -add : EndIf
icoef = 100 - coef
;{ deplacements des blobs
For bo = 0 To total - 1
Blob(bo)\x = Blob(bo)\x + Blob(bo)\vit * Cos(Blob(bo)\angle * #PI / 180)
Blob(bo)\y = Blob(bo)\y + Blob(bo)\vit * Sin(Blob(bo)\angle * #PI / 180)
Blob(bo)\angle + Blob(bo)\rot
Blob(bo)\rot + Blob(bo)\drot
Blob(bo)\drot = Random(6) - 3
Blob(bo)\vit + Blob(bo)\dvit
Blob(bo)\dvit + Blob(bo)\ddvit
Blob(bo)\ddvit = Random(4) - 2
If Blob(bo)\rot > 10 : Blob(bo)\rot = 10 : EndIf
If Blob(bo)\rot < -10 : Blob(bo)\rot = -10 : EndIf
If Blob(bo)\drot > 5 : Blob(bo)\drot = 5 : EndIf
If Blob(bo)\drot < -5 : Blob(bo)\drot = -5 : EndIf
If Blob(bo)\angle < 0 : Blob(bo)\angle + 360 : EndIf
If Blob(bo)\angle > 360 : Blob(bo)\angle - 360 : EndIf
If Blob(bo)\vit > 6 : Blob(bo)\vit = 6 : EndIf
If Blob(bo)\vit < 2 : Blob(bo)\vit = 2 : EndIf
If Blob(bo)\dvit > 3 : Blob(bo)\dvit = 3 : EndIf
If Blob(bo)\dvit < -3 : Blob(bo)\dvit = -3 : EndIf
If Blob(bo)\x > 5 And Blob(bo)\x < #w And Blob(bo)\y > 5 And Blob(bo)\y < #h
For a = 1 To 4
For b = 1 To 4
screen(Blob(bo)\x - a, Blob(bo)\y - b) = 10000000
Next
Next
Else
If Blob(bo)\x < 5
Blob(bo)\x = 5
Blob(bo)\angle = -Blob(bo)\angle + 180
ElseIf Blob(bo)\x > #w
Blob(bo)\x = #w
Blob(bo)\angle = -Blob(bo)\angle + 180
EndIf
If Blob(bo)\y < 5
Blob(bo)\angle = -Blob(bo)\angle
Blob(bo)\y = 5
ElseIf Blob(bo)\y > #h
Blob(bo)\angle = -Blob(bo)\angle
Blob(bo)\y = #h
EndIf
EndIf
Next
;}
If start_drawing_to_buffer()
For a = 1 To #w
For b = 1 To #h
If screen(a, b)
If a < #w / 2 And a > 1 And b < #h / 2 And b > 1
blue = 1
ElseIf a > #w / 2 And a < #w And b > #h / 2 And b < #h
blue = 2
ElseIf a > #w / 2 And a < #w And b < #h / 2 And b > 1
blue = 0
Else
blue = 3
EndIf
If blue
draw_pixel_buffer(a + #x, b + #y, screen(a, b))
Else
Plot(a + #x, b + #y, screen(a, b))
EndIf
EndIf
e1 = screen(a - 1, b - 1)
e2 = screen(a, b - 1)
e3 = screen(a + 1, b - 1)
e4 = screen(a + 1, b)
e5 = screen(a + 1, b + 1)
e6 = screen(a, b + 1)
e7 = screen(a - 1, b + 1)
e8 = screen(a - 1, b)
screen(a, b) = (e1 + e2 + e3 + e4 + e5 + e6 + e7 + e8) / (Random(rand) + div)
Next
Next
If fps = 1
DrawText(0, 20, "FPS : " + Str(GameTimer(3)), RGB(255, 255, 255), 0)
DrawText(0, 0, "CPU : " + Str(CpuUsage()), RGB(255, 255, 255), 0)
EndIf
StopDrawing()
EndIf
FlipBuffers()
Until event = #PB_Event_CloseWindow; KeyboardPushed(#PB_Key_Escape)
GameTimer(1)
End
oui ce sont a priori des cousins de mes Smurggsgraph100 a écrit : ca ressemble a ce qu'a fait Dobro je crois
mais je n'est pas regarder le code![]()