Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - stubler

Pages: [1]
1
I am using SFML for a rather non-traditional application. I am using it to animate a slide show. In doing so I have had to expose a few protected class members.

Reading large images fails because of texture size limitations. In order to load a large image, I have had to expose the ImageLoader. By doing so, I am able to read a large JPEG image and decimate it before creating a sf::Image using the LoadFromPixels function.

In animating the slide show, I often interpolate between transformation states. It would be easier to work directly with the transformation matrix. I see no reason not to expose GetMatrix as well as create a SetMatrix function.

I would also recommend some changes regarding images. Since images rarely change size, the overhead of STL vectors is not really justified. However, moving images around would be much easier if smart pointers were used to handle the allocation/deallocation of memory. In addition, if an image container also contained pointers to the start of every line, and appropriate operator[] functions were provided, then pixels could be accessed using doubly indexed notation such as: myImage[row][column].

Thanks for your consideration.

2
Graphics / SFML2 bugs
« on: March 29, 2010, 05:39:54 pm »
I have been using SFML2 to implement an interactive slide show as part of an image management prototype. I have encountered a few difficulties. I plan back down to SFML 1.5 and defer some of my planned visual effects in hopes of gaining stability and portability across Windows versions. However, as I do so, I would like to document my problems.

My environment:
OS: XP SP2
IDE: Visual Studio 2005 SP2
The main application GUI is C#. My image analysis and management library is in unmanaged C++. The managed<->unmanaged transition is made via a thin wrapper that creates a DLL used by the C# GUI. SFML is used within the unmanaged C++ domain, contained by the wrapper. To avoid naming collisions (my project is pretty big and has a lot of stuff in it), I link with the DLL versions of SFML. Because the slide show is just a feature, it may not be called and SFML functions may not be executed every time the program runs.

The Issues:
(1) I found that I had to put the following line in my main constructor within the C++, otherwise the SFML destructors would crash on exit if I did not call any other SFML functions.

Code: [Select]

  // HACK - This following line is to avoid a crash when the SFML dll exits
  sf::Context context;


(2) When using a RenderImage, sometimes the images are drawn vertically inverted. This is particularly odd because I cannot seem to anticipate whether it will be flipped. However, the behavior is repeatable to the extent that I can set the "FlipY" parameter to compensate once I have seen it flip in a given usage.

(3) In some cases, the first time I use a RenderImage, it is drawn onto my RenderWindow as all black. I am using the RenderImage to accomplish a clipping path on a rotated sprite. I clear() the RenderImage with a transparent color, draw the rotated sprite into the RenderImage, Display() the RenderImage, create a Sprite using the RenderImage, draw the RenderImage Sprite into the RenderWindow. After the first such use, it appears to behave normally.

(4) RenderImages appear to behave differently on different versions of Windows (or at least on different machines I have at my disposal). When it fails, most commonly it displays as black, however I have seen it display as the Sprite color.

(5) I played around with sounds and music and encountered a crash when I tried to LoadFromFile. However, I have not spent any time determining the details of this failure.

I suspect that many of these problems originate from my use of SFML within a DLL, combined with the fact that SFML is not always called upon.

I like SFML and find it pretty easy to use. I hope that these comments are not taken as overt criticism of the library, rather I am just trying to document behaviors that appear to be bugs.

Thanks

3
SFML projects / SFML-based slide show
« on: March 15, 2010, 07:32:42 pm »
I am working on a "slide show" project. The goal is to display multiple images simultaneously in different parts of the screen and to provide some sophisticated transitions as images enter and leave. It appears that SFML may have most of the features I need. I have hit several rough patches of road along the way and have been able to work through them with help from the SFML community (Many thanks!).

My current confusion centers around loading images via a background thread. I have written an image loader that employs a background worker thread in order to avoid pauses in the animation of the slide show. I have included the loader and some simple test code below. I encounter several problems with this code:
1) I still experience pauses in the execution
2) Some of the images are only rendered as white rectangles.
3) I am apparently leaking large amounts of memory (even though I delete the images).

Any insight to my problems would be greatly appreciated.

Note: I am using SFML 2.0 build 1444 because I need to use RenderImage until clipping paths are available.

Another Note: Upon re-examination, my "real" slide show routine does not appear to leak as much memory. the only real differences appear to be that the sprite that uses the image goes out of context and is destructed, and the RenderImage pointer that uses the sprite which uses the image is deleted immediately after the image is deleted. (Clear as mud?)

This is my test routine. The image file spinner.png is just a small image that I rotate to visualize hiccups in execution. The other images are from digital still cameras.
Code: [Select]

