Added RenderImage

Cleaned internal CSFML code
Synchronized with trunk

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1135 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-06-11 15:49:36 +00:00
commit 2deb8bd021
228 changed files with 15844 additions and 7152 deletions

View file

@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/ImageLoader.hpp>
#include <SFML/Graphics/RenderImage.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <algorithm>
@ -48,7 +49,9 @@ myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
myNeedArrayUpdate (false),
myUpdateSource (NULL),
myPixelsFlipped (false)
{
}
@ -67,7 +70,9 @@ myTexture (0),
myIsSmooth (Copy.myIsSmooth),
myPixels (Copy.myPixels),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
myNeedArrayUpdate (false),
myUpdateSource (Copy.myUpdateSource),
myPixelsFlipped (Copy.myPixelsFlipped)
{
CreateTexture();
}
@ -84,7 +89,9 @@ myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
myNeedArrayUpdate (false),
myUpdateSource (NULL),
myPixelsFlipped (false)
{
Create(Width, Height, Col);
}
@ -101,7 +108,9 @@ myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
myNeedArrayUpdate (false),
myUpdateSource (NULL),
myPixelsFlipped (false)
{
LoadFromPixels(Width, Height, Data);
}
@ -209,7 +218,7 @@ bool Image::LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8*
bool Image::SaveToFile(const std::string& Filename) const
{
// Check if the array of pixels needs to be updated
EnsureArrayUpdate();
const_cast<Image*>(this)->EnsureArrayUpdate();
// Let the image loader save our pixel array into the image
return priv::ImageLoader::GetInstance().SaveImageToFile(Filename, myPixels, myWidth, myHeight);
@ -275,7 +284,7 @@ void Image::Copy(const Image& Source, unsigned int DestX, unsigned int DestY, co
// Make sure both images have up-to-date arrays
EnsureArrayUpdate();
Source.EnsureArrayUpdate();
const_cast<Image&>(Source).EnsureArrayUpdate();
// Adjust the source rectangle
IntRect SrcRect = SourceRect;
@ -390,7 +399,8 @@ bool Image::CopyScreen(RenderWindow& Window, const IntRect& SourceRect)
GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
myNeedTextureUpdate = false;
myNeedArrayUpdate = true;
myNeedArrayUpdate = true;
myPixelsFlipped = true;
return true;
}
@ -431,7 +441,7 @@ void Image::SetPixel(unsigned int X, unsigned int Y, const Color& Col)
const Color& Image::GetPixel(unsigned int X, unsigned int Y) const
{
// First check if the array of pixels needs to be updated
EnsureArrayUpdate();
const_cast<Image*>(this)->EnsureArrayUpdate();
// Check if pixel is whithin the image bounds
if ((X >= myWidth) || (Y >= myHeight))
@ -453,7 +463,7 @@ const Color& Image::GetPixel(unsigned int X, unsigned int Y) const
const Uint8* Image::GetPixelsPtr() const
{
// First check if the array of pixels needs to be updated
EnsureArrayUpdate();
const_cast<Image*>(this)->EnsureArrayUpdate();
if (!myPixels.empty())
{
@ -473,7 +483,7 @@ const Uint8* Image::GetPixelsPtr() const
void Image::Bind() const
{
// First check if the texture needs to be updated
EnsureTextureUpdate();
const_cast<Image*>(this)->EnsureTextureUpdate();
// Bind it
if (myTexture)
@ -544,20 +554,26 @@ FloatRect Image::GetTexCoords(const IntRect& Rect, bool Adjust) const
float Width = static_cast<float>(myTextureWidth);
float Height = static_cast<float>(myTextureHeight);
FloatRect Coords;
if (Adjust && myIsSmooth)
{
return FloatRect((Rect.Left + 0.5f) / Width,
(Rect.Top + 0.5f) / Height,
(Rect.Right - 0.5f) / Width,
(Rect.Bottom - 0.5f) / Height);
Coords.Left = (Rect.Left + 0.5f) / Width;
Coords.Top = (Rect.Top + 0.5f) / Height;
Coords.Right = (Rect.Right - 0.5f) / Width;
Coords.Bottom = (Rect.Bottom - 0.5f) / Height;
}
else
{
return FloatRect(Rect.Left / Width,
Rect.Top / Height,
Rect.Right / Width,
Rect.Bottom / Height);
Coords.Left = Rect.Left / Width;
Coords.Top = Rect.Top / Height;
Coords.Right = Rect.Right / Width;
Coords.Bottom = Rect.Bottom / Height;
}
if (myPixelsFlipped)
std::swap(Coords.Top, Coords.Bottom);
return Coords;
}
@ -601,6 +617,8 @@ Image& Image::operator =(const Image& Other)
std::swap(myIsSmooth, Temp.myIsSmooth);
std::swap(myNeedArrayUpdate, Temp.myNeedArrayUpdate);
std::swap(myNeedTextureUpdate, Temp.myNeedTextureUpdate);
std::swap(myUpdateSource, Temp.myUpdateSource);
std::swap(myPixelsFlipped, Temp.myPixelsFlipped);
myPixels.swap(Temp.myPixels);
return *this;
@ -666,19 +684,28 @@ bool Image::CreateTexture()
/// Make sure the texture in video memory is updated with the
/// array of pixels
////////////////////////////////////////////////////////////
void Image::EnsureTextureUpdate() const
void Image::EnsureTextureUpdate()
{
if (myNeedTextureUpdate)
{
// Copy the pixels
if (myTexture && !myPixels.empty())
if (myTexture)
{
GLint PreviousTexture;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
// Update the texture with the pixels array in RAM
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
if (myUpdateSource)
{
// External update
myPixelsFlipped = myUpdateSource->UpdateImage(*this);
myUpdateSource = NULL;
}
else if (!myPixels.empty())
{
// Update the texture with the pixels array in RAM
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myWidth, myHeight, GL_RGBA, GL_UNSIGNED_BYTE, &myPixels[0]));
myPixelsFlipped = false;
}
GLCheck(glBindTexture(GL_TEXTURE_2D, PreviousTexture));
}
@ -692,10 +719,14 @@ void Image::EnsureTextureUpdate() const
/// Make sure the array of pixels is updated with the
/// texture in video memory
////////////////////////////////////////////////////////////
void Image::EnsureArrayUpdate() const
void Image::EnsureArrayUpdate()
{
if (myNeedArrayUpdate)
{
// First make sure the texture is up-to-date
// (may not be the case if an external update has been scheduled)
EnsureTextureUpdate();
// Save the previous texture
GLint PreviousTexture;
GLCheck(glGetIntegerv(GL_TEXTURE_BINDING_2D, &PreviousTexture));
@ -703,7 +734,7 @@ void Image::EnsureArrayUpdate() const
// Resize the destination array of pixels
myPixels.resize(myWidth * myHeight);
if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight))
if ((myWidth == myTextureWidth) && (myHeight == myTextureHeight) && !myPixelsFlipped)
{
// Texture and array have the same size, we can use a direct copy
@ -723,10 +754,19 @@ void Image::EnsureArrayUpdate() const
// The we copy the useful pixels from the temporary array to the final one
const Color* Src = &AllPixels[0];
Color* Dst = &myPixels[0];
int SrcPitch = myTextureWidth;
// Handle the case where source pixels are flipped vertically
if (myPixelsFlipped)
{
Src += myTextureWidth * (myHeight - 1);
SrcPitch = -SrcPitch;
}
for (unsigned int i = 0; i < myHeight; ++i)
{
std::copy(Src, Src + myWidth, Dst);
Src += myTextureWidth;
Src += SrcPitch;
Dst += myWidth;
}
}
@ -739,6 +779,19 @@ void Image::EnsureArrayUpdate() const
}
////////////////////////////////////////////////////////////
/// Notify the image that an external source has modified
/// its content.
/// For internal use only (see RenderImage class).
////////////////////////////////////////////////////////////
void Image::ExternalUpdate(RenderImage& Source)
{
myNeedTextureUpdate = true;
myNeedArrayUpdate = true;
myUpdateSource = &Source;
}
////////////////////////////////////////////////////////////
/// Reset the image attributes
////////////////////////////////////////////////////////////
@ -754,6 +807,8 @@ void Image::Reset()
myIsSmooth = true;
myNeedTextureUpdate = false;
myNeedArrayUpdate = false;
myUpdateSource = NULL;
myPixelsFlipped = false;
myPixels.clear();
}

View file

@ -306,10 +306,10 @@ void PostFX::Render(RenderTarget& Target) const
// Render a fullscreen quad using the effect on our framebuffer
FloatRect Screen = Target.GetView().GetRect();
glBegin(GL_QUADS);
glTexCoord2f(TexCoords.Left, TexCoords.Top); glVertex2f(Screen.Left, Screen.Bottom);
glTexCoord2f(TexCoords.Right, TexCoords.Top); glVertex2f(Screen.Right, Screen.Bottom);
glTexCoord2f(TexCoords.Right, TexCoords.Bottom); glVertex2f(Screen.Right, Screen.Top);
glTexCoord2f(TexCoords.Left, TexCoords.Bottom); glVertex2f(Screen.Left, Screen.Top);
glTexCoord2f(TexCoords.Left, TexCoords.Top); glVertex2f(Screen.Left, Screen.Top);
glTexCoord2f(TexCoords.Right, TexCoords.Top); glVertex2f(Screen.Right, Screen.Top);
glTexCoord2f(TexCoords.Right, TexCoords.Bottom); glVertex2f(Screen.Right, Screen.Bottom);
glTexCoord2f(TexCoords.Left, TexCoords.Bottom); glVertex2f(Screen.Left, Screen.Bottom);
glEnd();
// Disable program

View file

@ -0,0 +1,177 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.hpp>
#include <SFML/Graphics/RenderImageImplFBO.hpp>
#include <SFML/Graphics/RenderImageImplPBuffer.hpp>
#include <iostream>
namespace sf
{
////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
RenderImage::RenderImage() :
myRenderImage(NULL)
{
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
RenderImage::~RenderImage()
{
SetActive(false);
delete myRenderImage;
}
////////////////////////////////////////////////////////////
/// Create the render image from its dimensions
////////////////////////////////////////////////////////////
bool RenderImage::Create(unsigned int Width, unsigned int Height, bool DepthBuffer)
{
// Make sure that render-images are supported
if (!CanUseRenderImage())
{
std::cerr << "Impossible to create render image (your system doesn't support this feature)" << std::endl;
return false;
}
// Create the image
if (!myImage.Create(Width, Height))
{
std::cerr << "Impossible to create render image (failed to create the target image)" << std::endl;
return false;
}
// Create the implementation
delete myRenderImage;
if (priv::RenderImageImplFBO::IsSupported())
{
// Use FBO
myRenderImage = new priv::RenderImageImplFBO;
}
else if (priv::RenderImageImplPBuffer::IsSupported())
{
// Use P-Buffer
myRenderImage = new priv::RenderImageImplPBuffer;
}
// Initialize the render image
if (!myRenderImage->Create(Width, Height, myImage.myTexture, DepthBuffer))
return false;
// We can now initialize the render target part
RenderTarget::Initialize();
return true;
}
////////////////////////////////////////////////////////////
/// Activate of deactivate the render-image as the current target
/// for rendering
////////////////////////////////////////////////////////////
bool RenderImage::SetActive(bool Active)
{
if (myRenderImage && myRenderImage->Activate(Active))
{
// After the RenderImage has been modified, we have to notify
// the underlying image that its pixels have changed
if (!Active)
myImage.ExternalUpdate(*this);
return true;
}
else
{
return false;
}
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of the image
////////////////////////////////////////////////////////////
unsigned int RenderImage::GetWidth() const
{
return myImage.GetWidth();
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of the image
////////////////////////////////////////////////////////////
unsigned int RenderImage::GetHeight() const
{
return myImage.GetHeight();
}
////////////////////////////////////////////////////////////
/// Get the target image
////////////////////////////////////////////////////////////
const Image& RenderImage::GetImage() const
{
return myImage;
}
////////////////////////////////////////////////////////////
/// Check whether the system supports render images or not
////////////////////////////////////////////////////////////
bool RenderImage::CanUseRenderImage()
{
return priv::RenderImageImplFBO::IsSupported() ||
priv::RenderImageImplPBuffer::IsSupported();
}
////////////////////////////////////////////////////////////
/// Update the pixels of the target image.
/// This function is called automatically by the image when it
/// needs to update its pixels, and is only meant for internal use.
////////////////////////////////////////////////////////////
bool RenderImage::UpdateImage(Image& Target)
{
return myRenderImage && myRenderImage->UpdateTexture(Target.myTexture);
}
////////////////////////////////////////////////////////////
/// Activate / deactivate the render image for rendering
////////////////////////////////////////////////////////////
bool RenderImage::Activate(bool Active)
{
return SetActive(Active);
}
} // namespace sf

View file

@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImageImpl.hpp>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
RenderImageImpl::~RenderImageImpl()
{
}
} // namespace priv
} // namespace sf

View file

@ -0,0 +1,88 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGEIMPL_HPP
#define SFML_RENDERIMAGEIMPL_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/NonCopyable.hpp>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Abstract base class for render-image implementations
////////////////////////////////////////////////////////////
class RenderImageImpl : NonCopyable
{
public :
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderImageImpl();
////////////////////////////////////////////////////////////
/// Create the render image
///
/// \param Width : Width of the image to render to
/// \param Height : Height of the image to render to
/// \param TextureId : OpenGL texture identifier of the target image
/// \param DepthBuffer : Do you want a depth buffer attached ?
///
/// \return True if creation has been successful
///
////////////////////////////////////////////////////////////
virtual bool Create(unsigned int Width, unsigned int Height, unsigned int TextureId, bool DepthBuffer) = 0;
////////////////////////////////////////////////////////////
/// Activate / deactivate the render image for rendering
///
/// \param Active : True to activate, false to deactivate
///
////////////////////////////////////////////////////////////
virtual bool Activate(bool Active) = 0;
////////////////////////////////////////////////////////////
/// Update the pixels of the target texture
///
/// \param TextureId : OpenGL identifier of the target texture
///
/// \return True if the new pixels are flipped vertically
///
////////////////////////////////////////////////////////////
virtual bool UpdateTexture(unsigned int TextureId) = 0;
};
} // namespace priv
} // namespace sf
#endif // SFML_RENDERIMAGEIMPL_HPP

View file

@ -0,0 +1,175 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImageImplFBO.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <iostream>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
RenderImageImplFBO::RenderImageImplFBO() :
myFrameBuffer(0),
myDepthBuffer(0)
{
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
RenderImageImplFBO::~RenderImageImplFBO()
{
// Destroy the depth buffer
if (myDepthBuffer)
{
GLuint DepthBuffer = static_cast<GLuint>(myDepthBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &DepthBuffer));
}
// Destroy the frame buffer
if (myFrameBuffer)
{
GLuint FrameBuffer = static_cast<GLuint>(myFrameBuffer);
GLCheck(glDeleteFramebuffersEXT(1, &FrameBuffer));
}
}
////////////////////////////////////////////////////////////
/// Check whether the system supports FBOs or not
////////////////////////////////////////////////////////////
bool RenderImageImplFBO::IsSupported()
{
// Make sure that GLEW is initialized
EnsureGlewInit();
return glewIsSupported("GL_EXT_framebuffer_object") != 0;
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Create
////////////////////////////////////////////////////////////
bool RenderImageImplFBO::Create(unsigned int Width, unsigned int Height, unsigned int TextureId, bool DepthBuffer)
{
// Create the framebuffer object if not already done
if (!myFrameBuffer)
{
GLuint FrameBuffer = 0;
GLCheck(glGenFramebuffersEXT(1, &FrameBuffer));
myFrameBuffer = static_cast<unsigned int>(FrameBuffer);
if (!myFrameBuffer)
{
std::cerr << "Impossible to create render image (failed to create the frame buffer object)" << std::endl;
return false;
}
}
// Bind the framebuffer
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer));
// Create the depth buffer
if (myDepthBuffer)
{
GLuint DepthBuffer = static_cast<GLuint>(myDepthBuffer);
GLCheck(glDeleteRenderbuffersEXT(1, &DepthBuffer));
}
if (DepthBuffer)
{
GLuint DepthBuffer = 0;
GLCheck(glGenRenderbuffersEXT(1, &DepthBuffer));
myDepthBuffer = static_cast<unsigned int>(DepthBuffer);
if (!myDepthBuffer)
{
std::cerr << "Impossible to create render image (failed to create the attached depth buffer)" << std::endl;
return false;
}
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myDepthBuffer));
GLCheck(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, Width, Height));
GLCheck(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, myDepthBuffer));
}
// Link the image to the frame buffer
GLCheck(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, TextureId, 0));
// A final check, just to be sure...
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
{
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
std::cerr << "Impossible to create render image (failed to link the target image to the frame buffer)" << std::endl;
return false;
}
// Unbind the buffers
Activate(false);
return true;
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Activate
////////////////////////////////////////////////////////////
bool RenderImageImplFBO::Activate(bool Active)
{
if (Active)
{
// Bind the buffers
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer));
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myDepthBuffer));
}
else
{
// Unbind the buffers
GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0));
}
return true;
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::UpdateTexture
////////////////////////////////////////////////////////////
bool RenderImageImplFBO::UpdateTexture(unsigned int /*TextureId*/)
{
// Nothing to do: the FBO draws directly into the target image
return true;
}
} // namespace priv
} // namespace sf

View file

@ -0,0 +1,98 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGEIMPLFBO_HPP
#define SFML_RENDERIMAGEIMPLFBO_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImageImpl.hpp>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Specialization of RenderImageImpl using the
/// FrameBuffer Object extension
////////////////////////////////////////////////////////////
class RenderImageImplFBO : public RenderImageImpl
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
RenderImageImplFBO();
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~RenderImageImplFBO();
////////////////////////////////////////////////////////////
/// Check whether the system supports FBOs or not
///
/// \return True if FBO render images are supported
///
////////////////////////////////////////////////////////////
static bool IsSupported();
private :
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Create
///
////////////////////////////////////////////////////////////
virtual bool Create(unsigned int Width, unsigned int Height, unsigned int TextureId, bool DepthBuffer);
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Activate
///
////////////////////////////////////////////////////////////
virtual bool Activate(bool Active);
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::UpdateTexture
///
////////////////////////////////////////////////////////////
virtual bool UpdateTexture(unsigned TextureId);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int myFrameBuffer; ///< OpenGL frame buffer object
unsigned int myDepthBuffer; ///< Optional depth buffer attached to the frame buffer
};
} // namespace priv
} // namespace sf
#endif // SFML_RENDERIMAGEIMPLFBO_HPP

View file

@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#if defined(SFML_SYSTEM_WINDOWS)
#include <SFML/Graphics/Win32/RenderImageImplPBuffer.hpp>
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
#include <SFML/Graphics/Linux/RenderImageImplPBuffer.hpp>
#elif defined(SFML_SYSTEM_WINDOWS)
#include <SFML/Graphics/MacOSX/RenderImageImplPBuffer.hpp>
#endif

View file

@ -169,12 +169,17 @@ void RenderTarget::PreserveOpenGLStates(bool Preserve)
////////////////////////////////////////////////////////////
void RenderTarget::Initialize()
{
// Set the default rendering states
SetRenderStates();
if (Activate(true))
{
// Set the default rendering states
SetRenderStates();
// Setup the default view
myDefaultView.SetFromRect(FloatRect(0, 0, static_cast<float>(GetWidth()), static_cast<float>(GetHeight())));
SetView(myDefaultView);
// Setup the default view
myDefaultView.SetFromRect(FloatRect(0, 0, static_cast<float>(GetWidth()), static_cast<float>(GetHeight())));
SetView(myDefaultView);
Activate(false);
}
}
@ -185,7 +190,7 @@ void RenderTarget::SetRenderStates()
{
GLCheck(glDisable(GL_ALPHA_TEST));
GLCheck(glDisable(GL_DEPTH_TEST));
GLCheck(glDisable(GL_LIGHTING));
GLCheck(glDisable(GL_LIGHTING));
}
} // namespace sf

View file

@ -157,7 +157,7 @@ sf::Vector2f RenderWindow::ConvertCoords(unsigned int WindowX, unsigned int Wind
////////////////////////////////////////////////////////////
void RenderWindow::OnCreate()
{
// We can now initialize the render target part
// Just initialize the render target part
RenderTarget::Initialize();
}

View file

@ -162,8 +162,8 @@ Color Sprite::GetPixel(unsigned int X, unsigned int Y) const
unsigned int ImageX = mySubRect.Left + X;
unsigned int ImageY = mySubRect.Top + Y;
if (myIsFlippedX) ImageX = mySubRect.GetWidth() - ImageX;
if (myIsFlippedY) ImageY = mySubRect.GetHeight() - ImageY;
if (myIsFlippedX) ImageX = mySubRect.GetWidth() - ImageX - 1;
if (myIsFlippedY) ImageY = mySubRect.GetHeight() - ImageY - 1;
return myImage->GetPixel(ImageX, ImageY) * GetColor();
}

