SFML logo
  • Main Page
  • Namespaces
  • Classes
  • Files
  • File List

RenderImage.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Graphics/RenderImage.hpp>
00029 #include <SFML/Graphics/RenderImageImplFBO.hpp>
00030 #include <SFML/Graphics/RenderImageImplPBuffer.hpp>
00031 #include <iostream>
00032 
00033 
00034 namespace sf
00035 {
00039 RenderImage::RenderImage() :
00040 myRenderImage(NULL)
00041 {
00042 
00043 }
00044 
00045 
00049 RenderImage::~RenderImage()
00050 {
00051     // Destroy the implementation
00052     delete myRenderImage;
00053 }
00054 
00055 
00059 bool RenderImage::Create(unsigned int Width, unsigned int Height, bool DepthBuffer)
00060 {
00061     // Make sure render-images are supported
00062     if (!CanUseRenderImage())
00063     {
00064         std::cerr << "Impossible to create render image (your system doesn't support this feature)" << std::endl;
00065         return false;
00066     }
00067 
00068     // Create the image
00069     if (!myImage.Create(Width, Height))
00070     {
00071         std::cerr << "Impossible to create render image (failed to create the target image)" << std::endl;
00072         return false;
00073     }
00074 
00075     // Adjust the view
00076     GetDefaultView().SetFromRect(FloatRect(0, 0, static_cast<float>(Width), static_cast<float>(Height)));
00077 
00078     // Create the implementation
00079     delete myRenderImage;
00080     if (priv::RenderImageImplFBO::IsSupported())
00081     {
00082         myRenderImage = new priv::RenderImageImplFBO(myImage);
00083     }
00084     else if (priv::RenderImageImplPBuffer::IsSupported())
00085     {
00086         myRenderImage = new priv::RenderImageImplPBuffer(myImage);
00087     }
00088     else
00089     {
00090         myRenderImage = NULL;
00091         std::cerr << "Impossible to create render image (no implementation is supported)" << std::endl;
00092         return false;
00093     }
00094 
00095     // Initialize the render image
00096     if (!myRenderImage->Create(DepthBuffer))
00097         return false;
00098 
00099     return true;
00100 }
00101 
00102 
00107 bool RenderImage::SetActive(bool Active) const
00108 {
00109     return myRenderImage && myRenderImage->Activate(Active);
00110 }
00111 
00112 
00116 unsigned int RenderImage::GetWidth() const
00117 {
00118     return myImage.GetWidth();
00119 }
00120 
00121 
00125 unsigned int RenderImage::GetHeight() const
00126 {
00127     return myImage.GetHeight();
00128 }
00129 
00130 
00134 const Image& RenderImage::GetImage() const
00135 {
00136     return myImage;
00137 }
00138 
00139 
00143 bool RenderImage::CanUseRenderImage()
00144 {
00145     return priv::RenderImageImplFBO::IsSupported() ||
00146            priv::RenderImageImplPBuffer::IsSupported();
00147 }
00148 
00149 
00153 bool RenderImage::Activate(bool Active)
00154 {
00155     return SetActive(Active);
00156 }
00157 
00158 } // namespace sf

 ::  Copyright © 2007-2008 Laurent Gomila, all rights reserved  ::  Documentation generated by doxygen 1.5.2  ::