//-----------------------------------------------------------------------------
void LoaderTest()
{
  // Create a clock for measuring the time elapsed
  sf::Clock clock;

  // Create main window
  sf::RenderWindow canvas(sf::VideoMode(800, 600), "loaderTest");

  sf::Image spin_image;
  spin_image.LoadFromFile("C:/images/spinner.png");
  sf::Sprite spin_sprite(spin_image);
  spin_sprite.SetOrigin(spin_image.GetWidth()/2.0F, spin_image.GetHeight()/2.0F);
  spin_sprite.SetPosition(canvas.GetWidth()/2.0F, canvas.GetHeight()/2.0F);

  vector<string> fnames;
  fnames.push_back("C:/images/smallA.jpg");
  fnames.push_back("C:/images/largeA.jpg");
  fnames.push_back("C:/images/smallB.jpg");
  fnames.push_back("C:/images/largeB.jpg");

  SlideShowImageLoader loader;
  int idx = 0;
  sf::Image *pImage = 0;
  sf::Sprite image_sprite;
  std::string filename;

  // Start game loop
  float switchDelay = 2.0F;
  float switchTime = clock.GetElapsedTime();
  float currentTime = clock.GetElapsedTime();
  while (canvas.IsOpened())
  {
    // Process events
    sf::Event Event;
    while (canvas.GetEvent(Event))
    {
      // Close window : exit
      if (Event.Type == sf::Event::Closed)
        canvas.Close();

      // Escape key : exit
      else if (Event.Type == sf::Event::KeyPressed)
      {
        if (Event.Key.Code == sf::Key::Escape)
          canvas.Close();
      }
    }

    // queue up images
    while (loader.imagesTotal() < fnames.size())
      loader.RequestImageFile(fnames[idx++ % (int)fnames.size()]);

    // switch images periodically
    currentTime = clock.GetElapsedTime();
    if (currentTime >= switchTime)
    {
      if (pImage)
      {
        delete pImage;
        pImage = 0;
      }
      if (loader.DequeImage(filename, pImage))
      {
        image_sprite.SetImage(*pImage, true);
        image_sprite.SetOrigin(pImage->GetWidth()/2.0F, pImage->GetHeight()/2.0F);
        image_sprite.SetPosition(canvas.GetWidth()/2.0F, canvas.GetHeight()/2.0F);
        float scale = std::min((float)canvas.GetWidth()/pImage->GetWidth(), (float)canvas.GetHeight()/pImage->GetHeight());
        image_sprite.SetScale(scale, scale);
        switchTime = currentTime + switchDelay;
      }
    }

    // Display
    canvas.Clear();
    canvas.Draw(image_sprite);
    spin_sprite.SetRotation(currentTime * 180);
    canvas.Draw(spin_sprite);

    // Finally, display the rendered frame on screen
    canvas.Display();
  }
}


The SlideShowImageLoader.h looks like this:

Code: [Select]

#pragma once

#include <SFML/Graphics.hpp>
#include <deque>


typedef std::pair<std::string, sf::Image *> NamedImagePtr;

//-----------------------------------------------------------------------------
class SlideShowImageLoader
{
public:
  SlideShowImageLoader();
  virtual ~SlideShowImageLoader();

  static void LoaderLoop(void *pData);

  void RequestImageFile(std::string &filename);
  bool DequeImage(std::string &filename, sf::Image *&pImage);

  inline unsigned imagesAvailable() const { return (unsigned)responses.size(); }
  inline unsigned imagesPending() const { return (unsigned)requests.size(); }
  inline unsigned imagesTotal() const { return (unsigned)responses.size() + (unsigned)requests.size(); }


protected:
  bool                                exitSignal;
  sf::Thread                          loaderThread;
  sf::Mutex                           responseMutex;
  sf::Mutex                           requestMutex;
  std::deque<NamedImagePtr>           responses;
  std::deque<std::string>             requests;
};


SlideShowImageLoader.cpp
Code: [Select]

#include "SlideShowImageLoader.h"

//-----------------------------------------------------------------------------
SlideShowImageLoader::SlideShowImageLoader() : exitSignal(false), loaderThread(LoaderLoop, this)
{
  loaderThread.Launch();
}

//-----------------------------------------------------------------------------
SlideShowImageLoader::~SlideShowImageLoader()
{
  exitSignal = true;
  loaderThread.Wait();
  while (responses.size())
  {
    delete responses.front().second;
    responses.pop_front();
  }
}

//-----------------------------------------------------------------------------
void SlideShowImageLoader::LoaderLoop(void *pData)
{
  sf::Context context; // this line is needed for images to be loaded properly
  SlideShowImageLoader &loader = *(SlideShowImageLoader *)pData;
  while(!loader.exitSignal)
  {
    if (loader.requests.size())
    {
      loader.requestMutex.Lock();
      std::string filename = loader.requests.front();
      loader.requests.pop_front();
      loader.requestMutex.Unlock();

      sf::Image *pImage = new sf::Image();
      if (pImage->LoadFromFile(filename))
      {
        loader.responseMutex.Lock();
        loader.responses.push_back(NamedImagePtr(filename, pImage));
        loader.responseMutex.Unlock();
      }
    }
    sf::Sleep(0.01f);
  }
}