View file

@ -0,0 +1,218 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Win32/RenderImageImplPBuffer.hpp>
#include <SFML/Graphics/GLCheck.hpp>
#include <SFML/Window/Context.hpp>
#include <iostream>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
RenderImageImplPBuffer::RenderImageImplPBuffer() :
myPBuffer (NULL),
myDeviceContext(NULL),
myContext (NULL),
myWidth (0),
myHeight (0)
{
}
////////////////////////////////////////////////////////////
/// Destructor
////////////////////////////////////////////////////////////
RenderImageImplPBuffer::~RenderImageImplPBuffer()
{
if (myContext)
{
wglDeleteContext(myContext);
}
if (myPBuffer && myDeviceContext)
{
wglReleasePbufferDCARB(myPBuffer, myDeviceContext);
wglDestroyPbufferARB(myPBuffer);
}
// This is to make sure that another valid context is made
// active after we destroy the P-Buffer's one
Context Ctx;
}
////////////////////////////////////////////////////////////
/// Check whether the system supports FBOs or not
////////////////////////////////////////////////////////////
bool RenderImageImplPBuffer::IsSupported()
{
// Make sure that GLEW is initialized
EnsureGlewInit();
return wglewIsSupported("WGL_ARB_pbuffer") &&
wglewIsSupported("WGL_ARB_pixel_format");
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Create
////////////////////////////////////////////////////////////
bool RenderImageImplPBuffer::Create(unsigned int Width, unsigned int Height, unsigned int /*TextureId*/, bool DepthBuffer)
{
// Store the dimensions
myWidth = Width;
myHeight = Height;
// Get the current HDC
HDC CurrentDeviceContext = wglGetCurrentDC();
// Define the minimum PBuffer attributes
int Attributes[] =
{
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DRAW_TO_PBUFFER_ARB, GL_TRUE,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, (DepthBuffer ? 24 : 0),
WGL_DOUBLE_BUFFER_ARB, GL_FALSE,
0
};
// Select the best pixel format for our attributes
unsigned int NbFormats = 0;
int PixelFormat = -1;
wglChoosePixelFormatARB(CurrentDeviceContext, Attributes, NULL, 1, &PixelFormat, &NbFormats);
// Make sure that one pixel format has been found
if (NbFormats == 0)
{
std::cerr << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl;
return false;
}
// Create the P-Buffer and its OpenGL context
myPBuffer = wglCreatePbufferARB(CurrentDeviceContext, PixelFormat, Width, Height, NULL);
myDeviceContext = wglGetPbufferDCARB(myPBuffer);
myContext = wglCreateContext(myDeviceContext);
// Check errors
if (!myPBuffer || !myDeviceContext || !myContext)
{
std::cerr << "Impossible to create render image (failed to create PBuffer)" << std::endl;
return false;
}
// Check the actual size of the P-Buffer
int ActualWidth, ActualHeight;
wglQueryPbufferARB(myPBuffer, WGL_PBUFFER_WIDTH_ARB, &ActualWidth);
wglQueryPbufferARB(myPBuffer, WGL_PBUFFER_HEIGHT_ARB, &ActualHeight);
if ((ActualWidth != static_cast<int>(Width)) || (ActualHeight != static_cast<int>(Height)))
{
std::cerr << "Impossible to create render image (failed to match the requested size). "
<< "Size: " << ActualWidth << "x" << ActualHeight << " - "
<< "Requested: " << Width << "x" << Height
<< std::endl;
return false;
}
// Share the P-Buffer context with the current context
HGLRC CurrentContext = wglGetCurrentContext();
if (CurrentContext)
{
wglMakeCurrent(NULL, NULL);
wglShareLists(CurrentContext, myContext);
wglMakeCurrent(CurrentDeviceContext, CurrentContext);
}
return true;
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Activate
////////////////////////////////////////////////////////////
bool RenderImageImplPBuffer::Activate(bool Active)
{
if (Active)
{
if (myDeviceContext && myContext && (wglGetCurrentContext() != myContext))
{
// Bind the OpenGL context of the P-Buffer
if (!wglMakeCurrent(myDeviceContext, myContext))
{
std::cout << "Failed to activate render image" << std::endl;
return false;
}
}
}
else
{
// We don't actually unbind the P-Buffer, for performances reasons
}
return true;
}
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::UpdateTexture
////////////////////////////////////////////////////////////
bool RenderImageImplPBuffer::UpdateTexture(unsigned int TextureId)
{
// Store the current active context
HDC CurrentDeviceContext = wglGetCurrentDC();
HGLRC CurrentContext = wglGetCurrentContext();
if (Activate(true))
{
// Bind the texture
GLCheck(glEnable(GL_TEXTURE_2D));
GLCheck(glBindTexture(GL_TEXTURE_2D, TextureId));
// Copy the rendered pixels to the image
GLCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, myWidth, myHeight));
// Restore the previous context
wglMakeCurrent(CurrentDeviceContext, CurrentContext);
return true;
}
return false;
}
} // namespace priv
} // namespace sf

