📄 dubtrip.htm
字号:
<!--Header-->
<HTML>
<HEAD>
<TITLE>GPMega - Beginners Section - Double and Triple-Buffering</TITLE>
<META NAME="DESCRIPTION" CONTENT="In this introductory article written by Dominic Filion, he dives into the details of using the various page flipping and buffering methods of todays games. He discusses the technical details of montors, and how they relate to page flipping and a good vertical sync. A good article for an introduction to page flipping or buffering.">
</HEAD>
<BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#00FF00 VLINK=#00FF00 ALINK=#0000FF>
<!--End Header-->
<!--Advertiser-->
<CENTER>
<TABLE>
<TR>
<TD>
<A HREF="http://www.ugo.com/">
<IMG SRC="/GPMega/ugologo120.gif" BORDER=0 WIDTH=120 HEIGHT=60></A>
</TD>
<TD>
<IMG SRC="/GPMega/sponsored.gif" WIDTH=468 HEIGHT=10><br><br>
<SCRIPT LANGUAGE= "JavaScript">
<!--
var now = new Date();
var random_num = now.getSeconds();
document.write("<A HREF='http://www.ugo.net/RealMedia/ads/click_nx.cgi/www.perplexed.com/GPMega/beginners/dubtrip.htm/" + random_num + "/@Top'>");
document.write("<IMG SRC='http://www.ugo.net/RealMedia/ads/adstream_nx.cgi/www.perplexed.com/GPMega/beginners/dubtrip.htm/" + random_num + "/@Top' BORDER='0' WIDTH='468' HEIGHT='60'></A>");
//-->
</SCRIPT>
</TD>
</TR>
</TABLE>
</CENTER>
<!--End Advertiser-->
<!--Splitter-->
<BR>
<!--End Splitter-->
<!--Body-->
<FONT SIZE=2 FACE=Helvetica>
<STRONG>
<!--Top Navigation-->
<A NAME="top"></A>
<CENTER>
<TABLE WIDTH=75%>
<TR VALIGN=MIDDLE>
<TD ALIGN=LEFT>
<IMG SRC="gradsplit2.jpg" WIDTH=100% HEIGHT=1><BR><BR>
<A HREF="http://www.perplexed.com/GPMega/"><IMG SRC="logo.jpg" BORDER=0 ALT="Home" WIDTH=80 HEIGHT=47 ALIGN=CENTER></A>
<FONT COLOR=#666666 FACE=HELVETICA SIZE=-1><I>
This Article Is Taken From <A HREF="http://www.perplexed.com/GPMega/">The Game Programming MegaSite</A>, A Definitive Resource For Game Developers!
</I></FONT><BR>
<IMG SRC="gradsplit2.jpg" WIDTH=100% HEIGHT=1>
</TD>
</TR>
</TABLE>
</CENTER>
<BR><!--End Top Navigation-->
<!--Title-->
<H3 ALIGN=CENTER><font color="#FFF600">D</font><font color="#FFED00">o</font><font color="#FFE400">u</font><font color="#FFDB00">b</font><font color="#FFD200">l</font><font color="#FFC900">e</font><font color="#FFC000"> </font><font color="#FFB700">a</font><font color="#FFAE00">n</font><font color="#FFA500">d</font><font color="#FF9C00"> </font><font color="#FF9300">T</font><font color="#FF8A00">r</font><font color="#FF8100">i</font><font color="#FF7800">p</font><font color="#FF6F00">l</font><font color="#FF6600">e</font><font color="#FF5D00">-</font><font color="#FF5400">B</font><font color="#FF4B00">u</font><font color="#FF4200">f</font><font color="#FF3900">f</font><font color="#FF3000">e</font><font color="#FF2700">r</font><font color="#FF1E00">i</font><font color="#FF1500">n</font><font color="#FF0C00">g</font><BR><FONT SIZE=-2>By: Dominic Filion</FONT></H3>
<!--End Title-->
<P><A href="http://members.xoom.com/armagammon/">Armagammon Game Engine</A>
<H3><FONT COLOR=YELLOW><I>Page Flipping</I></FONT></H3>
<P>What is it? Let's look at the DirectX Reference
Documentation for a quick introduction:
<BLOCKQUOTE>
<P>"Page flipping is key in
multimedia, animation, and game software. Software page flipping is
analogous to the way animation can be done with a pad of paper. On each
page the artist changes the figure slightly, so that when you flip between
sheets rapidly the drawing appears animated.
</BLOCKQUOTE>
<P>Page flipping in software is very similar to this process.
Initially, you set up a series of DirectDraw surfaces (i.e. areas of
memory that hold what's supposed to be on screen) that are designed to
"flip" to the screen the way artist's paper flips to the next
page. The first surface is referred to as the primary
surface and the surfaces behind it are called
back buffers. Your application writes
to a back buffer, then flips the primary surface so that the back buffer
appears on screen. While the system is displaying the image, your software
is again writing to a back buffer. The process continues as long as you're
animating, allowing you to animate images quickly and
efficiently."
<P>This explains, what it is, but why is it necessary ? Well, a typical
game can have hundreds of graphical objects moving and animating on screen
: monsters, players, walls, text, scores, you name it. Now our game needs
to update these graphical objects as fast as possible, in a clean manner,
changing the position of graphical objects as they move.
<P>Some games keep redraw the whole screen everytime, others keep track of
what has changed on the screen and redraw those parts. We'll take the
first method for our example. So, everytime your game screen is refreshed,
the screen will be cleared so we aren't left with any stuff from the old
frame, and we redraw everything. What will this do ? Flicker.
<P>It could take your game 1/50th of a second (or more) to redraw its
screen; 1/50th is a "long" time, and it's enough for the eye to
notice. Since we are clearing our game screen, the eye will see the image
"being built" and get a flicker of the black (cleared) screen as
it is being filled up with graphics. It's like watching a magician from
behind the stage and seeing all his secrets : it's very interesting if you
want to know how things are done, but it kinda ruins the experience.
<P>So this is where page flipping comes in. Like explained in the DirectX
documentation, when using page flipping, you draw your graphics on an
offscreen, "secret" surface, and when you're done you quickly
"flip" it so it appears on the screen instantly (well, almost,
"instantly" doesn't have the same meaning in computer
graphics!). This way, the eye always sees a clean image, without any
flickering or other visual artifacts.
<P>But page flipping comes out with its own set of troubles, which are
rooted in the way video cards and monitors work, which is the subject of
the next section.
<H3><FONT COLOR=YELLOW><I>How monitors work</I></FONT></H3>
<P>You draw a line and it appears instantly on screen, right ? No.
Monitors are far from being "instantaneous"; a typical monitor
takes 1/75th of a second to "draw" its whole image, which is a
rather large amount of time in the computer world. Some newer (and
expensive) active-matrix flat screen displays could be dubbed
"instantaneous", but the great majority of monitors aren't flat,
and are called CRT monitors.
<P>Inside your monitor is a vacuum tube, completely void of air. It'
called a cathode-ray tube (or CRT). Those of you with electrical
backgrounds will know that a cathode is the negatively charged
pole in an electrical system; the positive pole is the anode. The
cathode in the monitor is at the back of the monitor, where lies a
"gun" shooting electrons right in your face, which are
thankfully stopped by the glass screen of the monitor. Around thise
cathode gun is a yoke, which, by manipulation its magnetic charge
causes the electrons to be deviated up, down, left or right from the
center of the screen.
<P>By controlling this magnet in a certain pattern, the electrons can be
caused to "spray" the screen horizontally, going down one line
at a time, which is represented by this picture:
<P align=center><IMG height=386 src="monitorscan.gif" width=427>
<P>The electrons will hit the back of the glass screen, which
is made of rows phosphor, which lights up when hit, The amount of
electrons being fired by the gun can also be controlled, providing
different levels of intensity.
<P>In color monitors, each pixel is represent by a
triplet of phosphor cells, one for red, green and blue. There are
also three electron guns instead of one, each one positioned so it can
only it one of phosphor cells in each triplet; so there's a red, blue and
green gun, the three primary colors that can combined to produce any
color. By varying the output of electrons from each gun and synchronizing
all this with the screen scanning process as depicted above, we can
effectively control the appearance (color) of each pixel on our screen.
<H3><FONT COLOR=YELLOW><I>The Vertical Sync Signal (VSync)</I></FONT></H3>
<P>What does this all have to do with page flipping, and game
programming ? Well, first of all, we've understood that a monitor doesn't
display its image instantly; it takes a certain time for the monitor to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -