SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: 3DzForMe on December 28, 2018, 07:37:32

Title: Why I Love this forum
Post by: 3DzForMe on December 28, 2018, 07:37:32
I was hunting around for a recent thread regarding drawing circles which got the creative cogs nearly grinding into life.

In my searching I came across some code for plotting some points and allowing them to be moved.

I thought it'd be interesting to add the ability to add some more points, or remove them if you felt like it.

[EDIT]

for those of you without a Blitz esque compiler, heres a link to an executable:



circles2.exe  circles2.exe (http://www.gpsrunner.co.uk/circles2.exe)




Here's the code in all it's glory - it'll run in Blitz3D and probably BlitzPlus.....

Code: [Select]
; Original author Credit:
; https://www.syntaxbomb.com/index.php/topic,2714.msg3703.html#msg3703

; Version 0.2
; Adding mouse cursor info to allow for capture of additional datapoints:
; Completed 28 Dec 18, by 3DZforMe, aka Blitzplotter

; Set the screensize
Graphics 800,600,32,2
SetBuffer BackBuffer()

MaxNumberOfPoints=200
Global CurrentPlotCount=4
Global NextPlotCount=5

; Dimension the pointarray and set startvalues
Dim DataPoint(MaxNumberOfPoints,1)
DataPoint(0,0) = 100 : DataPoint(0,1) = 090
DataPoint(1,0) = 200 : DataPoint(1,1) = 160
DataPoint(2,0) = 300 : DataPoint(2,1) = 300
DataPoint(3,0) = 400 : DataPoint(3,1) = 210
DataPoint(4,0) = 500 : DataPoint(4,1) = 100

    ; Set the clearcolor to red, and select point 0
ClsColor 255,255,255 : Global Selected = 0

    ; Mainloop
While Not KeyDown(1)
Cls ; Clear screen

       ; Userinput (Use [Q] and [W] to select a point,
       ; and Arrowkeys to position the selected point)
If KeyHit(16) And Selected > 0 Then Selected = Selected - 1
If KeyHit(17) And Selected < CurrentPlotCount Then Selected = Selected + 1
If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1
If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1
If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1
If KeyDown(208) Then DataPoint(Selected,1) = DataPoint(Selected,1) + 1

DrawLine(CurrentPlotCount) ; Draw the interpolated line between point 0 and 4

xP=MouseX()
yP=MouseY()

Color 0,0,250

Text 40,1,"Userinput: (Use [Q] and [W] to select a point, and Arrowkeys to Move the selected point"

Color 100,180,0

Text 12,30,"x: "+xP+" y: "+yP+" Points to Draw:"+CurrentPlotCount

;If left click add extra position to current list of points

button$="No"
If MouseDown(1) Then button$="Left"
If MouseDown(2) Then button$="Right"
If MouseDown(3) Then button$="Middle"

Text 400,30, button$ + " mouse button pressed!"

If button$="Left"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP
CurrentPlotCount=CurrentPlotCount+1
NextPlotCount=NextPlotCount+1

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

Text 40,60,"Press any key to continue to add your next point"

Flip

WaitKey()

EndIf

If button$="Right"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP

If CurrentPlotCount>1

CurrentPlotCount=CurrentPlotCount-1
NextPlotCount=NextPlotCount-1

Text 40,60,"Press any key to continue....."

Flip

WaitKey()

Else

Text 40,60,"Add some more points first please....."

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

Text 40,80,"Press any key to continue....."

Flip

WaitKey()


EndIf


EndIf

If button$="Middle"

Text 200,50,"Congratutaions on 3 buttons...."

EndIf


Flip ; Flip backbuffer to frontbuffer
Wend

End ; End of programm

Function DrawLine(CurrentPlotCount)
       ; Startpoint for the first Line
X = DataPoint(0,0) : Y = DataPoint(0,1) : Color 0,0,0

       ; Draw the interpolyted Line between point 0 and 1
MX = (DataPoint(0,0) - DataPoint(1,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(0,1),DataPoint(1,1),MU#)
X = MX * MU# + DataPoint(0,0)
Line OX,OY,X,Y
Next

       ; Draw the interpolated line between point 1 and 4
For I = 2 To CurrentPlotCount
MX = (DataPoint(I - 1,0) - DataPoint(I,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(I - 1,1),DataPoint(I,1),MU#) 
X = MX * MU# + DataPoint(I - 1,0)
Line OX,OY,X,Y
Next
Next

       ; Dra the anchor points
Color 255,0,0
For I = 0 To CurrentPlotCount
If Selected = I Then
Color 0,0,255
Else
Color 255,0,0
EndIf
Oval DataPoint(I,0) - 2,DataPoint(I,1) - 2,5,5,1
Next
End Function

    ; Function for cosineinterpolated line
Function CosineInterpolate(Y1#,Y2#,MU#)
Local MU2#
MU2# = (1.0 - Cos(MU# * 180.0))/2.0
Return (Y1# * (1.0 - MU2#) + Y2# * MU2#)
End Function

    ; Function for normal line
Function LinearInterpolate(Y1#,Y2#,MU#)
Return Y1# * (1 - MU#) + Y2# * MU#
End Function


Right, coding done for the day.... off to pack for a cheeky 300 mile drive to Scotland ;)
Title: Re: Why I Love this forum
Post by: c0d3r9 on December 28, 2018, 11:09:50
I remember that i have a problem with bb3d exe´s.
I have only a black colored window.
Must i install any feature in windows 10?

DirectPlay is installed.
Title: Re: Why I Love this forum
Post by: MagosDomina on December 28, 2018, 16:23:35
I remember that i have a problem with bb3d exe´s.
I have only a black colored window.
Must i install any feature in windows 10?

DirectPlay is installed.

We need a bit more information to help.
Can you run the code within the example folder from the IDE without issue?
Does compiling the same code into an .exe produce the same result?
Do you have the full installation of DX9c on your system? Windows 10 does not come with it standard.
Multiple monitors will cause issues with Blitz. Unless the program ran is displayed on your primary screen it will show up blank/blackscreen but still function in the background.
Lastly do you have any global settings on your 3D card? I would have it set for "application preference" or whatever is equivalent to your card.
Title: Re: Why I Love this forum
Post by: c0d3r9 on December 28, 2018, 17:13:41
I just start the .exe
In past (a few month ago i tried some codes with bb3d) i have the same problem.
Sometimes it go well sometime not.
Dx9c is installed.
Driver up2date, nothing special configured in the settings.

I start the exe and it opens a normal bordered window with a black background...thats all.
But not very important that i must this issue solve now ;)
Title: Re: Why I Love this forum
Post by: MagosDomina on December 28, 2018, 19:34:10
Do 2d examples always work? Meaning its only the 3D examples that give you this issue?

I have noticed on Windows 7 sometimes at random when I build an .exe it does not link everything together correctly, resulting in a "missing library" error. Recompiling until it works solves the issue.

Please let me know what code you are attempting to run.

Title: Re: Why I Love this forum
Post by: 3DzForMe on December 28, 2018, 20:19:53
Sorry to hear your trouble with the executable, just downloaded it to my dad's laptop in Scotland, not that the country should matter much, it's a windows10 box, sure it needed .  ....   Gotta go for my yea, it worked after installing directplay though ;)
Title: Re: Why I Love this forum
Post by: c0d3r9 on December 28, 2018, 20:50:33
I only wanted to run the exe.There is no reason for me to play around with bb3d.
But that demonstrates that bb3d is sometimes just to old.
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 28, 2018, 21:40:42
I suspect it's compatibility lssues with your 3d card, I was surprised it ran on my dad's old laptop, and I didn't need to install Blitz3D for the exe to work, even though the screen grab shows otherwise. I was just intrigued to see if my dad's clunky computer could compile blitz stuff. Sorry it didn't work for you though.
Title: Re: Why I Love this forum
Post by: c0d3r9 on December 28, 2018, 21:43:56
its no problem.
that issue is only with bb3d´s builds.
Title: Re: Why I Love this forum
Post by: MagosDomina on December 29, 2018, 03:10:46
I only wanted to run the exe.There is no reason for me to play around with bb3d.
But that demonstrates that bb3d is sometimes just to old.

I'm going to guess and say that English isn't your first language? I was under the impression you were trying to compile the code yourself. The problem you're having is not Blitz related but likely your hardware or something else specific to your system.
Title: Re: Why I Love this forum
Post by: c0d3r9 on December 29, 2018, 08:10:07
Right ;)
And i start only circles2.exe
Maybe its hardware related that my chipset doesn´t allow the dx7 emulated things.I don´t know.Its not important.
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 29, 2018, 10:48:02
I'm jealous of folks with 64 bit hardware, all my Dev machines are only (only....!) 32 bit so aren't Cerberus compatible. I'm also an advocate of MonkeyX despite the fact the forums vanished. On my dad's W10 computer (I've only got W7, tbh it's like today's XP OS), it was taking for EVER to locate directplay, nearly gave up and went hunting on the web.... But it eventually found it. Was the only hiccup, I'd be surprised if he's got older DirectX versions but you never know!
Title: Re: Why I Love this forum
Post by: MagosDomina on December 29, 2018, 14:39:53
There is a way to strip a Blitz exe of the direct-play requirement. I found it on a German based Blitz website and archived it on a drive. If I remember correctly the direct play requirement is only for the multiplayer compatibility. So if your app doesn't use any of those functions you can strip out request for the .dll thus removing the need for Windows 10 to install this legacy component.


*edit*

Here is what you do, open runtime.dll in the blitz3d\bin folder into a hex editor. Search for Dplayx.dll and replace it with Dinput.dll and save it.
This only works with Blitz3d and lets you run your code without direct play.
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 30, 2018, 03:47:57
Great piece of advice, thanks for sharing!

I think I recall Blitz3D may need a dedicated graphics card to run, some of the on motherboard graphics cards may not be up to the job .
Title: Re: Why I Love this forum
Post by: RemiD on December 30, 2018, 09:23:30
Quote
I think I recall Blitz3D may need a dedicated graphics card to run
what are you talking about ? how do you know that ? i have run blitz3d (3d) programs on many different laptops / desktops without having ever noticed this !!!


maybe consider that your code is the problem ?
Title: Re: Why I Love this forum
Post by: RemiD on December 30, 2018, 10:53:13
after a quick look at your code, i have noticed a possible cause of the problem :

setbuffer(backbuffer()) must be used before any rendering (2D or 3D) (if you then want to flip it on the frontbuffer), the exception is when you use renderworld(), because apparently setbuffer(backbuffer()) is automaticlaly called, but in your code, since you only render 2D stuff, you have to put setbuffer(backbuffer()) before drawing anything on this buffer. (else you are still on the frontbuffer !!! (to be precise, half of the time))

I really don't understand how you can, after so many years of using blitzbasic, don't grasp simple concepts like this (be reassured, you are not alone, the old codes archives is full of such mistakes...)
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 31, 2018, 02:33:21
I simply massaged some existing code.... Too tired to rectify now, just in from a 300 miles road trip, after my first go at a skate park with my daughter on quads, my left hip sure knows about it!
Title: Re: Why I Love this forum
Post by: MagosDomina on December 31, 2018, 02:46:05
RemiD is correct a discrete graphics card while superior is not a requirement for Blitz. But I would expect much lower performance on integrated Intel chipsets.

That sounds like an awesome trip, how well did the quad handle inside the skate park?  ;D
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 31, 2018, 13:25:29
I gave my son my £100 graphics card a while back and tried reverting to an old lesser specced graphics card, Blitz3D failed to play, although it was probably some PC config nuance.

As for the quads, they performed great, as for me, my first time in a skate park at 47 ,if I fell once, I fell 10 times, did get some good jumps in though! Then after getting home at 3 am this morning, was up cobbling together pre amp and amp stuff for my sons bands last practice before their first gig of 2019,in Nottingham, shameless plug in an attached images.

Bought a new set of knee pads, Which cracked within the first two hours, so some heavy falls!

So, they're my excuses for my syntactical XP diminishing in Blitz3D diminishing, use it or lose it folks. Happy Coding  8)
Title: Re: Why I Love this forum
Post by: RemiD on January 01, 2019, 10:24:27
Of course, if the graphics card is very old, maybe damaged or maybe with drivers which are not compatible with recent OS, it may cause problems... But personally i have tested Blitz3d 2d / 3d functions on many different hardwares / OS and it always worked (except cubemapping and stencil shadows)

But a black screen (without any crash) may be caused by a wrong use of the setbuffer(xbuffer) and of flip(), that's what i have tried to explain to you...
Title: Re: Why I Love this forum
Post by: 3DzForMe on January 02, 2019, 09:35:19
Ah, I understand now, apologies for being a bit slow. Will try to update the code inline with your recommendations, Happy New Year RemiD and all.
Title: Re: Why I Love this forum
Post by: 3DzForMe on January 05, 2019, 19:40:46
Modified code with SetBuffer(Backbuffer)) called, may stop crashes:

@RemiD, realise why I wasn't calling SetBuffer - I usually always have Renderworld() in my code.

Code: [Select]

; Original author Credit:
; https://www.syntaxbomb.com/index.php/topic,2714.msg3703.html#msg3703

; Version 0.3
; Setbuffer added

; Version 0.2
; Adding mouse cursor info to allow for capture of additional datapoints:
; Completed 28 Dec 18, by 3DZforMe, aka Blitzplotter

; Set the screensize
Graphics 800,600,32,2
SetBuffer BackBuffer()

MaxNumberOfPoints=200
Global CurrentPlotCount=4
Global NextPlotCount=5

; Dimension the pointarray and set startvalues
Dim DataPoint(MaxNumberOfPoints,1)
DataPoint(0,0) = 100 : DataPoint(0,1) = 090
DataPoint(1,0) = 200 : DataPoint(1,1) = 160
DataPoint(2,0) = 300 : DataPoint(2,1) = 300
DataPoint(3,0) = 400 : DataPoint(3,1) = 210
DataPoint(4,0) = 500 : DataPoint(4,1) = 100

    ; Set the clearcolor to red, and select point 0
ClsColor 255,255,255 : Global Selected = 0

SetBuffer(BackBuffer())   ; Required if Renderworld not being used

    ; Mainloop
While Not KeyDown(1)
Cls ; Clear screen

       ; Userinput (Use [Q] and [W] to select a point,
       ; and Arrowkeys to position the selected point)
If KeyHit(16) And Selected > 0 Then Selected = Selected - 1
If KeyHit(17) And Selected < CurrentPlotCount Then Selected = Selected + 1
If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1
If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1
If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1
If KeyDown(208) Then DataPoint(Selected,1) = DataPoint(Selected,1) + 1

DrawLine(CurrentPlotCount) ; Draw the interpolated line between point 0 and 4

xP=MouseX()
yP=MouseY()

Color 0,0,250

Text 40,1,"Userinput: (Use [Q] and [W] to select a point, and Arrowkeys to Move the selected point"

Color 100,180,0

Text 40,26,"Left Mouse Click to add a point, Right Mouse Click to remove a point, then press a key"

Text 12,60,"x: "+xP+" y: "+yP+" Points to Draw:"+CurrentPlotCount

;If left click add extra position to current list of points

button$="No"
If MouseDown(1) Then button$="Left"
If MouseDown(2) Then button$="Right"
If MouseDown(3) Then button$="Middle"

Text 400,300, button$ + " mouse button pressed!"

If button$="Left"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP
CurrentPlotCount=CurrentPlotCount+1
NextPlotCount=NextPlotCount+1

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

SetBuffer(BackBuffer())   ; Required if Renderworld not being used

Text 300,60,"Press any key to continue to add your next point"

Flip

WaitKey()

EndIf

If button$="Right"

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP

If CurrentPlotCount>1

CurrentPlotCount=CurrentPlotCount-1
NextPlotCount=NextPlotCount-1

SetBuffer(BackBuffer())   ; Required if Renderworld not being used

Text 140,260,"Press any key to continue....."

Flip

WaitKey()

Else

SetBuffer(BackBuffer())   ; Required if Renderworld not being used

Text 340,60,"Add some more points first please....."

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

Text 140,280,"Press any key to continue....."

Flip

WaitKey()


EndIf


EndIf

If button$="Middle"

SetBuffer(BackBuffer())   ; Required if Renderworld not being used

Text 200,50,"Congratutaions on 3 buttons...."


Flip

WaitKey()

EndIf


Flip ; Flip backbuffer to frontbuffer
Wend

End ; End of programm

Function DrawLine(CurrentPlotCount)
       ; Startpoint for the first Line
X = DataPoint(0,0) : Y = DataPoint(0,1) : Color 0,0,0

       ; Draw the interpolyted Line between point 0 and 1
MX = (DataPoint(0,0) - DataPoint(1,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(0,1),DataPoint(1,1),MU#)
X = MX * MU# + DataPoint(0,0)
Line OX,OY,X,Y
Next

       ; Draw the interpolated line between point 1 and 4
For I = 2 To CurrentPlotCount
MX = (DataPoint(I - 1,0) - DataPoint(I,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(I - 1,1),DataPoint(I,1),MU#) 
X = MX * MU# + DataPoint(I - 1,0)
Line OX,OY,X,Y
Next
Next

       ; Dra the anchor points
Color 255,0,0
For I = 0 To CurrentPlotCount
If Selected = I Then
Color 0,0,255
Else
Color 255,0,0
EndIf
Oval DataPoint(I,0) - 2,DataPoint(I,1) - 2,5,5,1
Next
End Function

    ; Function for cosineinterpolated line
Function CosineInterpolate(Y1#,Y2#,MU#)
Local MU2#
MU2# = (1.0 - Cos(MU# * 180.0))/2.0
Return (Y1# * (1.0 - MU2#) + Y2# * MU2#)
End Function

    ; Function for normal line
Function LinearInterpolate(Y1#,Y2#,MU#)
Return Y1# * (1 - MU#) + Y2# * MU#
End Function

Title: Re: Why I Love this forum
Post by: RemiD on January 05, 2019, 23:55:07
either you have not read my post carefully, or my english is bad ?! :-[

Quote
setbuffer(backbuffer()) must be used before any rendering (2D or 3D)
you have to put setbuffer(backbuffer()) before drawing anything on this buffer. (else you are still on the frontbuffer !!! (to be precise, half of the time))

this means :

;go on the buffer on which you want to draw (backbuffer in this case)
setbuffer(backbuffer())
;draw 3d
renderworld()
;draw 2d / text
color(R,G,B) : Rect() : Plot() : Text()
;flip the backbuffer to the frontbuffer, Flip is then used to make the BackBuffer become the FrontBuffer, at the same time the FrontBuffer becomes the BackBuffer, allowing you to draw the next screen update on the BackBuffer before Flipping again. (from the documentation)
Flip()

i have rewritten your code (removed the useless things, and added the setbuffer(backbuffer()) at the right places, with comments, maybe it will be more clear :
Code: [Select]

; Original author Credit:
; https://www.syntaxbomb.com/index.php/topic,2714.msg3703.html#msg3703

; Version 0.3
; Setbuffer added

; Version 0.2
; Adding mouse cursor info to allow for capture of additional datapoints:
; Completed 28 Dec 18, by 3DZforMe, aka Blitzplotter

; Set the screensize
Graphics 800,600,32,2
;on which buffer are we ? i don't know, i don't care !!!

MaxNumberOfPoints=200
Global CurrentPlotCount=4
Global NextPlotCount=5

; Dimension the pointarray and set startvalues
Dim DataPoint(MaxNumberOfPoints,1)
DataPoint(0,0) = 100 : DataPoint(0,1) = 090
DataPoint(1,0) = 200 : DataPoint(1,1) = 160
DataPoint(2,0) = 300 : DataPoint(2,1) = 300
DataPoint(3,0) = 400 : DataPoint(3,1) = 210
DataPoint(4,0) = 500 : DataPoint(4,1) = 100

;select point 0
Global Selected = 0

    ; Mainloop
While Not KeyDown(1)
   
       ; Userinput (Use [Q] and [W] to select a point,
       ; and Arrowkeys to position the selected point)
If KeyHit(16) And Selected > 0 Then Selected = Selected - 1
If KeyHit(17) And Selected < CurrentPlotCount Then Selected = Selected + 1
If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1
If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1
If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1
If KeyDown(208) Then DataPoint(Selected,1) = DataPoint(Selected,1) + 1

;here you want to draw, so we must go on the backbuffer !
SetBuffer(BackBuffer())

ClsColor(255,255,255) : Cls() ;-> to clear the active buffer

       ;here you are still on the backbuffer, you can draw, no problem

DrawLine(CurrentPlotCount) ; Draw the interpolated line between point 0 and 4

xP=MouseX()
yP=MouseY()

Color 0,0,250

Text 40,1,"Userinput: (Use [Q] and [W] to select a point, and Arrowkeys to Move the selected point"

Color 100,180,0

Text 40,26,"Left Mouse Click to add a point, Right Mouse Click to remove a point, then press a key"

Text 12,60,"x: "+xP+" y: "+yP+" Points to Draw:"+CurrentPlotCount

;If left click add extra position to current list of points

button$="No"
If MouseHit(1) Then button$="Left"
If MouseHit(2) Then button$="Right"
If MouseHit(3) Then button$="Middle"

SStr$ = button$+" mouse button pressed!" : Color(012,012,012) : Text(GraphicsWidth()/2-StringWidth(SStr)/2,GraphicsHeight()-StringHeight(SStr),SStr)

If button$="Left"

;here you are still on the backbuffer, you can draw, no problem

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP
CurrentPlotCount=CurrentPlotCount+1
NextPlotCount=NextPlotCount+1

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

SStr$ = "press any key to continue" : Color(012,012,012) : Text(xP-StringWidth(SStr)/2,yP-StringHeight(SStr)/2,SStr)

;here the backbuffer is fliped to the frontbuffer and then you are on the frontbuffer ( that's why, at the beginning of the next frame, you need to go back to the backbuffer before drawing anything else ! )
Flip()

FlushKeys()
WaitKey()

Else If button$="Right"

;here you are still on the backbuffer, you can draw, no problem

DataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yP

If CurrentPlotCount>1

CurrentPlotCount=CurrentPlotCount-1
NextPlotCount=NextPlotCount-1

SStr$ = "press any key to continue" : Color(012,012,012) : Text(xP-StringWidth(SStr)/2,yP-StringHeight(SStr)/2,SStr)

;here the backbuffer is fliped to the frontbuffer and then you are on the frontbuffer ( that's why, at the beginning of the next frame, you need to go back to the backbuffer before drawing anything else ! )
Flip()

FlushKeys()
WaitKey()

Else

;here you are still on the backbuffer, you can draw, no problem

Color(125,125,125) : Text 340,60,"Add some more points first please....."

;Implement a pause to stop NUMEROUS extra points being added in quick succesion

SStr$ = "press any key to continue" : Color(012,012,012) : Text(xP-StringWidth(SStr)/2,yP-StringHeight(SStr)/2,SStr)

;here the backbuffer is fliped to the frontbuffer and then you are on the frontbuffer ( that's why, at the beginning of the next frame, you need to go back to the backbuffer before drawing anything else ! )
Flip()

FlushKeys()
WaitKey()


EndIf


Else If button$="Middle"

;here you are still on the backbuffer, you can draw, no problem

SStr$ = "congratulations on 3 buttons... wtf?!" : Color(012,012,012) : Text(xP-StringWidth(SStr)/2,yP-StringHeight(SStr)/2,SStr)

;here the backbuffer is fliped to the frontbuffer and then you are on the frontbuffer ( that's why, at the beginning of the next frame, you need to go back to the backbuffer before drawing anything else ! )
Flip()

FlushKeys()
WaitKey()

Else

;here the backbuffer is fliped to the frontbuffer and then you are on the frontbuffer ( that's why, at the beginning of the next frame, you need to go back to the backbuffer before drawing anything else ! )    
Flip()

EndIf

Wend

End ; End of programm

Function DrawLine(CurrentPlotCount)
       ; Startpoint for the first Line
X = DataPoint(0,0) : Y = DataPoint(0,1) : Color 0,0,0

       ; Draw the interpolyted Line between point 0 and 1
MX = (DataPoint(0,0) - DataPoint(1,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(0,1),DataPoint(1,1),MU#)
X = MX * MU# + DataPoint(0,0)
Line OX,OY,X,Y
Next

       ; Draw the interpolated line between point 1 and 4
For I = 2 To CurrentPlotCount
MX = (DataPoint(I - 1,0) - DataPoint(I,0)) * (-1)
For MU# = 0 To 1.0 Step 0.08
OX = X : OY = Y
Y = CosineInterpolate(DataPoint(I - 1,1),DataPoint(I,1),MU#) 
X = MX * MU# + DataPoint(I - 1,0)
Line OX,OY,X,Y
Next
Next

       ; Dra the anchor points
Color 255,0,0
For I = 0 To CurrentPlotCount
If Selected = I Then
Color 0,0,255
Else
Color 255,0,0
EndIf
Oval DataPoint(I,0) - 2,DataPoint(I,1) - 2,5,5,1
Next
End Function

    ; Function for cosineinterpolated line
Function CosineInterpolate(Y1#,Y2#,MU#)
Local MU2#
MU2# = (1.0 - Cos(MU# * 180.0))/2.0
Return (Y1# * (1.0 - MU2#) + Y2# * MU2#)
End Function

    ; Function for normal line
Function LinearInterpolate(Y1#,Y2#,MU#)
Return Y1# * (1 - MU#) + Y2# * MU#
End Function

i hope that you will understand why it must be done this way (to reassure you, from what i have seen in the code archives, most coders don't, they just hope it will go well and with the fast fliping between the frontbuffer and the backbuffer, at 60fps, it is not noticeable for humans, even if it is incorrect !)
Title: Re: Why I Love this forum
Post by: Holzchopf on January 06, 2019, 11:23:38
Errm sorry RemiD, but that's not correct. You've been mislead by the docs there. To be fair, they are a bit misleading: It's not the buffers that are swapped, it's their contents. Of course, internally it's only a pointer that's swapped, but from BBs view it's like their contents were swapped. After Flip(), the drawing operations are "taking place" on the buffer that's now the back buffer.

You only need to set the backbuffer once (or after rendering to an image, but that's not used here). Here's a simple demonstration:

Code: [Select]
Graphics 800,600,0,2
; get the identities of the two available buffers, for later use
Local bufb% = BackBuffer()
Local buff% = FrontBuffer()
; initially set the back buffer
SetBuffer bufb
; needed for "debuggin" info
Local ty% = 0
Local buf0%, buf1%

While Not KeyDown(1)
; False statement: After the First Flip() we're on the front buffer
; (so this should be rendered immediately visible)
ClsColor 255,0,0
Cls
; we can actually check on which buffer we're currently are
buf0 = GraphicsBuffer()
; this is to make sure windows would find the time to
; draw, if there was anything to draw ;-)
Delay 500
; False statement: only now we're going to the back buffer
; (try commenting/uncommenting this line and see for yourself)
SetBuffer BackBuffer()
ClsColor 0,255,0
Cls
;... wait, in which buffer were we again?
buf1 = GraphicsBuffer()
; additional "debug" info. Moving, so you see the program
; is still running ;-)
Text 10,ty, "BackBuffer id: "+bufb
Text 10,ty+15, "FrontBuffer id: "+buff
Text 10,ty+30, "After Flip(), we were drawing on buffer: "+buf0
Text 10,ty+45, "After SetBuffer BackBuffer(), we were drawing on buffer: "+buf1
ty = ty + 5
If ty > 540 Then ty = 0
; swap buffer contents and let them be for a while
Flip()
Delay 500
Wend

Title: Re: Why I Love this forum
Post by: RemiD on January 06, 2019, 11:55:34
the documentation says that after having used Flip() the backbuffer becomes the frontbuffer and so, at the start of the mainloop, in theory you are still on the frontbuffer, or maybe you are still on the backbuffer and the frontbuffer has been copied to the frontbuffer, but in this case, the documentation is indeed confusing.

in any case, there must have been a reason (that i don't remember, it was a few years ago) why is started to write code this way, so i am going to code something to really see what is on the backbuffer / frontbuffer ( before and after using flip() )...

Code: [Select]
Graphics3D(640,480,32,2)

DebugLog(GraphicsBuffer())

BackB% = BackBuffer()
DebugLog("BackBuffer ref = "+BackB)

FrontB% = FrontBuffer()
DebugLog("FrontBuffer ref = "+FrontB)

;SetBuffer(BackB)

DebugLog(GraphicsBuffer())

Repeat

 DebugLog("start of mainloop")

 DebugLog(GraphicsBuffer())
 
 ;SetBuffer(BackB)
 
 ;Renderworld()

 Flip()
 
 DebugLog("end of mainloop")

 FlushKeys()
 WaitKey()

Until( KeyDown(1)=1 )

End()
Holzchopf is correct, i was mistaken...

in fact, you don't even need to use setbuffer(backbuffer()) at all (if you don't draw on others image buffers / texture buffers), apparently, by default, the back buffer is automatically set for you to draw, see the example above...

i remmember why i started to write setbuffer(backbuffer()) before dawing anything (3D or 2D) -> to be safe, because i often play with images and textures, so just to be sure that i draw on the backbuffer, i always go on it before drawing 3d or 2d.
Title: Re: Why I Love this forum
Post by: Flanker on January 06, 2019, 13:02:58
in fact, you don't even need to use setbuffer(backbuffer()) at all (if you don't draw on others image buffers / texture buffers), apparently, by default, the back buffer is automatically set for you to draw, see the example above...

I remember having issues if not setting the backbuffer, especially in 2D examples, I'll try to replicate it, but there was a reason why people start to always set it once on top of the program.

Just try that, with and without setting the backbuffer, and check the FPS you get :
Code: [Select]
Graphics 800,600,32,2
SetBuffer BackBuffer()

While Not KeyHit(1)

Cls

Text 200,200,Rnd(1000)

Flip

Wend

End
Title: Re: Why I Love this forum
Post by: RemiD on January 06, 2019, 16:55:00
Quote
but there was a reason why people start to always set it once on top of the program
run the code example that i have posted, you will see that you are by default on the backbuffer... so no need to go where you already are ?

there is also a reason why i took the habit to always write setbuffer(backbuffer()) before drawing 3d or 2d, but if you never play with images / textures, it seems that there is no need to write it at all...

even with 3d + 2d :
Code: [Select]
Graphics3D(640,480,32,2)

DebugLog(GraphicsBuffer())

BackB% = BackBuffer()
DebugLog("BackBuffer ref = "+BackB)

FrontB% = FrontBuffer()
DebugLog("FrontBuffer ref = "+FrontB)

Camera = CreateCamera()
CameraClsColor(Camera,015,015,015)
CameraRange(Camera,0.15,150)
PositionEntity(Camera,0,1.65,-3)

Shape = CreateCube()
ScaleMesh(Shape,1.0/2,1.0/2,1.0/2)
EntityColor(Shape,125,125,125)
PositionEntity(Shape,0,0,0)

;SetBuffer(BackB)

DebugLog(GraphicsBuffer())

Repeat

 millistart% = MilliSecs()

 ;DebugLog("start of mainloop")

 If( KeyHit(57)=1 )
  DebugLog(GraphicsBuffer())
 EndIf

 TurnEntity(Shape,0,+3,0)

 ;SetBuffer(BackB)

 ;ClsColor(010,010,010) : Cls()

 CameraClsColor(Camera,010,010,010)
 RenderWorld()

 Color(125,125,125) : Rect(GraphicsWidth()/2-1,GraphicsHeight()/2-1,2,2,True)

 Color(255,255,255) : XStr$ = FPS : Text(GraphicsWidth()/2-StringWidth(XStr)/2,0,XStr)

 Flip(True)
 
 ;DebugLog("end of mainloop")

 millitime% = MilliSecs() - millistart

 FPS% = 1000.0/millitime

 ;FlushKeys()
 ;WaitKey()

Until( KeyDown(1)=1 )

End()
i don't notice an abnormal FPS hit ?
Title: Re: Why I Love this forum
Post by: Flanker on January 06, 2019, 22:01:59
run the code example that i have posted, you will see that you are by default on the backbuffer... so no need to go where you already are ?

Yes this doesn't seem to happen whith Graphics3D(), but test my example with Graphics() and you'll see the FPS drop.
Title: Re: Why I Love this forum
Post by: RemiD on October 06, 2019, 07:47:43
recently i have encountered the same weird behavior (bug?) that i have encountered some years ago, and that made me write setbuffer(backbuffer()) before renderworld()

the scenario was that :
i create a texture
i go on the texture buffer to draw on the texture
then when renderworld() happens, the render is on the texture buffer instead of the back buffer, and i had to write setbuffer(backbuffer()) before renderworld() to render the scene on the back buffer.

however i can't reproduce it lol
Title: Re: Why I Love this forum
Post by: STEVIE G on October 06, 2019, 08:13:16
recently i have encountered the same weird behavior (bug?) that i have encountered some years ago, and that made me write setbuffer(backbuffer()) before renderworld()

the scenario was that :
i create a texture
i go on the texture buffer to draw on the texture
then when renderworld() happens, the render is on the texture buffer instead of the back buffer, and i had to write setbuffer(backbuffer()) before renderworld() to render the scene on the back buffer.

however i can't reproduce it lol

This isn't a bug.  It's normal practice to use 'setbuffer backbuffer()' once you are done writing to an image/texture buffer.
Title: Re: Why I Love this forum
Post by: RemiD on October 06, 2019, 11:00:47
well, in the documentation, it is written that renderworld() draws on the backbuffer, so (if the documentation is correct) it should not happen...
Title: Re: Why I Love this forum
Post by: TomToad on October 06, 2019, 12:06:07
(Checks documentation)
RenderWorld [tween#] 

Parameters:


tween# - defaults to 1.

Description:

Renders all entities in the world.
The optional tween parameter can be used to render entities at a point somewhere between their captured position and their current position. A tween value of 0 will render entities at their captured position, a tween value of 1 will render entities at their current position. Other values may be used for interpolation. Defaults to 1.

Tweening is a technique used to allow games to have their game logic updated a fixed amount of times, e.g. 30, while having Blitz3D interpolate between these game logic updates to render as many frames per second as it can, e.g. 60+, with each frame different to the last.

This results in a game which only has to have its game logic updated at half the rate of the renders per second, freeing up CPU time, while at the same time having the game run as smooth as possible on anybody's machine.

Render tweening is quite an advanced technique, and it is not necessary to use it, so don't worry if you don't quite understand it. See the castle demo included in the mak (nickname of Mark Sibly, author of Blitz3D) directory of the Blitz3D samples section for a demonstration of render tweening.
 


Example:

None.


No mention of BackBuffer.
Title: Re: Why I Love this forum
Post by: RemiD on October 06, 2019, 12:08:47
i have this written in my blitz3d doc :
Quote
Renders the current scene to the BackBuffer onto the rectangle defined by each cameras CameraViewport( ). Every camera not hidden by HideEntity( ) or with a CameraProjMode( ) of 0 is rendered. Rendering to other buffers is currently not supported by Blitz3D.

The optional tween parameter should only be specified when RenderWorld is used in conjunction with CaptureWorld. CaptureWorld is used to store the 'old' position, rotation and scale, alpha and colour of each entity in the game world, and a tween value of < 1 will interpolate between these 'old' values and the 'current' ones. A tween value of 0 will render all entities at their state when CaptureWorld was last called, and a tween value of 1 will render all entities at their current state.

The use of tweening allows you to render more than one frame per game logic update, while still keeping the display smooth. This allows you to cut down on the CPU time that would be required to update your game logic every render. Note, however, that the bottleneck in almost all 3D applications is the graphics card and the CPU time involved in updating game logic is often very little. A good alternative to render tweening is the use of a delta time, that is, moving your entities each frame depending on the time it took for the program to process and render that frame.

Render tweening is quite an advanced technique, and it is not necessary to use it, so don't worry if you don't quite understand it. See the castle demo included in the mak (nickname of Mark Sibly, author of Blitz3D) directory of the Blitz3D samples section for a demonstration of render tweening.
Title: Re: Why I Love this forum
Post by: TomToad on October 06, 2019, 13:55:12
Strange, I just checked some backups to see which is the latest docs.  Looking at the RenderWorld command, v1.64 has no mention of BackBuffer.  The date of the docs is 2001.  V 1.88 says rendering will be on the backbuffer, docs from 2005.  v 1.106-v1.108 has the original 2001 docs.

The 2001 docs imply 3d rendering is only allowed on the BackBuffer for other commands, such as CreateTexture() which says "to display 3D graphics on a texture, your only option is to copy from the backbuffer to the texturebuffer.", but nothing in RenderWorld nor SetBuffer where you would expect such a description.

After some experimenting, I have found that you can set other rendering targets, but they will only result in a black image.  So the 2005 docs (which seem to be the latest) are correct, just poorly worded.  It should say
Quote
Renders the current scene onto the rectangle defined by each cameras CameraViewport( ). Every camera not hidden by HideEntity( ) or with a CameraProjMode( ) of 0 is rendered. Only the BackBuffer currently supports 3D rendering.  Using SetBuffer to render to other buffers will result in a blank image.
(and why the latest version of B3D is using an old version of the docs is a mystery).

Edit:  It appears the download from itch.io has the latest docs (2005).  The download from BlitzBasic.com does not, though they are listed as the same version.
Title: Re: Why I Love this forum
Post by: RemiD on October 06, 2019, 14:04:36
there was also another update for the Blitz3d docs : (1.99)
http://rd-stuff.fr/blitz3d-docpak-1.99.zip
Title: Re: Why I Love this forum
Post by: 3DzForMe on December 30, 2019, 07:47:18
Thanks for the info about the update to the docs,  ;D

Was digging around trying to source the fastlibs libraries/dll(s) (As some of you may know I've had TWO dev machines die during the gaming competitions this year).

Was working on compiling my old tcx file plotter last night - realised the fastlibs I need are stuck (possibly) on a dead computers hard drive. At the mo I've no way of accessing them (my current dev machine is a laptop with no E-Sata connectors). I found some fastlibs online, retailing at 10 or 12 dollars, which ain't much I know - but I'll have to be patient and wait until I can access the old hard drives. After all, I'm spending 200 quid this morning on brake discs, pads, oil, oil filter and airfilter for the old workhorse.

In the interim - compiled the code in this thread again - just a year after the first time - and made this years chrimbo message (almost etch-a-sketch style) , with a little help from Paint3D - a rather brill paint package by Microsoft. Yeah, my tree needs a bit of work ;)

SimplePortal 2.3.6 © 2008-2014, SimplePortal