//-----------------------------------------------------------------------------
void SlideShowImageLoader::RequestImageFile(std::string &filename)
{
  requestMutex.Lock();
  requests.push_back(filename);
  requestMutex.Unlock();
}

//-----------------------------------------------------------------------------
bool SlideShowImageLoader::DequeImage(std::string &filename, sf::Image *&pImage)
{
  bool rval = false;
  if (responses.size())
  {
    responseMutex.Lock();
    filename = responses.front().first;
    pImage = responses.front().second;
    responses.pop_front();
    responseMutex.Unlock();
    rval = true;
  }
  return rval;
}
:lol:

4
Graphics / Clipping paths or masks
« on: March 04, 2010, 11:44:37 pm »
I am very new to SFML and greatly appreciate the help I have received so far. My latest question concerns clipping paths or masks. I would like to create pan, zoom, rotate, and alpha blend effects within a defined region of the window. Referring to the picture below, consider that I have a full screen in which the background is a sprite  I would like to define regions of the screen in which I can use pan and zoom effects. For instance, I would like to be able to zoom into one of the faces in one of the foreground images while clipping the image to the white rectangle surrounding the foreground image, and leaving the background image completely intact.

Currently, I am only interested in rectangular clipping windows, however I could definitely imagine using arbitrary clipping paths if available.

Thanks for any advice you can share.
---Pete


5
Window / RenderWindow crash on dual monitor (laptop w/ external)
« on: March 03, 2010, 06:52:46 pm »
I use my laptop with an external monitor in my office. I use both screens (dual monitor setup) with the external monitor as the primary display. The following code crashes, sometimes taking the whole machine with it. I do not experience problems using a single monitor or using two monitors with the laptop screen set as the primary display.

Any help would be appreciated.
Thanks

Code: [Select]
 sf::RenderWindow canvas(sf::VideoMode(), "Dual Crasher", sf::Style::Fullscreen);
  sf::Color canvasColor(192,192,192);
  canvas.Clear();
  canvas.Display();
  // Start game loop
  while (canvas.IsOpened())
  {
    // Process events
    sf::Event Event;
    while (canvas.GetEvent(Event))
    {
      // Close window : exit
      if (Event.Type == sf::Event::Closed)
        canvas.Close();

      // Escape key : exit
      else if (Event.Type == sf::Event::KeyPressed)
      {
        if (Event.Key.Code == sf::Key::Escape)
          canvas.Close();
      }
    }

    // Draw background
    canvas.Clear(canvasColor);

    // Finally, display the rendered frame on screen
    canvas.Display();
  }

6
General / Exception thrown within sfml-window.dll when exiting
« on: March 01, 2010, 10:17:55 pm »
I intend to use SFML within a .dll accessed by a C# GUI. For testing, I copied the main body of OpenGL.cpp sample into a function within my .dll project. Everything worked fine, however while exiting the program I experience an exception.  I am using Visual Studio 2005 on an XP machine.

The call stack looks like this:
    nvoglnt.dll!697216d0()    
    [Frames below may be incorrect and/or missing, no symbols loaded for nvoglnt.dll]   
    nvoglnt.dll!69721a5b()    
    nvoglnt.dll!6973ce0a()    
    nvoglnt.dll!69594d4e()    
    nvoglnt.dll!69585c0d()    
    nvoglnt.dll!6971f4a8()    
    opengl32.dll!5ed19652()    
    opengl32.dll!5ed19aad()    
    opengl32.dll!5ed19c5f()    
>   sfml-window-d.dll!sf::priv::WindowImplWin32::SetActive(bool Active=true)  Line 298 + 0x1c bytes   C++
    sfml-window-d.dll!sf::Context::SetActive(bool Active=true)  Line 64 + 0x17 bytes   C++
    sfml-graphics-d.dll!sf::priv::GraphicsContext::GraphicsContext()  Line 69   C++
    sfml-graphics-d.dll!sf::Image::DestroyTexture()  Line 776 + 0x8 bytes   C++
    sfml-graphics-d.dll!sf::Image::~Image()  Line 117   C++
    sfml-graphics-d.dll!sf::Font::~Font()  + 0x63 bytes   C++
    sfml-graphics-d.dll!`sf::Font::GetDefaultFont'::`2'::`dynamic atexit destructor for 'DefaultFont''()  + 0x28 bytes   C++
    sfml-graphics-d.dll!_CRT_INIT(void * hDllHandle=0x04230000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 420   C
    sfml-graphics-d.dll!__DllMainCRTStartup(void * hDllHandle=0x04230000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 512 + 0x11 bytes   C
    sfml-graphics-d.dll!_DllMainCRTStartup(void * hDllHandle=0x04230000, unsigned long dwReason=0, void * lpreserved=0x00000001)  Line 462 + 0x11 bytes   C

When I comment out the four lines near the bottom dealing with rendering the string "This is a rotating cube", I do not experience the exception.

Any suggestions?

Pages: [1]