View file

@ -0,0 +1,102 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGEIMPLPBUFFER_HPP
#define SFML_RENDERIMAGEIMPLPBUFFER_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImageImpl.hpp>
#include <SFML/Graphics/GLEW/glew.h>
#include <SFML/Graphics/GLEW/wglew.h>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Specialization of RenderImageImpl using WGL P-Buffers
////////////////////////////////////////////////////////////
class RenderImageImplPBuffer : public RenderImageImpl
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
RenderImageImplPBuffer();
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~RenderImageImplPBuffer();
////////////////////////////////////////////////////////////
/// Check whether the system supports P-Buffer or not
///
/// \return True if P-Buffer render images are supported
///
////////////////////////////////////////////////////////////
static bool IsSupported();
private :
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Create
///
////////////////////////////////////////////////////////////
virtual bool Create(unsigned int Width, unsigned int Height, unsigned int TextureId, bool DepthBuffer);
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::Activate
///
////////////////////////////////////////////////////////////
virtual bool Activate(bool Active);
////////////////////////////////////////////////////////////
/// /see RenderImageImpl::UpdateTexture
///
////////////////////////////////////////////////////////////
virtual bool UpdateTexture(unsigned TextureId);
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
HPBUFFERARB myPBuffer; ///< P-Buffer
HDC myDeviceContext; ///< Associated device context
HGLRC myContext; ///< Associated OpenGL context
unsigned int myWidth; ///< Width of the P-Buffer
unsigned int myHeight; ///< Height of the P-Buffer
};
} // namespace priv
} // namespace sf
#endif // SFML_RENDERIMAGEIMPLPBUFFER_HPP

