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

Pages: [1]
1
Graphics / Slow rendering?
« on: August 05, 2013, 05:55:53 pm »
Hi!

My objective is to have many (5 or so) textures plotted on the same place which have a dynamic (software set) alpha.
So here is a small test I did.
I am drawing a texture two times on the screen and I am getting 60FPS only (both have the alpha set entirely to 1, a better example would be one with alphas summing 1). From my experience this seems very slow.
My machine is running linux and SFML 2.0. I can add more details about it upon request.

My question is: Don't you think it is slow? Do you think multi-texturing with GLSL would be a faster solution?
Threads? This is another question I have (because it made my simple code unstable), but I think it would be better to post on the System tab. If anyone want to take a look at my code with threads it is posted here:
http://en.sfml-dev.org/forums/index.php?topic=12521.0

2
System / Threads not working with simple window
« on: August 05, 2013, 05:47:29 pm »
Hi,

Going directly to the point, I wanted to try a rendering thread to decrease my the FPS count.
It ended up giving me strange results and unstable behavior. Sometimes I get:
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 104 requests (104 known processed) with 0 events remaining.

Sometimes, it almost work but I cannot change the window. If I do, I can not get back again.

By the error you should already know I am running Linux. I am using the 2.0 SFML version from the Gentoo ebuild.

My makefile is:
         g++ -o o main.cpp  -lsfml-graphics -lsfml-window -lsfml-system -std=c++0x -pthread
 

Below is my simple code:

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

#include<iostream>
#include <thread>

using namespace std;

#define DIR_MEDIA_TEXTURES "media/textures/"

sf::Sprite sprite;

//return if the number of frames should be reset
bool frameTiming(float number_of_frames, float accum_elapsed_seconds)
{
        if(accum_elapsed_seconds > 5.0)
        {
                cout << "FPS: " << number_of_frames/accum_elapsed_seconds << endl;
                return true;
        }
        return false;
}


void renderingThread(sf::Window* window)
{

        // activate the window's context
        window->setActive(true);

        sf::RenderWindow* render_window= (sf::RenderWindow*) window;

        // the rendering loop
        while (window->isOpen())
        {
                // draw...
                render_window->clear();
                //window.draw(shape);
                render_window->draw(sprite);
                //render_window->draw(sprite);

                // end the current frame -- this is a rendering function (it requires the context to be active)
                window->display();
        }
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 800), "Triturus Project", sf::Style::Default);
        //sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Triturus Project", sf::Style::Fullscreen);
        window.setVerticalSyncEnabled(true);

        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
        sf::Texture texture;
        if (!texture.loadFromFile(DIR_MEDIA_TEXTURES"grass94.tga"))
        //if (!texture.loadFromFile("test.png"))
        //if (!texture.loadFromFile(DIR_MEDIA_TEXTURES"plant142.tga"))
        //if (!texture.loadFromFile(DIR_MEDIA_TEXTURES"stone240.tga"))
        {
                    // error...
                    cout << "Error: Failed loading texture" << endl;
        }

        texture.setRepeated(true);
        //texture.setSmooth(true);


        sprite.setTexture(texture);
        sprite.setScale(1,1);
        sf::IntRect rect(0,0,1000,1000);
        sprite.setTextureRect(rect);
        // deactivate its OpenGL context
        window.setActive(false);

        // launch the rendering thread
        sf::Thread thread(&renderingThread, &window);
        //std::thread render_thread( renderingThread, &window);
        //render_thread.join();
        thread.launch();



        sf::Clock clock;
        sf::Time accum_time;
        float number_of_frames;

        while (window.isOpen())
        {
                //------------- Event Handling -------------
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }


                //------------- Time -------------

                //get the time elapsed
                sf::Time elapsed = clock.restart();
                //updateGame(elapsed);
                //cout << elapsed.asSeconds() << endl;

                //frame counter
                accum_time+= elapsed;
                number_of_frames++;
                bool reset_frame_counter= frameTiming(number_of_frames, accum_time.asSeconds());
                if(reset_frame_counter==true)
                {
                        number_of_frames=0.0f;
                        accum_time= sf::seconds(0.0f);
                }

        }

        return 0;
}
 

Pages: [1]