Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > ed1483a4d9709d82850bb84cf25535e7 > files > 98

sfml-1.5-1mdv2010.0.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>SFML - Simple and Fast Multimedia Library</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <link href="doxygen.css" rel="stylesheet" type="text/css" />
        <link href="tabs.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="logo">
            <img src="./logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
        </div>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.htm"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.htm"><span>Namespaces</span></a></li>
      <li><a href="annotated.htm"><span>Classes</span></a></li>
      <li class="current"><a href="files.htm"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.htm"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>RenderTarget.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// SFML - Simple and Fast Multimedia Library</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This software is provided 'as-is', without any express or implied warranty.</span>
<a name="l00007"></a>00007 <span class="comment">// In no event will the authors be held liable for any damages arising from the use of this software.</span>
<a name="l00008"></a>00008 <span class="comment">//</span>
<a name="l00009"></a>00009 <span class="comment">// Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00010"></a>00010 <span class="comment">// including commercial applications, and to alter it and redistribute it freely,</span>
<a name="l00011"></a>00011 <span class="comment">// subject to the following restrictions:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// 1. The origin of this software must not be misrepresented;</span>
<a name="l00014"></a>00014 <span class="comment">//    you must not claim that you wrote the original software.</span>
<a name="l00015"></a>00015 <span class="comment">//    If you use this software in a product, an acknowledgment</span>
<a name="l00016"></a>00016 <span class="comment">//    in the product documentation would be appreciated but is not required.</span>
<a name="l00017"></a>00017 <span class="comment">//</span>
<a name="l00018"></a>00018 <span class="comment">// 2. Altered source versions must be plainly marked as such,</span>
<a name="l00019"></a>00019 <span class="comment">//    and must not be misrepresented as being the original software.</span>
<a name="l00020"></a>00020 <span class="comment">//</span>
<a name="l00021"></a>00021 <span class="comment">// 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00022"></a>00022 <span class="comment">//</span>
<a name="l00024"></a>00024 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">// Headers</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="preprocessor">#include &lt;SFML/Graphics/RenderTarget.hpp&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;SFML/Graphics/Drawable.hpp&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;SFML/Graphics/GraphicsContext.hpp&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">namespace </span>sf
<a name="l00035"></a>00035 {
<a name="l00039"></a><a class="code" href="classsf_1_1RenderTarget.htm#2997c96cbd93cb8ce0aba2ddae35b86f">00039</a> <a class="code" href="classsf_1_1RenderTarget.htm#2997c96cbd93cb8ce0aba2ddae35b86f" title="Default constructor.">RenderTarget::RenderTarget</a>() :
<a name="l00040"></a>00040 myCurrentView   (&amp;myDefaultView),
<a name="l00041"></a>00041 myPreserveStates(false),
<a name="l00042"></a>00042 myIsDrawing     (false)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 }
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 
<a name="l00051"></a><a class="code" href="classsf_1_1RenderTarget.htm#45414a2f09b257db7e7b37861d70c5a0">00051</a> <a class="code" href="classsf_1_1RenderTarget.htm#45414a2f09b257db7e7b37861d70c5a0" title="Destructor.">RenderTarget::~RenderTarget</a>()
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053     <span class="comment">// Nothing to do</span>
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 
<a name="l00060"></a><a class="code" href="classsf_1_1RenderTarget.htm#125645088d7b2df07599ea36fbb8b87e">00060</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1RenderTarget.htm#125645088d7b2df07599ea36fbb8b87e" title="Clear the entire target with a single color.">RenderTarget::Clear</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Color.htm" title="Color is an utility class for manipulating 32-bits RGBA colors.">Color</a>&amp; FillColor)
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062     <span class="keywordflow">if</span> (Activate(<span class="keyword">true</span>))
<a name="l00063"></a>00063     {
<a name="l00064"></a>00064         <span class="comment">// Clear the frame buffer</span>
<a name="l00065"></a>00065         GLCheck(glClearColor(FillColor.<a class="code" href="classsf_1_1Color.htm#6a5256ca24a4f9f0e0808f6fc23e01e1" title="Red component.">r</a> / 255.f, FillColor.<a class="code" href="classsf_1_1Color.htm#591daf9c3c55dea830c76c962d6ba1a5" title="Green component.">g</a> / 255.f, FillColor.<a class="code" href="classsf_1_1Color.htm#6707aedd0609c8920e12df5d7abc53cb" title="Blue component.">b</a> / 255.f, FillColor.<a class="code" href="classsf_1_1Color.htm#56dbdb47d5f040d9b78ac6a0b8b3a831" title="Alpha (transparency) component.">a</a> / 255.f));
<a name="l00066"></a>00066         GLCheck(glClear(GL_COLOR_BUFFER_BIT));
<a name="l00067"></a>00067 
<a name="l00068"></a>00068         Activate(<span class="keyword">false</span>);
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 
<a name="l00076"></a><a class="code" href="classsf_1_1RenderTarget.htm#18678bb6afe22b7462e2cf08f701d2ff">00076</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1RenderTarget.htm#18678bb6afe22b7462e2cf08f701d2ff" title="Draw something into the target.">RenderTarget::Draw</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1Drawable.htm" title="Abstract base class for every object that can be drawn into a render window.">Drawable</a>&amp; Object)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078     <span class="comment">// Check whether we are called from the outside or from a previous call to Draw</span>
<a name="l00079"></a>00079     <span class="keywordflow">if</span> (!myIsDrawing)
<a name="l00080"></a>00080     {
<a name="l00081"></a>00081         myIsDrawing = <span class="keyword">true</span>;
<a name="l00082"></a>00082 
<a name="l00083"></a>00083         <span class="comment">// Set our target as the current target for rendering</span>
<a name="l00084"></a>00084         <span class="keywordflow">if</span> (Activate(<span class="keyword">true</span>))
<a name="l00085"></a>00085         {
<a name="l00086"></a>00086             <span class="comment">// Save the current render states and set the SFML ones</span>
<a name="l00087"></a>00087             <span class="keywordflow">if</span> (myPreserveStates)
<a name="l00088"></a>00088             {
<a name="l00089"></a>00089                 GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glPushMatrix());
<a name="l00090"></a>00090                 GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPushMatrix());
<a name="l00091"></a>00091                 GLCheck(glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT   | GL_ENABLE_BIT  |
<a name="l00092"></a>00092                                      GL_TEXTURE_BIT      | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT));
<a name="l00093"></a>00093                 SetRenderStates();
<a name="l00094"></a>00094             }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096             <span class="comment">// Set the window viewport and transform matrices</span>
<a name="l00097"></a>00097             GLCheck(glViewport(0, 0, <a class="code" href="classsf_1_1RenderTarget.htm#4df749ecfddb5355d8357afe719cf681" title="Get the width of the rendering region of the target.">GetWidth</a>(), <a class="code" href="classsf_1_1RenderTarget.htm#9495774c371e0dd9ad9835ad2f34a03a" title="Get the height of the rendering region of the target.">GetHeight</a>()));
<a name="l00098"></a>00098             GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glLoadMatrixf(myCurrentView-&gt;<a class="code" href="classsf_1_1View.htm#98df64926582a286cad8600e432e4db1" title="Get the projection matrix of the view.">GetMatrix</a>().<a class="code" href="classsf_1_1Matrix3.htm#ff23cbd3d056d404a566a62dea4c98c1" title="Return the elements of the matrix as a 4x4, in an array of 16 floats.">Get4x4Elements</a>()));
<a name="l00099"></a>00099             GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glLoadIdentity());
<a name="l00100"></a>00100 
<a name="l00101"></a>00101             <span class="comment">// Let the object draw itself</span>
<a name="l00102"></a>00102             Object.<a class="code" href="classsf_1_1Drawable.htm#849c20578156747914d17d25c2c62682" title="Draw the object into the specified window.">Draw</a>(*<span class="keyword">this</span>);
<a name="l00103"></a>00103 
<a name="l00104"></a>00104             <span class="comment">// Restore render states</span>
<a name="l00105"></a>00105             <span class="keywordflow">if</span> (myPreserveStates)
<a name="l00106"></a>00106             {
<a name="l00107"></a>00107                 GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPopMatrix());
<a name="l00108"></a>00108                 GLCheck(glMatrixMode(GL_MODELVIEW));  GLCheck(glPopMatrix());
<a name="l00109"></a>00109                 GLCheck(glPopAttrib());
<a name="l00110"></a>00110             }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112             <span class="comment">// Deactivate rendering on this target</span>
<a name="l00113"></a>00113             Activate(<span class="keyword">false</span>);
<a name="l00114"></a>00114         }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116         myIsDrawing = <span class="keyword">false</span>;
<a name="l00117"></a>00117     }
<a name="l00118"></a>00118     <span class="keywordflow">else</span>
<a name="l00119"></a>00119     {
<a name="l00120"></a>00120         <span class="comment">// We are already called from a previous Draw : we don't need to set the states again, just draw the object</span>
<a name="l00121"></a>00121         Object.<a class="code" href="classsf_1_1Drawable.htm#849c20578156747914d17d25c2c62682" title="Draw the object into the specified window.">Draw</a>(*<span class="keyword">this</span>);
<a name="l00122"></a>00122     }
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 
<a name="l00129"></a><a class="code" href="classsf_1_1RenderTarget.htm#7060ca19e685d8d5b7c6f5dd9b5906e1">00129</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1RenderTarget.htm#7060ca19e685d8d5b7c6f5dd9b5906e1" title="Change the current active view.">RenderTarget::SetView</a>(<span class="keyword">const</span> <a class="code" href="classsf_1_1View.htm" title="This class defines a view (position, size, etc.">View</a>&amp; NewView)
<a name="l00130"></a>00130 {
<a name="l00131"></a>00131     myCurrentView = &amp;NewView;
<a name="l00132"></a>00132 }
<a name="l00133"></a>00133 
<a name="l00134"></a>00134 
<a name="l00138"></a><a class="code" href="classsf_1_1RenderTarget.htm#d426b7ba51cc6970fb828a2bef020274">00138</a> <span class="keyword">const</span> <a class="code" href="classsf_1_1View.htm" title="This class defines a view (position, size, etc.">View</a>&amp; <a class="code" href="classsf_1_1RenderTarget.htm#d426b7ba51cc6970fb828a2bef020274" title="Get the current view.">RenderTarget::GetView</a>()<span class="keyword"> const</span>
<a name="l00139"></a>00139 <span class="keyword"></span>{
<a name="l00140"></a>00140     <span class="keywordflow">return</span> *myCurrentView;
<a name="l00141"></a>00141 }
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 
<a name="l00147"></a><a class="code" href="classsf_1_1RenderTarget.htm#16db9179a7f035c59b8ecdd10cc2e699">00147</a> <a class="code" href="classsf_1_1View.htm" title="This class defines a view (position, size, etc.">View</a>&amp; <a class="code" href="classsf_1_1RenderTarget.htm#16db9179a7f035c59b8ecdd10cc2e699" title="Get the default view of the window for read / write.">RenderTarget::GetDefaultView</a>()
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149     <span class="keywordflow">return</span> myDefaultView;
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 
<a name="l00161"></a><a class="code" href="classsf_1_1RenderTarget.htm#b763d16f00166b516fead600d8824c71">00161</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1RenderTarget.htm#b763d16f00166b516fead600d8824c71" title="Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.">RenderTarget::PreserveOpenGLStates</a>(<span class="keywordtype">bool</span> Preserve)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163     myPreserveStates = Preserve;
<a name="l00164"></a>00164 }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 
<a name="l00170"></a><a class="code" href="classsf_1_1RenderTarget.htm#3d9265548b6903ab7f645d12177bba24">00170</a> <span class="keywordtype">void</span> <a class="code" href="classsf_1_1RenderTarget.htm#3d9265548b6903ab7f645d12177bba24" title="Called by the derived class when it&amp;#39;s ready to be initialized.">RenderTarget::Initialize</a>()
<a name="l00171"></a>00171 {
<a name="l00172"></a>00172     <span class="comment">// Set the default rendering states</span>
<a name="l00173"></a>00173     SetRenderStates();
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     <span class="comment">// Setup the default view</span>
<a name="l00176"></a>00176     myDefaultView.<a class="code" href="classsf_1_1View.htm#a5c2ac8985a573632f9a1e95d56cc2ee" title="Rebuild the view from a rectangle.">SetFromRect</a>(<a class="code" href="classsf_1_1Rect.htm">FloatRect</a>(0, 0, static_cast&lt;float&gt;(<a class="code" href="classsf_1_1RenderTarget.htm#4df749ecfddb5355d8357afe719cf681" title="Get the width of the rendering region of the target.">GetWidth</a>()), static_cast&lt;float&gt;(<a class="code" href="classsf_1_1RenderTarget.htm#9495774c371e0dd9ad9835ad2f34a03a" title="Get the height of the rendering region of the target.">GetHeight</a>())));
<a name="l00177"></a>00177     <a class="code" href="classsf_1_1RenderTarget.htm#7060ca19e685d8d5b7c6f5dd9b5906e1" title="Change the current active view.">SetView</a>(myDefaultView);
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 
<a name="l00184"></a>00184 <span class="keywordtype">void</span> RenderTarget::SetRenderStates()
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186     GLCheck(glDisable(GL_ALPHA_TEST));
<a name="l00187"></a>00187     GLCheck(glDisable(GL_DEPTH_TEST));
<a name="l00188"></a>00188     GLCheck(glDisable(GL_LIGHTING)); 
<a name="l00189"></a>00189 }
<a name="l00190"></a>00190 
<a name="l00191"></a>00191 } <span class="comment">// namespace sf</span>
</pre></div></div>

        <p id="footer">
            &nbsp;::&nbsp; Copyright &copy; 2007-2008 Laurent Gomila, all rights reserved &nbsp;::&nbsp;
            Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen 1.5.2</a> &nbsp;::&nbsp;
        </p>

    </body>
</html>