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 - Carlo Meroni

Pages: [1]
1
Audio / Static sf::Sound cause the application to crash on MAC
« on: September 26, 2014, 08:34:21 pm »
Hi,

While I was creating a game on Mac OS X I noticed that if I declare a static sf :: Sound variable and I set a SoundBuffer to it, then when I close the application it crash with bad errors.
The problem is in the sf::Sound destructor.
On windows everything works fine (with visual studio compiler).

Here is minimal code example:
//=======================
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
#include <map>

//=======================
#include "ResourcePath.hpp"

//======================
using namespace sf;

//static sound declaration
static sf::Sound snd;

int main()
{
    sf::Window win;
        win.create(VideoMode(1100, 700), "TEST", Style::Titlebar | Style::Close);
        win.setVerticalSyncEnabled(true);

    sf::SoundBuffer sndb;
    sndb.loadFromFile(resourcePath() + "Greenkey.wav");
    snd.setBuffer(sndb);
    snd.play();

        while (win.isOpen())
        {
                Event ev;
                while (win.pollEvent(ev)) {
                        switch (ev.type) {
                        case Event::Closed:
                                win.close();
                                break;
                        }
                }

                win.display();
        }

        return EXIT_SUCCESS;
}
 

Here is what XCode says:
https://www.dropbox.com/s/qgy36in0bjkytbp/Prove.png?dl=0

2
Graphics / Re: OpenGL application lag
« on: January 10, 2014, 08:54:25 pm »
Hey guys! I have resolved the issue. SFMl was managing the frames 2 times because i was calling window.setVerticalSyncEnabled(true) at the beginning of the programme and in the event 'lost focus' i was calling window.setFrameratelimit(30).

I have a question.. Whith VSYNC the framerate is set to 60? I can change it?

3
Graphics / Re: OpenGL application lag
« on: January 09, 2014, 08:26:44 pm »
I have a costant 60 FPS. The elapsed time for each frame look like that (in microsecond) :

17680
17675
17282
17679
16684
16999
17678
17390
.....

I checked and there are no rounding issues.
For the drivers settings... OS X Mavericks does not allow users to touch the graphics card driver.
I tried to use glflush () and glfinish () after every draw but there is no difference.

Maybe i'm drawing in a wrong way?


4
Graphics / Re: OpenGL application lag
« on: January 09, 2014, 07:16:00 pm »
I made a video:
Watch carefully at the logo that rotates and the view when is moving.


5
Graphics / Re: OpenGL application lag
« on: January 09, 2014, 06:03:37 pm »
It happens something like that, all the objects that are moving, (like rotating or simply when moving the view using glulookat() ) they move like the speed is irregular, like there is a delay or something like that.
In the video the movement of the view is not smooth.



6
Graphics / Re: OpenGL application lag
« on: January 09, 2014, 05:44:24 pm »
This video shows my issue:


It's not mine but happen exactly the same thing, whit VSYNC and on 3 different MAC computers as I wrote above.

In the code I posted you can not see the Spritebatch class and the Sprite class...
I simply put every Sprite in a Sprite array and i draw everything with spritebatch.end() with Vertex array.

Sorry if I made any mistakes in writing, I'm Italian.

7
Graphics / Re: OpenGL application lag
« on: January 06, 2014, 08:46:49 pm »


Here a minimal code with a rotating quad that is a little bit laggy:

    sf::RenderWindow window(sf::VideoMode(800, 600), "Virtual Shock Testing",sf::Style::Default,settings);
   
    glEnable( GL_BLEND );
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   
    window.setVerticalSyncEnabled(true);
    window.setFramerateLimit(60);
   
    //--- OPENGL INITIALIZE ---
    //Perspective
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho (0, 800, 600,0, 0, 1);
    glViewport(0,0,800,600);
    glMatrixMode (GL_MODELVIEW);
   
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
   
    sf::Time time;
    sf::Clock clock;
   
    SpriteBatch spritebatch;
    Sprite test;
   
    test.SetColor(Color(1,0,0,1));
    test.SetTexture(0);
    test.SetTextureSource(Rectf(0,0,1,1));
    float rotation = 0;
   
    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed) {
                window.close();
            }

            // Escape pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
                window.close();
            }
        }
       
        rotation+=0.0001*time.asMicroseconds()/1000.00;
       
        test.SetPosition(Rect(200,200,400,400),Vector2i(400,400),rotation);
       
        window.clear();
       
        spritebatch.Begin();
        spritebatch.Draw(test);
        spritebatch.End();
       
        window.display();
       
        time = clock.restart();
    }
 

I'm not using network.

