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 - Avency

Pages: [1]
1
Audio / Buffers not deleted
« on: September 04, 2008, 11:55:11 pm »
If my application exits, I get the following error message (replace 1 with the number of sounds loaded at runtime):

Code: [Select]
AL lib: alBuffer.c:1097: exit() 1 Buffer(s) NOT deleted

I keep a sf::Sound and a sf::SoundBuffer inside a class to make it easier to keep track of the resources (for my resource-manager and script bindings).

The destructor is called as expected, so I'm not sure what causes it.

Code: [Select]
class SoundBuffer
{
public:
SoundBuffer()
{
std::cerr << "sound created" << std::endl;
}

virtual ~SoundBuffer()
{
std::cerr << "sound destroyed" << std::endl;
}

bool Init(File& Data)
{
bool Success = Buffer.LoadFromMemory(Data.GetContent(), Data.Size());

Sound.SetBuffer(Buffer);

return Success;
}

sf::Sound Sound;

private:
sf::SoundBuffer Buffer;
};


Can anyone help?

2
General / [Sovled] Intergrating SFML into gtkmm
« on: March 23, 2008, 06:57:00 pm »
Has anyone ever successfully integrated SFML into gtkmm?
I am currently trying, but I cannot find any method that gets called when repainting the widget.

See:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html

I managed SFML to display a Sprite in the widget but only if an event occurs.
I also recreate the sf::RenderWindow each time the window is resized. There has to be a better solution.
I am definetly not an expert when it comes to creating custom gtkmm widgets.
So if there is anyone who has done that before, then help/suggestions would be appreciated.

Here is what I've got so far (this will probably not work under windows):

File: SFMLWidget.h
Code: [Select]

#ifndef SFMLWIDGET_H_
#define SFMLWIDGET_H_

#include <SFML/Graphics.hpp>
#include <gtkmm.h>
#include <gdk/gdkx.h>


class SFMLWidget : public Gtk::Widget, public sf::RenderWindow
{
public:
SFMLWidget();
virtual ~SFMLWidget();

protected:

  virtual void on_size_request(Gtk::Requisition* requisition);
  virtual void on_size_allocate(Gtk::Allocation& allocation);
  virtual void on_map();
  virtual void on_unmap();
  virtual void on_realize();
  virtual void on_unrealize();
  virtual bool on_event(GdkEvent* event);

  Glib::RefPtr<Gdk::Window> ourGdkWindow;
  sf::Image Image;
  sf::Sprite Sprite;

};

#endif /*SFMLWIDGET_H_*/


SFMLWidget.cpp
Code: [Select]

#include "SFMLWidget.h"

SFMLWidget::SFMLWidget() :
  Glib::ObjectBase("SFMLWidget"),
  Gtk::Widget()
{
  set_flags(Gtk::NO_WINDOW);
 
  Image.LoadFromFile("image.png");
  Sprite.SetImage(Image);
}

SFMLWidget::~SFMLWidget()
{
}

void SFMLWidget::on_size_request(Gtk::Requisition* requisition)
{
  *requisition = Gtk::Requisition();
 
  requisition->height = 50;
  requisition->width = 50;
}

void SFMLWidget::on_size_allocate(Gtk::Allocation& allocation)
{
set_allocation(allocation);

if (ourGdkWindow)
{
ourGdkWindow->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height() );
GdkWindow* Win = ourGdkWindow->gobj();
XFlush(GDK_WINDOW_XDISPLAY(Win));
sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
SetBackgroundColor(sf::Color::Red);
}
}

void SFMLWidget::on_map()
{
  Gtk::Widget::on_map();
}

void SFMLWidget::on_unmap()
{
  Gtk::Widget::on_unmap();
}

