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

Pages: [1]
1
Graphics / Impossible to create render texture (failed to link...
« on: August 10, 2014, 10:00:24 pm »
Impossible to create render texture (failed to link the target texture to the framebuffer)

with debug libaries I also get this:

An internal OpenGL call failed in RenderTextureImplFBO.cpp (117)
 : GL_INVALID_OPERATION, the specified operation is not allowed in the current state


Some code which triggers it for me:
#include <SFML/Graphics.hpp>
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
    std::vector<unsigned int> w;
    std::vector<unsigned int> h;
    for(unsigned int i = 100; i < sf::Texture::getMaximumSize(); i +=500)
    {
        w.push_back(i);
    }
    h.reserve(w.size());
    std::copy(w.begin(),w.end(),h.begin());
    for(unsigned int i =0; i < w.size(); i++)
    {
        std::cout << "i: " << i << std::endl;
        std::cout << "wi: " << w[i] << std::endl;
        std::cout << "hi: " << h[i] << std::endl;
        sf::RenderTexture rt;

        if(!rt.create(w[i],h[i]))
            continue;
        rt.display();
    }
    return 0;
}
Outputs:
i: 0
wi: 100
hi: 100
An internal OpenGL call failed in RenderTextureImplFBO.cpp (117) : GL_INVALID_OPERATION, the specified operation is not allowed in the current state
Impossible to create render texture (failed to link the target texture to the frame buffer)
i: 1
wi: 600
hi: 600
i: 2
wi: 1100
hi: 1100
i: 3
wi: 1600
hi: 1600
i: 4
wi: 2100
hi: 2100
i: 5
wi: 2600
hi: 2600
i: 6
wi: 3100
hi: 3100
i: 7
wi: 3600
hi: 3600

I'm on arch linux with fully up to date sfml. This happens on the open source radeon driver and the intel driver on my laptop.Subsequent textures afer the first get created normally. I can write to them and copy them etc but the first one fails regardless of settings.

Can anyone else reproduce this? Am I doing it wrong? Is it a bug? Do you want more info?


Thanks.

2
General discussions / Custom SFML Wizard for QtCreator
« on: July 31, 2014, 04:29:21 pm »
Something I find useful is adding a SFML custom wizard to qtcreator, it takes the drudgery out of setting up  a new project so I thought I may as well share it.

First you need to locate your qtcreator config folder, which on linux (for me) is at $HOME/.config/QtProject/qtcreator/templates

It will vary depending on distro/OS so check this out:
http://qt-project.org/doc/qtcreator-3.1/creator-project-wizards.html
You may have to create the templates folder, and inside that the wizards folder and then inside that a folder called SFML. So the path now becomes: $HOME/.config/QtProject/qtcreator/templates/wizards/SFML

I'm using CMake so you will need to create a generic CMakeLists.txt inside your newly created SFML folder. Mine looks like this but you should adjust it to your system:

project(%ProjectName%)
cmake_minimum_required(VERSION 2.8)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -O0")
set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules/"  "/usr/share/SFML/cmake/Modules/")


set(SOURCE
   ${SOURCE}
   ${CMAKE_CURRENT_SOURCE_DIR}/main.%CppSourceSuffix%


)
set(HEADERS
   ${HEADERS}


)

find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
  include_directories(${SFML_INCLUDE_DIR})
endif()


add_executable(${PROJECT_NAME} ${SOURCE})
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})

The %ProjectName% variable will be replaced with the name of the project you give in the new project wizard. The variable %CppSourceSuffix% will be replaced with whatever you have qtcreator set to use as C++ file name suffixes. So if you use something other than cpp you will want to change the filename of main.cpp you will create next and adjust the "file source" attribute in the XML file you will create later, or you can get rid of the %CppSourceSuffix% and just hard code the name.

Now you will need a main.cpp file (adjust it to your needs):

#include <SFML/Graphics.hpp>


int main()
{
    const int SWIDTH = 1024;
    const int SHEIGHT = 768;
    sf::RenderWindow win(sf::VideoMode(SWIDTH,SHEIGHT),"%ProjectName:c%",sf::Style::Close);
    while(win.isOpen())
    {
        sf::Event e;
        while (win.pollEvent(e))
        {
            if(e.type == sf::Event::Closed)
            {

                win.close();
            }            
        }
        win.clear();
        //drawing
        win.display();
    }
    return 0;
}

 

