Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: DeXtr0 on July 19, 2007
-
Hey Guys,
Since i'm trying to read the freebasic code of ShockWave (I'm a PureBasic guy) I got some really rookie questions for those FreeBasic experts here:
1. DIM SHARED AS UINTEGER BUFFER ( XRES * YRES )
=> Create a temporary buffer with the size of xres*yres ?
2. DIM SHARED AS DOUBLE CXP ( CHESS_RES , CHESS_RES )
=> Create a 2 dimensional array ?
3. PTC_UPDATE@BUFFER(0) & ERASE BUFFER
=> Is this the same as flipbuffer in PureBasic ? Anybody an idea ?
4. dim pp as uinteger PTR
=> Does this create a pointer ? If yes, then i need to figure out if that can be done in PB
5. TTC = BPL (TC,LO+COPOFF)
=> ?
6. PP = @BUFFER(IL1+(LO*XRES))
=> ?
If somebody could explain this commands to me, It would be of great help !
Kind regards,
DeXtr0
-
1. Yes, that creates a 1-dimensional array of XRES*YRES+1 unsigned 32bit integers indexed from 0 to XRES*YRES (good for RGBA pixels!)
The 'shared' keyword means that the array is visible across the whole program globally. Without it everything is local to the sub or function you're working in.
2. Yep. A 2d array of 64bit floating point numbers.
3. Not quite. The array 'Buffer' contains all the pixels we've drawn. ptc_update copies those pixels to video memory. PRC_flip() does what flipbuffer does.
4. Yes. pp is a pointer to a buffer of unsigned integers. I know Blitz can't do this, not sure about PB.
5. That's just an array access. BPL is a 2D array.
6. That points pp at some position inside the array 'buffer'. Now you can use pp like a 1d array, which is using some part of 'buffer' as storage.
Jim
-
Wow cool Jim, this is a very explanation you gave me here.
I'm going to see what commands are possible in PB to see if I can match it..
1 last question:
ptc_update => Actualy it is 1 instruction to copy all pixels from a temporary buffer (screen memory) to the video memory ?
Isn't that the same what PRC_Flip does ? At least in PureBasic Flipbuffers() copies all pixels drawn in the memory to the screen (if I'm right)
DeXtr0
-
First a typo: PRC_flip should be PTC_flip. Sorry about that.
Flipbuffers() doesn't work how you think it does. What you have, both with PTC and PB, is 2 screens-worth allocated in video memory. In both, one of these screens is the one which you are actually seeing (the front buffer), and the other is offscreen (called the back buffer). In PB you draw pixels or blit sprites directly on to the back buffer. In PTC you draw the back buffer image into an array, and then use PTC_update to copy the entire array in to the back buffer. Finally, you call FlipBuffers or PTC_flip to make the back buffer into the front buffer (to get it on to the display, no copy involved), and the front buffer becomes the back buffer. Effectively this just flips a pointer on the graphics card to tell it to draw the display on the monitor from a different piece of video memory, and the change happens instantaneously.
The reason for this is called double buffering. If you were drawing to the piece of memory which is presently being displayed, you'd see the pixels or blits happening on the screen one-by-one. You don't want to see that, so you construct the entire frame offscreen and then flip to it in one go.
Jim
-
Jim - that is the clearest explanation of double buffering that I have ever read.
Well done for that!
Drew