void SFMLWidget::on_realize()
{
  Gtk::Widget::on_realize();

  if(!ourGdkWindow)
  {
    GdkWindowAttr Attributes;
    memset(&Attributes, 0, sizeof(Attributes));

    Gtk::Allocation Allocation = get_allocation();

    Attributes.x = Allocation.get_x();
    Attributes.y = Allocation.get_y();
    Attributes.width = Allocation.get_width();
    Attributes.height = Allocation.get_height();

    Attributes.event_mask = Gdk::ALL_EVENTS_MASK ;
    Attributes.window_type = GDK_WINDOW_CHILD;
    Attributes.wclass = GDK_INPUT_OUTPUT;

    ourGdkWindow = Gdk::Window::create(get_window(), &Attributes, GDK_WA_X | GDK_WA_Y);
    unset_flags(Gtk::NO_WINDOW);
   
    Gtk::WidgetFlags Flags = Gtk::DOUBLE_BUFFERED | Gtk::APP_PAINTABLE;
    set_flags(Flags);
   
    set_window(ourGdkWindow);

    ourGdkWindow->set_user_data(gobj());
   
    GdkWindow* Win =  ourGdkWindow->gobj();
    XFlush(GDK_WINDOW_XDISPLAY(Win));
    sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
    SetBackgroundColor(sf::Color::Red);
  }
}

void SFMLWidget::on_unrealize()
{
ourGdkWindow.clear();
Gtk::Widget::on_unrealize();
}

bool SFMLWidget::on_event(GdkEvent* event)
{
if (event)
{
if (event->type == GDK_BUTTON_PRESS )
{
Sprite.SetPosition(event->button.x, event->button.y);
}
Draw(Sprite);
Display();
return true;
}

return false;
}


Edit:

Problem solved.
Next time I should look through the documentation more carefully.
There exist signals for idle and timeouts.

3
Window / Window creation (Linux)
« on: March 18, 2008, 04:21:50 pm »
Instead of starting centered, windows always appear in the upper left corner when running Metacity.
Compiz has a similar behavior, but you cannot predict in which corner windows are opened.
Is there any way to fix this?

4
Window / Understanding sf::Event::KeyPressed
« on: February 14, 2008, 08:15:14 pm »
In each loop I receive a sf::Event::KeyPressed event , if a key is held down.
Is there a way to receive a single key press?
If I wanted to check if a key is beeing held down, I would use the sf::Input class instead.
sf::Event::KeyReleased events are only received if a key is released, as I would expect it.

Here is a short example of what I mean:

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>

int main()
{

    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Events");
   
    sf::Font Font;
    Font.LoadFromFile("ARIAL.TTF", 40);
   
    sf::String Text("", Font, 32);
   
    std::ostringstream oss;
   
    int NbKeysPressed = 0; //counts, how often a key has been pressed

    // Start game loop
    bool Running = true;
    while (Running)
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            switch(Event.Type)
            {
            case sf::Event::Closed:
            {
            Running = false;
            break;
            }
            case sf::Event::KeyPressed:
            {
            ++NbKeysPressed;
           
            oss.str("");
            oss << NbKeysPressed;
            Text.SetText(oss.str());
           
            break;
            }
            case sf::Event::KeyReleased:
            {
            --NbKeysPressed;
            oss.str("");
            oss << NbKeysPressed;
            Text.SetText(oss.str());

                  break;
            }
            default:
            {
            break;
            }      
            }
        }
       
        App.Draw(Text);

        App.Display();
    }

    return EXIT_SUCCESS;
}


Any ideas?

5
Feature requests / Possibility to load resources from a file buffer
« on: November 12, 2007, 07:00:26 pm »
I'd like to see the possibility of loading resources from a file buffer or filestream
(at least for the built-in ones like images and audio).
I was able to do image loading from a file buffer using DevIL, but since you are going
to replace it in the next version, I'd strongly apply for alternative loading methods as they
shouldn't be hard to implement.

It would be rather useful for use in combination with custom resource files,
filesystems such as PhysicsFS or compression libraries in general.

i.e.
Code: [Select]

bool sf::Image::LoadFromBuffer(void* data, std::size_t size)
bool sf::Image::ReadFromStream(std::fstream& stream, std::size_t size)
bool sf::Image::WriteToStream(std::fstream& stream, std::size_t size)

bool sf::SoundBuffer::LoadFromBuffer(void* data, std::size_t size)
bool sf::SoundBuffer::ReadFromStream(std::fstream& stream, std::size_t size)
bool sf::SoundBuffer::WriteToStream(std::fstream& stream, std::size_t size)

You get the idea...

Pages: [1]