• Advertisement
Sign in to follow this  

what is this doing: frontBuffer / backBuffer

This topic is 4642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

TEST For some reason it will not let me post my source code.
...
[Edited by - Tom Knowlton on June 4, 2005 6:23:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
public void DrawPicture()
{
Graphics g = Graphics.FromImage(_frontBuffer);
g.DrawImage(_backBuffer,0,0);

GamePiece gp;

if (_gw != null)
{
if ((_isDragging) && (_draggingBitmapSet))
{
g.DrawImage(_dragBuffer,0,0);
}
else
{
//Draw pieces
for (int col = MIN_COL; col < _boardCellWidth; col++)
{
for (int row = MIN_ROW; row < _boardCellWidth; row++)
{
if ((_isDragging) &&
(_movingPiecePosition.X == col) &&
(_movingPiecePosition.Y == row))
{

continue;
}
//**********************************
// Start drag highlighting
//**********************************

if ((_isDragging)&&(_MoveCostPositions != null))
{
for (int i = 0; i < _MoveCostPositions.Length; i++)
{
if ((_MoveCostPositions != _gw.NoMove)&&
(_MoveCostPositions.X == col)&&
(_MoveCostPositions.Y == row))
{
if (_gw.CanMoveTo(_movingPiecePosition.X,_movingPiecePosition.Y,col,row))
{
ShadeCell(g,col,row);
break;
}
}
}
}

//**********************************
// End drag highlighting
//**********************************
gp = _gw.ReturnGamePieceAtCell(col,row);
if (gp != null)
{
DrawPieceAtCell(g,gp.ImageIndex,col,row);
}
}
}
}
if (_isDragging)
{
if (!_draggingBitmapSet)
{
Graphics gTmp = Graphics.FromImage(_dragBuffer);
gTmp.DrawImage(_frontBuffer,0,0);
gTmp.Dispose();
_draggingBitmapSet = true;
}
gp = _gw.ReturnGamePieceAtCell(_movingPiecePosition.X,_movingPiecePosition.Y);
if(gp != null)
{
g.DrawImage(_iList.Images[gp.ImageIndex],_lastMousePosition.X - _lastOffset.X,_lastMousePosition.Y - _lastOffset.Y);
}
}
}
g.Dispose();
_pBox.Image = _frontBuffer;
}

Share this post


Link to post
Share on other sites
you realise that names with a preceding underscore (like _isDragging) are reserved for the compiler under the c++ standard, right?

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbastard
you realise that names with a preceding underscore (like _isDragging) are reserved for the compiler under the c++ standard, right?


I didn't. So I googled for it and found this:

Quote:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndeepc/html/deep04202000.asp
The rules differ slightly between the two languages. In C90 and C99, the implementation reserves

* any global-scope name beginning with _.
* any name beginning with _ followed by an upper-case letter.
* any name beginning with __.

In C++, the implementation reserves

* any global-scope name beginning with _.
* any name beginning with _ followed by an upper-case letter.
* any name containing __.

(The C++ rules are more restrictive, reserving any name that features double underscores anywhere, not just at the beginning.)


So the TS (and I :)) should be save.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think he is using Java cause he uses "null" and not "NULL".

Share this post


Link to post
Share on other sites
Quote:
Original post by Seraphim
So the TS (and I :)) should be save.


Thanks for correcting me - I didn't know it was that specific.

Share this post


Link to post
Share on other sites
To ALL:

Yes...I've been trying to use the souce tags:

  
(is that correct?)


The language is C# I am writing this in.

Share this post


Link to post
Share on other sites
I don't think this forum has any syntax highliting for C#, I'm not sure. Simply use the tag as C++ source code (since they're almost similar):
{source lang="cpp"}...{/source}
NOTE: Replace the "{}"s with "[]"s.

   As for your question about double buffering, what it does is it attempts to prevent "tearing", or that flashing effect when you draw something incomplete on the specified surface. Imagine that you're taking requests for drawing from some people (I don't know how to put this in a real-world situation), you have to constantly show the audience one sheet of paper, and you only draw on one sheet of paper. Each time the people request a new drawing from you, you have to draw a new, well, drawing, and the bad thing is, the people actually see your picture in the process of it being drawn, which'll probably look... odd.
   So, to fix this problem, you would need more than one sheet of paper to draw on, so you get two sheets of paper. One sheet of paper is the "viewing paper", or the paper that the people are currently seeing (similar to the "frontBuffer"), and the other sheet of paper is the "drawing paper", the paper that you are currently drawing on ("backBuffer").
   Whenever someone requests a new drawing, you wait until you're done with your current drawing (if you choose to do so), take the "drawing paper" up there, and swap it with the "viewing paper". So now, the papers have traded places, so the previous "viewing paper" is now the "drawing paper" and vice versa. Now, you can draw on the "drawing paper" without the people seeing it, but they still have something to look at.

Meh, it was the best example I could think of.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement