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

Pages: [1]
1
Graphics / Re: sf::VertexArray: Help Generating Verticies of This Object
« on: August 11, 2014, 01:27:20 am »
You want to describe the outer rim of a circle?

x = radius * cos(angle)
y = radius * sin(angle)

Where angle is in radians.

So:

#include <SFML/Graphics.hpp>
const float DEGTORAD = 0.0174532925199432957f;

int main()
{
    const int SWIDTH = 1024;
    const int SHEIGHT = 768;
    std::vector<sf::Vertex> vertices(32);
    float radius = 100;
    float TOTALANGLE = 180.f;
    vertices[0]= sf::Vertex({0,0});
    vertices[0].color = sf::Color::White;
    for (int i = 0; i < 31; i+=2)
    {
          float angle = i / 30.f * TOTALANGLE * DEGTORAD;
          vertices[i+1] = sf::Vertex( {radius * cos(angle), radius * sin(angle)} );
          vertices[i+1].color = sf::Color::White;
    }
    for(auto &a: vertices)
    {
        a.position += sf::Vector2f(100,100);

    }
    sf::RenderWindow win(sf::VideoMode(SWIDTH,SHEIGHT),"Cossin",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.draw(&vertices[0],vertices.size(),sf::PrimitiveType::Lines);
        win.display();
    }
    return 0;
}


 
NOTE: This describes a 180 degree half-circle in 32 x,y points starting at 0,0 and stretching out to 100,100. What you do with those is up to you.

2
Graphics / Re: Impossible to create render texture (failed to link...
« on: August 10, 2014, 11:00:36 pm »
Probably same issue as here and here. Your call to sf::Texture::getMaximumSize() before any other GlResource is created breaks context management resulting in sf::RenderTexture going crazy. Since the fix hasn't been merged yet, you can try to create an sf::Context object at the start of your main() if you don't plan on creating a window and see if that fixes the problem.

Looks like you hit it. As a quick test I replaced the getmaximum with a hardcoded value and the problem disappears. I'll see if I can do the context thingy.

Edit: Keeping an active context before calling getMaximum also fixes this. Thanks

3
Graphics / Re: Impossible to create render texture (failed to link...
« on: August 10, 2014, 10:57:54 pm »
RenderTexture does work, I've used them before and it passes the isAvailable test. Like I said, it's only the first iteration which has the problem, it smells of a bug to me.

Nevertheless:

Radeon X1950 PRO RV570
ati-dri: 10.2.5-1

Intel Mobile 4
intel-dri: 10.2.4-1

Did you run the code?


4
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.

5
General discussions / Re: Custom SFML Wizard for QtCreator
« on: July 31, 2014, 05:26:48 pm »
That works too. You learn soemthing new every day, I've updated the original post.

6
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.

7
Graphics / Re: [SOLVED]Holes between vertices on rotate
« on: July 20, 2014, 10:38:56 pm »
My intial tests with a render texture are positive.  At the moment I'm building a background from two images onto a RT and using the resulting texture as a sprite. When I want some of the foreground gone I'm creating a vertex array from the background image and blitting it onto the RT and then updating the sprites texture from that.

Sorry to be a pain but I'm not too clear on what you mean. Are you referring to creating a pixel array copied from part of the image, adjusting the alpha component for the pixels I'm interested in and updating the texture from that?

8
Graphics / Re: Holes between vertices on rotate
« on: July 20, 2014, 09:59:01 pm »
Yes your solution and explanation does work. Thank you. Unfortunately moving from points to quads is just too expensive for my machine. I'll mark this as solved but I guess I'm back to experimenting.

9
Graphics / Re: Holes between vertices on rotate
« on: July 20, 2014, 08:37:20 pm »
That was quick, thanks. Yes I'm mapping an image to the array so I can switch off pixels as I need to.  What you say makes sense but let me ask what you mean. Is it a 2x2 square for each pixel or a square (0.0f,0.0f,1.0f,1.0f).. 1x1?


10
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]