8
Graphics / OpenGL application lag
« on: January 06, 2014, 07:55:18 pm »
Hi,

I have a problem with my OpenGL application because i get some lag.
I set the VSync to true and the lag is reduced a lot but it is still present.
I set the limit of the frames to 60 and i get 16-17 millisecond elapsed time every frame.
The CPU usage is low  (5-10%) and the RAM usage is about 20 Mb.
I tested the application on 3 different computers (All macintosh) and the problem persist.

Specs of computers:

Mackbook pro 13"
OS : Maverick
Graphic Card : GeeForce 320M

Mackbook air 11"
OS : Maverick
Graphic Card : Intel HD 5000

Hackintosh
OS : MAverick
Graphic Card : AMD Radeon HD 6500;


9
General / Re: Sort Sprite List by Scale
« on: October 07, 2013, 07:37:52 pm »
I can not do it with those examples ... I'm not very good with C + +.
Can someone please show me an example with a list of sprites?

10
General / Sort Sprite List by Scale
« on: October 07, 2013, 06:09:28 pm »
Hi! I have a list of Sprite and i want to sort it by the scale of the sprite (sprite.getScale ()). How can I do it ?

11
Graphics / Re: CPU Performance, 2D Tile Based game
« on: October 06, 2013, 02:32:32 pm »
Now it works fine. My code was wrong. :)

12
Graphics / Re: CPU Performance, 2D Tile Based game
« on: October 05, 2013, 04:44:44 pm »
this is the code:
//SpriteBatch.h
#include<SFML\Graphics.hpp>

class SpriteBatch
{
public:
        SpriteBatch(void);
        ~SpriteBatch(void);

        void Begin(int Maxvertex);
        void Draw(sf::RenderWindow &window,sf::Texture &Texture,sf::Rect<int> &transform,sf::Rect<int> &Source,sf::Color &colora,sf::Color &colorb,sf::Color &colorc,sf::Color &colord,int deep);
        virtual void End(sf::RenderWindow &window,sf::Texture &Texture);

        sf::VertexArray vertexs;
        sf::Texture texture;
        int maxvertex;
        int cvertex;
};

//SpriteBatch.cpp
void SpriteBatch::Begin(int Max)
{
        //Vertex Array
        cvertex=0;
        maxvertex=Max;
        vertexs.setPrimitiveType(sf::Quads);
        vertexs.resize(maxvertex);
}

void SpriteBatch::Draw(sf::RenderWindow &window,sf::Texture &tx, sf::Rect<int> &transform,sf::Rect<int> &Source,sf::Color &colora,sf::Color &colorb,sf::Color &colorc,sf::Color &colord,int deep)
{

        //Position - Dimension
        vertexs[cvertex].position = sf::Vector2f(transform.left, transform.top);
        vertexs[cvertex+1].position = sf::Vector2f(transform.left+transform.width, transform.top);
        vertexs[cvertex+2].position = sf::Vector2f(transform.left+transform.width, transform.top+transform.height);
        vertexs[cvertex+3].position = sf::Vector2f(transform.left,transform.top+transform.height);

        //Texture
        vertexs[cvertex].texCoords = sf::Vector2f(Source.left,Source.top);
        vertexs[cvertex+1].texCoords = sf::Vector2f(Source.left+Source.width, Source.top);
        vertexs[cvertex+2].texCoords = sf::Vector2f(Source.left+Source.width,Source.top+Source.height);
        vertexs[cvertex+3].texCoords = sf::Vector2f(Source.left, Source.top+Source.height);

        //Color
        vertexs[cvertex].color = colora;
        vertexs[cvertex+1].color = colorb;
        vertexs[cvertex+2].color = colorc;
        vertexs[cvertex+3].color = colord;

        cvertex+=4;
        if (cvertex==maxvertex)
        {
                End(window,tx);
                cvertex=0;
        }

}

void SpriteBatch::End(sf::RenderWindow &window,sf::Texture &tx)
{
        window.draw(vertexs,&tx);
}
 
I set Maxvertex = 1024

13
Graphics / CPU Performance, 2D Tile Based game
« on: October 05, 2013, 01:44:24 pm »
Hi! I've recently started using SFML and I really like it a lot. I am translating my game from XNA to SFML and I noticed that the performance of SFML are lower in image rendering. I created a simple class for spritebatching (with vertex array) and I compared the performance with XNA.
10000 drawing sprites with the same texture:
- XNA: 60 FPS, about 4% CPU usage
- SFML: 60 FPS, about 11% CPU usage

is a problem of my code? can be fixed?
sorry for my bad english!

Pages: [1]
anything