View file

@ -21,8 +21,7 @@ export CFLAGS = -W -Wall -pedantic -I../../../include -I../../ $(DEBUGFLAGS)
export CFLAGSEXT = -I../../../include -I../.. $(DEBUGFLAGS) $(BUILDFLAGS)
export LDFLAGS = $(LINKFLAGS)
export LIBPATH = ../../../lib
export VERSION = 2.0
export CP = cp
export VERSION = 2.0export CP = cp
export LN = ln
export LNFLAGS = -s -f
export AR = ar

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -44,6 +44,8 @@ static AppController *shared = nil;
@end
#endif
#define ENABLE_FADE_OPERATIONS 1
@implementation NSApplication (SFML)
- (void)setRunning:(BOOL)flag
@ -388,7 +390,7 @@ static AppController *shared = nil;
- (void)setFullscreenWindow:(WindowWrapper *)aWrapper mode:(sf::VideoMode *)fullscreenMode
{
// If we have a fullscreen window and want to remove it
if (myFullscreenWrapper && aWrapper == nil)
if (aWrapper == nil && myFullscreenWrapper)
{
// Get the CoreGraphics display mode according to the desktop mode
CFDictionaryRef displayMode = CGDisplayBestModeForParameters (kCGDirectMainDisplay,
@ -397,8 +399,10 @@ static AppController *shared = nil;
myDesktopMode.Height,
NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to black screen
[self doFadeOperation:FillScreen time:0.2f sync:true];
#endif
// Switch to the desktop display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
@ -409,13 +413,15 @@ static AppController *shared = nil;
// Show the menu bar
[NSMenu setMenuBarVisible:YES];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen
[self doFadeOperation:CleanScreen time:0.5f sync:true];
#endif
// Release the saved window wrapper
[myFullscreenWrapper release], myFullscreenWrapper = nil;
myFullscreenWrapper = nil;
}
else if (myFullscreenWrapper == nil && aWrapper)
else if (aWrapper)
{
assert(fullscreenMode != NULL);
@ -426,24 +432,39 @@ static AppController *shared = nil;
fullscreenMode->Height,
NULL);
#if ENABLE_FADE_OPERATIONS
// Fade to a black screen
[self doFadeOperation:FillScreen time:0.5f sync:true];
#endif
// Hide to the main menu bar
[NSMenu setMenuBarVisible:NO];
if (!myFullscreenWrapper)
{
// Hide the main menu bar
[NSMenu setMenuBarVisible:NO];
}
// Switch to the wished display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
if (myPrevMode != *fullscreenMode)
{
// Switch to the wished display mode
CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode);
}
if (myFullscreenWrapper)
{
[[myFullscreenWrapper window] close];
}
// Open and center the window
[[aWrapper window] makeKeyAndOrderFront:nil];
[[aWrapper window] center];
#if ENABLE_FADE_OPERATIONS
// Fade to normal screen
[self doFadeOperation:CleanScreen time:0.2f sync:false];
#endif
// Save the fullscreen wrapper
myFullscreenWrapper = [aWrapper retain];
myFullscreenWrapper = aWrapper;
}
else
{
@ -453,7 +474,7 @@ static AppController *shared = nil;
////////////////////////////////////////////////////////////
/// Perform fade operation where 'operation' is one of { FillScreen, CleanScreen}
/// Perform fade operation where 'operation' is one of {FillScreen, CleanScreen}
/// and 'time' is the time during which you wish the operation to be performed.
/// Set 'sync' to true if you do not want the method to end before the end
/// of the fade operation. Pass the last used token or a new one if you are

View file

@ -155,13 +155,6 @@
title:(NSString *)title
delegate:(sf::priv::WindowImplCocoa *)delegate;
////////////////////////////////////////////////////////////
/// Finish the window setup (without knowing whether it's a imported
/// window)
////////////////////////////////////////////////////////////
/* - (void)setupGLViewAndWindow; */
////////////////////////////////////////////////////////////
/// Return a reference to the internal Cocoa window
////////////////////////////////////////////////////////////

View file

@ -77,6 +77,9 @@ static GLContext *sharedCtx = nil;
//
// I've no way to fix this for now.
if (attribs.AntialiasingLevel)
std::cerr << "Warning: antialiasing settings are inhibited under Mac OS X for technical reasons" << std::endl;
NSOpenGLPixelFormat *myPixelFormat = nil;
unsigned idx = 0;
@ -445,107 +448,6 @@ static GLContext *sharedCtx = nil;
title:(NSString *)title
delegate:(sf::priv::WindowImplCocoa *)delegate
{
/*
assert(title != nil);
assert(delegate != NULL);
self = [super init];
if (self)
{
NSRect frame = NSMakeRect (0.0f, 0.0f, (float) mode.Width, (float) mode.Height);
unsigned int mask = 0;
// We grab options from WindowStyle and add them to our window mask
if (style & sf::Style::None || style & sf::Style::Fullscreen) {
mask |= NSBorderlessWindowMask;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
// Check display mode and put new values in 'mode' if needed
boolean_t exact = true;
CFDictionaryRef properties = CGDisplayBestModeForParameters(kCGDirectMainDisplay, mode.BitsPerPixel,
mode.Width, mode.Height, &exact);
if (!properties) {
std::cerr << "Unable to get a display mode with the given parameters" << std::endl;
[self autorelease];
return nil;
}
if (exact == false) {
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayWidth),
kCFNumberIntType, &mode.Width);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayHeight),
kCFNumberIntType, &mode.Height);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayBitsPerPixel),
kCFNumberIntType, &mode.BitsPerPixel);
}
}
} else {
if (style & sf::Style::Titlebar) {
mask |= NSTitledWindowMask;
mask |= NSMiniaturizableWindowMask;
}
if (style & sf::Style::Resize) {
mask |= NSTitledWindowMask;
mask |= NSMiniaturizableWindowMask;
mask |= NSResizableWindowMask;
}
if (style & sf::Style::Close) {
mask |= NSTitledWindowMask;
mask |= NSClosableWindowMask;
mask |= NSMiniaturizableWindowMask;
}
}
// Now we make the window with the values we got
// Note: defer flag set to NO to be able to use OpenGL in our window
myWindow = [[GLWindow alloc] initWithContentRect:frame
styleMask:mask
backing:NSBackingStoreBuffered
defer:NO];
if (myWindow) {
// We set title and window position
[myWindow setTitle:title];
[myWindow center];
// Make the OpenGL view
myView = [[GLView alloc] initWithFrame:[[myWindow contentView] frame]
mode:mode
settings:params
delegate:delegate];
if (myView) {
// Finish setting up the view and window
[self setupGLViewAndWindow];
} else {
std::cerr << "Unable to create the OpenGL view" << std::endl;
[self autorelease];
return nil;
}
if (myIsFullscreen) {
myFullscreenMode = mode;
// Using this because full screen window was not always
// in front of the other application windows when unhiding app
[myWindow setLevel:NSFloatingWindowLevel];
}
}
}
return self;
*/
return [self initWithWindow:nil
settings:params
videoMode:mode
@ -565,43 +467,8 @@ static GLContext *sharedCtx = nil;
settings:(sf::WindowSettings&)params
delegate:(sf::priv::WindowImplCocoa *)delegate
{
/*
assert(window != NULL);
assert(delegate != NULL);
self = [super init];
if (self)
{
myWindow = (GLWindow *)[window retain];
sf::VideoMode mode([[myWindow contentView] frame].size.width,
[[myWindow contentView] frame].size.height);
// Make the OpenGL view
myView = [[GLView alloc] initWithFrame:[[myWindow contentView] frame]
mode:mode
settings:params
delegate:delegate];
if (myView)
{
// Finish setting up the view and window
[self setupGLViewAndWindow];
}
else
{
std::cerr << "Unable to create the OpenGL view" << std::endl;
[self autorelease];
return nil;
}
}
return self;
*/
sf::VideoMode mode([[myWindow contentView] frame].size.width, [[myWindow contentView] frame].size.height);
return [self initWithWindow:[window autorelease]
return [self initWithWindow:window
settings:params
videoMode:mode
style:0
@ -638,37 +505,39 @@ static GLContext *sharedCtx = nil;
NSRect frame = NSMakeRect (0.0f, 0.0f, (float) mode.Width, (float) mode.Height);
unsigned int mask = 0;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
// Check display mode and put new values in 'mode' if needed
boolean_t exact = true;
CFDictionaryRef properties = CGDisplayBestModeForParameters(kCGDirectMainDisplay, mode.BitsPerPixel,
mode.Width, mode.Height, &exact);
if (!properties) {
std::cerr << "Unable to get a display mode with the given parameters" << std::endl;
[self autorelease];
return nil;
}
if (exact == false) {
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayWidth),
kCFNumberIntType, &mode.Width);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayHeight),
kCFNumberIntType, &mode.Height);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayBitsPerPixel),
kCFNumberIntType, &mode.BitsPerPixel);
}
}
// We grab options from WindowStyle and add them to our window mask
if (style & sf::Style::None || style & sf::Style::Fullscreen) {
mask |= NSBorderlessWindowMask;
if (style & sf::Style::Fullscreen) {
myIsFullscreen = true;
// Check display mode and put new values in 'mode' if needed
boolean_t exact = true;
CFDictionaryRef properties = CGDisplayBestModeForParameters(kCGDirectMainDisplay, mode.BitsPerPixel,
mode.Width, mode.Height, &exact);
if (!properties) {
std::cerr << "Unable to get a display mode with the given parameters" << std::endl;
[self autorelease];
return nil;
}
if (exact == false) {
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayWidth),
kCFNumberIntType, &mode.Width);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayHeight),
kCFNumberIntType, &mode.Height);
CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(properties, kCGDisplayBitsPerPixel),
kCFNumberIntType, &mode.BitsPerPixel);
}
}
} else {
if (style & sf::Style::Titlebar) {
@ -768,53 +637,14 @@ static GLContext *sharedCtx = nil;
return self;
}
////////////////////////////////////////////////////////////
/// Finish the window setup (without knowing whether it's a imported
/// window)
////////////////////////////////////////////////////////////
/* - (void)setupGLViewAndWindow
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// We want to know when our window got the focus
[nc addObserver:myView
selector:@selector(windowDidBecomeMain:)
name:NSWindowDidBecomeMainNotification
object:myWindow];
// We want to know when our window lost the focus
[nc addObserver:myView
selector:@selector(windowDidResignMain:)
name:NSWindowDidResignMainNotification
object:myWindow];
// We want to know when the user closes the window
[nc addObserver:myView
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
object:myWindow];
// I want to re-center the window if it's a full screen one and moved by Spaces
[nc addObserver:myView
selector:@selector(windowDidMove:)
name:NSWindowDidMoveNotification
object:myWindow];
// Needed not to make application crash when releasing the window in our destructor
// (I prefer to take control of everything :P)
[myWindow setReleasedWhenClosed:NO];
[myWindow setAcceptsMouseMovedEvents:YES];
} */
////////////////////////////////////////////////////////////
/// Clean the window wrapper
////////////////////////////////////////////////////////////
- (void)dealloc
{
// Remove the notification observer
if (myView)
[[NSNotificationCenter defaultCenter] removeObserver:myView];
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Close the window

View file

@ -93,21 +93,30 @@ myWheelStatus(0.0f)
{
if (Handle)
{
// We create the window according to the given handle
myWrapper = [[WindowWrapper alloc] initWithWindow:(NSWindow *)Handle
settings:params
delegate:this];
if (myWrapper)
if (![(NSWindow *)Handle isKindOfClass:[NSWindow class]])
std::cerr << "Cannot import this Window Handle because it is not a <NSWindow *> object"
<< "(or one of its subclasses). You gave a <"
<< [[(NSWindow *)Handle className] UTF8String]
<< "> object." << std::endl;
else
{
// initial mouse state
myMouseIn = [myWrapper mouseInside];
// We set the myWidth and myHeight members to the correct values
myWidth = (int) [[myWrapper glView] frame].size.width;
myHeight = (int) [[myWrapper glView] frame].size.height;
} else {
std::cerr << "Failed to make the public window" << std::endl;
// We create the window according to the given handle
myWrapper = [[WindowWrapper alloc] initWithWindow:(NSWindow *)Handle
settings:params
delegate:this];
if (myWrapper)
{
// initial mouse state
myMouseIn = [myWrapper mouseInside];
// We set the myWidth and myHeight members to the correct values
myWidth = (int) [[myWrapper glView] frame].size.width;
myHeight = (int) [[myWrapper glView] frame].size.height;
} else {
std::cerr << "Failed to make the public window" << std::endl;
}
}
}
}

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.

View file

@ -49,6 +49,8 @@ void Joystick::Initialize(unsigned int Index)
// Get the Index-th connected joystick
MMRESULT Error;
JOYINFOEX JoyInfo;
JoyInfo.dwSize = sizeof(JoyInfo);
JoyInfo.dwFlags = JOY_RETURNALL;
for (unsigned int NbFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++)
{
// Check if the current joystick is connected