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.

Messages - Avency

Pages: 1 ... 5 6 [7]
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.


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]


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

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


  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_*/

Code: [Select]

#include "SFMLWidget.h"

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)

if (ourGdkWindow)
ourGdkWindow->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height() );
GdkWindow* Win = ourGdkWindow->gobj();

void SFMLWidget::on_map()

void SFMLWidget::on_unmap()

void SFMLWidget::on_realize()

    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);
    Gtk::WidgetFlags Flags = Gtk::DOUBLE_BUFFERED | Gtk::APP_PAINTABLE;

    GdkWindow* Win =  ourGdkWindow->gobj();

void SFMLWidget::on_unrealize()

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

return false;


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

Window / Window creation (Linux)
« on: March 23, 2008, 04:18:20 pm »
I've pulled down the latest fedora snapshot -> the problem still remains.

This is especially annoying in combination with sf::Style::None. Metacity displays the window in the top left corner, Compiz on the other hand handles sf::Style::None correctly (and centers the window).
To all other combinations the problems described earlier apply.
But you certainly want to disable Compiz when running an OpenGL application in windowed mode anyway.

Is there anyone using Linux who experiences the same problems or is it just me?

Graphics / Tileset/Sprite - Design question
« on: March 23, 2008, 03:56:26 pm »
It depends on the type of game you are trying to create.


2. Create each frame a new sprite then use SetPosition, SetSubRect & Draw for each tile and destroy the sprite once the job is done.

I've tried this some time ago. It worked but was a bit slow (where slow can be seen relative). But for a game like SimCity it should be sufficient.

To me, the best solution would be to store one sprite per tile and just draw them each frame.

This can be quite memory consuming for big maps. But it depends on your target hardware.

My current attempt is to store an integer for each tile and then to calculate its texture coordinates in the rendering loop and blit it to the screen using OpenGL directly.
This methods kicks ass (ca. 4 times faster than the method above and can handle really big maps). :D

Another method would be to create a tileset class storing a sprite for each tile and precalculating their subrects.
In the render-loop, you would only have to decide which sprite should be drawn at which position. Or maybe creating a tile class that inherits sf::Sprite.

But as said above, it heavily depends on what you are trying to achieve.

Feature requests / bool sf::Sprite::CheckCollosion(Sprite param)
« on: March 22, 2008, 03:09:19 pm »
Yep, maybe a function to generate collision outlines might be expensive.
But how to check on collisions between sprites otherwise (if not using just rectangles or pixel perfect collision detection)?
I have no idea...
Collision checking between shapes would still be a nice and useful feature, even if seen independent from the sprite issue.
Though I'm not sure how to implement it.


And I think this interface would be too complicated for just simple collision tests.

Sure, the implementation is complicated, but the interface itself?
I'm just curious what you are thinking of. :D
I guess I'll have to wait until you are done.

Feature requests / bool sf::Sprite::CheckCollosion(Sprite param)
« on: March 22, 2008, 11:13:29 am »
What about using shapes to detect collisions?
And maybe providing a function that generates shapes from the non-transparent part of an image.
Like sf::Shape sf::Sprite::GetCollisionOutline(int Quality), where the quality parameter determines how detailed the shapes end up.
And then use bool sf::Shape::Collide(const sf::Shape& Other) and bool sf::Shape::IsPointInside(int X, int Y).
Shapes are quite flexible and can adapt almost any 2d geometry.

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?

Graphics / Problem changing fonts
« on: March 05, 2008, 06:19:59 pm »
If you are using VisualStudio, make sure it is in your working directory.
What happens if you try to load an image from that directory?

I figured out, that the lettering could be a problem.
If your file is named "Arial.ttf" and you try to load it as "arial.ttf", it will fail (at least under linux).

Feature requests / some suggestions
« on: March 04, 2008, 06:41:56 pm »
Quote from: "Lord Delvin"

An optional manager would be nice, as some of as (or at least my project) might have their own ressource management which might want to do things different.

I agree, since the implementation of a resource manager can heavily depend on what you are trying to achive.
Still, having an optional default manager could be helpful in certain situations.
But a file archives manager would be more useful and should be taken care of first (I know, it is already on the roadmap).

Quote from: "tgm"

And a last thingy: Drawables should get parents (other drawables). So every thing would be in the parents coordinate systems (Multipling the Parents matrix with the Childs Matrix at render Time) Extremly cool would be to be able to controll which porpertys depends on the parent.
(Like: My position is always relativ to my Parents one but neither my rotation nor my scale, or my sclae depends on my parent, but not my rotation and Position etc.)

I like this idea. It could help to group drawables.

Edit:: Never leave the pc when writing a post  :wink:

Graphics / Re: Problem changing fonts
« on: March 03, 2008, 05:43:14 pm »
Do I have to put the .tff in  the directory of my project?

Yes, otherwise the built-in font will be used.
Also, there is no need for Text.SetFont() after
sf::String Text("text", "arial.tff", 36.f);
as it already sets the "arial.ttf" as active font.
(I could be wrong since I always sync with the svn repository).

Graphics / how do I use sf::Image::LoadFromMemory correctly?
« on: February 28, 2008, 06:52:53 pm »

Code: [Select]

    char* memory;
    std::ifstream myfile("image.png", std::ios::binary | std::ios::ate);
    std::ifstream::pos_type size;
    size = myfile.tellg();
    memory = new char[size];
    myfile.seekg(0, std::ios::beg);
    myfile.read(memory, size);
    sf::Image Image;

    delete[] memory;

It should work unless your image is corrupted. But why won't you use sf::Image::LoadFromFile?

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))
            case sf::Event::Closed:
            Running = false;
            case sf::Event::KeyPressed:
            oss << NbKeysPressed;
            case sf::Event::KeyReleased:
            oss << NbKeysPressed;



    return EXIT_SUCCESS;

Any ideas?

Graphics / sfml-graphics.lib
« on: December 03, 2007, 06:02:33 pm »
Recompile the sfml-binaries on your own, it should work fine then.

Feature requests / Possibility to load resources from a file buffer
« on: November 26, 2007, 04:05:58 pm »
I see it has been added to svn.
Thanks a lot :D. I really appreciate your work.
I am now going to replace my own code (even if it was almost the same), as I prefer to leave third-party libraries the way they are.

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.

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 ... 5 6 [7]