Again it has the %ProjectName:c% variable with a ':c', which means it will use your project name with the first letter capitalised as your window title.

Now create a file called wizard.xml
<wizard version="1" kind="project" firstpage="10" id="S.Plain C++ (SFML/CMake)" category="I.Projects"
       platformIndependent="true" featuresRequired="CMake.CMakeSupport">
    <icon>sfml.png</icon>
    <description>Creates a SFML C++ project using CMake.</description>
    <displayname>Plain SFML C++ Project (CMake Build)</displayname>;
    <displaycategory>Non-Qt Project</displaycategory>
    <files>
        <file source="main.cpp" target="main.%CppSourceSuffix%" openeditor="true"/>
        <file source="CMakeLists.txt" openproject="true"/>
    </files>
</wizard>

This xml file describes the generic wizard, where to place it in the "Create New" dialog and the picture to use. I knocked up a quick 32x32 sfml logo in GIMP which I've attached (hope you don't mind Laurent), this also goes in the SFML folder.

That's it. Restart QtCreator, go to New Project/Non-Qt Project and "Plain SFML Project" should be under the usual CMake options. Hope it's useful.

3
Graphics / [SOLVED]Holes between vertices on rotate
« on: July 20, 2014, 08:21:23 pm »
Hello.

So I have a problem with rotating vector of vertices. I've included a simple example and some screen shots.

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

class BackGround : public sf::Drawable, public sf::Transformable
{
public:
    typedef std::vector<sf::Vertex> VertVec;
    BackGround() = delete;
    BackGround(sf::Image &im)
        :m_pType(sf::PrimitiveType::Points)
    {
        m_vertices.reserve(im.getSize().x * im.getSize().y);
        for(int y = 0; y < im.getSize().y; ++y)
        {
            for (int x = 0; x < im.getSize().x; ++x)
            {
                sf::Vertex vert(sf::Vector2f(x+0.5f,y+0.5f));
                vert.color = im.getPixel(x,y);
                m_vertices.push_back(vert);
            }
        }
    }

    ~BackGround(){}
private:

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        // apply the entity's transform -- combine it with the one that was passed by the caller
        states.transform *= getTransform(); // getTransform() is defined by sf::Transformable

        // apply the texture
        states.texture = &m_texture;

        // you may also override states.shader or states.blendMode if you want


        // draw the vertex array
        target.draw(&m_vertices[0],m_vertices.size(),m_pType, states);

    }
    sf::Texture m_texture;
    VertVec m_vertices;
    sf::PrimitiveType m_pType;
};
int main()
{
    sf::RenderWindow win(sf::VideoMode(800,600),"PSIMPL",sf::Style::Close);
    sf::Image im,im2;
    im.loadFromFile("animage.png");

    BackGround bVert(im);


    bVert.setOrigin(400,300);
    bVert.move(400,300);

    while(win.isOpen())
    {
        sf::Event e;
        while (win.pollEvent(e))
        {
            if(e.type == sf::Event::Closed)
            {
                win.close();
            }
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::P))
        {
            im2 = win.capture();
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            bVert.move(sf::Vector2f(-1,0));
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            bVert.move(sf::Vector2f(1,0));
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            bVert.rotate(1);
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        {
            bVert.rotate(-1);
        }
        win.clear();
        win.draw(bVert);

        win.display();

    }
    im2.saveToFile("animage2.png");
    return 0;
}

 

Hopefully you can see that on rotation holes appear between the vertices. It gets worse between 45  degree increments before getting better at  90 degee steps.  It seems like some kind of rounding error but I am unsure how I can compensate, or if I can. It only seems to occur on rotation and not translation. Am I going about this the right way?

I'm only playing around really, seeing how far SFML is coming but I'm hoping to make a destructible terrain type thingy and I thought that keeping a screens worth of vertices would be ideal. The other option would be rendertexture but I think that would be fairly slow for my purposes.

This is happening with cutting edge master from github, mesa 10.2.3, arch linux and xf86-video-ati 1:7.4.0-2.

Pages: [1]
anything