Author
Topic: Why I Love this forum (Read 904 times)

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...)

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

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...

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 3drenderworld();draw 2d / textcolor(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 :

; 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 - 1If KeyHit(17) And Selected < CurrentPlotCount Then Selected = Selected + 1If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1If 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 4xP=MouseX()yP=MouseY()Color 0,0,250Text 40,1,"Userinput: (Use [Q] and [W] to select a point, and Arrowkeys to Move the selected point"Color 100,180,0Text 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 pointsbutton$="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 problemDataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yPCurrentPlotCount=CurrentPlotCount+1NextPlotCount=NextPlotCount+1;Implement a pause to stop NUMEROUS extra points being added in quick succesionSStr$ = "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 problemDataPoint(NextPlotCount,0) = xP : DataPoint(NextPlotCount,1) = yPIf CurrentPlotCount>1CurrentPlotCount=CurrentPlotCount-1NextPlotCount=NextPlotCount-1SStr$ = "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 problemColor(125,125,125) : Text 340,60,"Add some more points first please.....";Implement a pause to stop NUMEROUS extra points being added in quick succesionSStr$ = "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()EndIfElse If button$="Middle";here you are still on the backbuffer, you can draw, no problemSStr$ = "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()EndIfWend

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 !)

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:

Graphics 800,600,0,2; get the identities of the two available buffers, for later useLocal bufb% = BackBuffer()Local buff% = FrontBuffer(); initially set the back bufferSetBuffer bufb; needed for "debuggin" infoLocal ty% = 0Local 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,0Cls; we can actually check on which buffer we're currently arebuf0 = 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,0Cls;... 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: "+bufbText 10,ty+15, "FrontBuffer id: "+buffText 10,ty+30, "After Flip(), we were drawing on buffer: "+buf0Text 10,ty+45, "After SetBuffer BackBuffer(), we were drawing on buffer: "+buf1ty = ty + 5If ty > 540 Then ty = 0; swap buffer contents and let them be for a whileFlip()Delay 500Wend

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() )...

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.

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 :

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...