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

Pages: [1] 2
1
Python / Can't install PySFML
« on: June 07, 2018, 03:25:45 am »
I'm trying to install PySFML but I'm getting an error:

Code: [Select]
Could not find a version that satisfies the requirement pySFML (from versions: )
No matching distribution found for pySFML

How to install PySFML?

2
General / Vector of class not storing separate Textures
« on: June 02, 2018, 03:29:34 am »
I'm creating a car simulation using SFML.

As a matter of organization and logic, I created a single class "car", which also inherits sf::RectangleShape, and within this class there are other SFML objects, among them a Texture and a method to setup it.

I want to have multiple cars, so I created a vector of class "car".

In this example, I left only 2 cars with the images:


Here is an extract from the logic I'm using (I did a test program to make it easier to understand):

   
#include <iostream>
    #include <vector>
    #include <SFML/Graphics.hpp>
    #define debug(x) std::cout << #x << "=" << x << std::endl;
   
    using namespace std;
   
    class car : public sf::RectangleShape {
    public:
        string s;
        sf::Texture tex;
        sf::Sprite img;
   
        void imgInit(string imgFile) {
                tex.loadFromFile(imgFile);
                img.setTexture(tex);
                s = imgFile;
        }
    };
    int main()
    {
        vector<car> vecRet;
        car objRet;
   
        objRet.imgInit("car-red.png");
        objRet.setSize(sf::Vector2f(150, 70));
        objRet.setFillColor(sf::Color::Yellow);
        vecRet.push_back(objRet);
   
        objRet.imgInit("car-black.png");
        objRet.setPosition(sf::Vector2f(300, 300));
        objRet.img.setPosition(objRet.getPosition());
        vecRet.push_back(objRet);
   
        debug(vecRet[0].s);
        debug(vecRet[1].s);
            debug(vecRet[0].img.getTexture());
            debug(vecRet[1].img.getTexture());
   
        sf::RenderWindow window(sf::VideoMode(500,500), "Window", sf::Style::Close);
        window.setFramerateLimit(120);
   
        while (window.isOpen())
        {
                for (sf::Event event; window.pollEvent(event);) {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
   
                window.clear();
                window.draw(vecRet[0]);
                window.draw(vecRet[1]);
                window.draw(vecRet[0].img);
                window.draw(vecRet[1].img);
                window.display();
        }
   
        return EXIT_SUCCESS;
    }
 



There are two problems I can not solve:

1) Even doing `push_back` of the two cars, only the last image prevails.
Apparently, push_back refers to a single RAM address for the image.

Then the result looks like this:



That is, the second image (car-black.png) is probably overlapping the address of the first image.

The curious thing is that this only happens with the Texture class. In the example, the program `debug` a string within the class and in this case there is no overlap:

    vecRet[0].s=car-red.png
    vecRet[1].s=car-black.png

However the Texture objects within the class vector are pointing to the same memory address:

Code: [Select]
vecRet[0].img.getTexture()=000000C57A5FF250
vecRet[1].img.getTexture()=000000C57A5FF250

How to solve this?

 2) The second problem is that, for each `vecRet.push_back(objRet)`, the following errors appear in the console:

   
Code: [Select]
An internal OpenGL call failed in Texture.cpp(98).
    Expression:
       glFlush()
    Error description:
       GL_INVALID_OPERATION
       The specified operation is not allowed in the current state.

What i[1]: s this?

3
I'm working on a project with Code:Blocks and I decided to migrate to Visual Studio 2017.
Everythig was ok with this project on CB, but now on VS I get a runtime error "Access Violation" on some SFML Classes. They are outside "main".

For example, in any project, just put "Renderwindow" line outside main and you will get the "Access Violation" runtime error:

sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
int main()
Error:
Code: [Select]
Unhandled exception at 0x00007FF8DF70B709 (ntdll.dll) in teste.exe: 0xC0000005: Access violation writing location 0x0000000000000008. occurred
But I need these classes as Global, and as I said, it was ok on CB, so, how can I solve this?

4
I made this code that shows a timer and pauses when you press spacebar:

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

using namespace sf;
using namespace std;
void events();

bool pause, exitPause;
char key;
double timeFrame, timeTot = 0;
Clock timer;
Text text;
Font font;

RenderWindow window(VideoMode(800, 600), "Window", Style::Close);

int main()
{
        font.loadFromFile("C:/Windows/Fonts/arial.ttf");
        text.setFont(font);
        text.setCharacterSize(15);
        window.setFramerateLimit(120);
        while (window.isOpen())
        {
                for (Event event; window.pollEvent(event);) {
                        if (event.type == Event::Closed)
                                window.close();
                        if (event.type == Event::TextEntered) {
                                key = std::tolower(static_cast<char>(event.text.unicode));
                                if (key == ' ') {
                                        pause = !pause;
                                        if (!pause) {
                                                timer.restart();
                                        }
                                }
                        }
                }
                if (!pause) {
                        timeFrame = timer.restart().asSeconds();
                        timeTot += timeFrame;
                        text.setString(to_string(timeTot));
                        window.clear();
                        window.draw(text);
                }
                window.display();
        }
}
 

If you test, you will see something curious. When pausing by pressing the spacebar, window.display () alternates between the last and the current displayed number.

But if I put window.clear and window.draw together with window.display, the problem does not happen.


                if (!pause) {
                        timeFrame = timer.restart().asSeconds();
                        timeTot += timeFrame;
                        text.setString(to_string(timeTot));
                }
                window.clear();
                window.draw(text);
                window.display();

I thought windows.display, alone, would only show the last buffer.
What is the problem?

5
General / [SOLVED] High CPU usage with almost nothing
« on: May 23, 2018, 01:32:24 am »
Why a single code like this can consume about 15% of CPU usage in a Intel I7 processor?

Code: [Select]
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(800, 600), "Janela", Style::Close);
window.setFramerateLimit(120);
while (window.isOpen())
{
for (Event event; window.pollEvent(event);) {
if (event.type == Event::Closed)
window.close();
}

}
return EXIT_SUCCESS;
}

6
A rectangle shape is inside a view.
The view has been moved, zoomed, rotated, and the same for the rectangle.
But the rectangle is there in the window, visible.



I need to know the exact coordinate of this rectangle in relation to the window edges, ie how to grab a ruler and count the pixels of the visual object to the edges.
This has a purpose: I want to keep the object always visible in the window, regardless of which transformations it receives.

Does anyone know how to do this?

7
General / [SOLVED] Visual Studio 2017 and SFML 2.5.0
« on: May 20, 2018, 05:18:59 am »
I installed Visual Studio 2017 and downloaded SFML Visual C++ 15 (2017) - 32-bit package.
I do not know if they are compatible, but as I did not find the updated SFML package for Visual Studio 2017, I downloaded this one myself.
I configured it according to the video
https://www.youtube.com/watch?v=_9yem5dJt2E
... because the https://www.sfml-dev.org/tutorials/2.5/start-vc.php tutorial was not clear about using the files with "-d" end and was not working.
But I used the example code on this page and when compiling I get the errors:
Code: [Select]
1>ConsoleApplication2.obj : error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)
1>ConsoleApplication2.obj : error LNK2001: unresolved external symbol "public: static class sf::Color const sf::Color::Green" (?Green@Color@sf@@2V12@B)

My question is whether these errors have to do with some mismatch between the installed versions or if the problem is another.
I wanted to avoid the ordeal that is installing SFML manually.

8
General / [SOLVED] What's wrong with this code?
« on: May 14, 2018, 05:21:56 am »
In the code below, I have the attached image (1000x1000) and I want to show it in a window (500x500) using RenderTexture.
However, only part of the image appears in the first quadrant:



What is wrong?

Code: [Select]
#include <SFML/Graphics.hpp>
using namespace sf;

int main()
{
RenderWindow window({500, 500}, "SFML Views", Style::Close);

View camera;
camera.setSize(Vector2f(window.getSize()));

Texture background;
background.loadFromFile("numeros.png");
Sprite numeros (background);

RenderTexture texture;
texture.create(window.getSize().x, window.getSize().y);

Sprite content;
content.setTexture(texture.getTexture());

texture.draw(numeros);
texture.display();

while (window.isOpen())
{
for (Event event; window.pollEvent(event);)
if (event.type == Event::Closed)
window.close();
window.clear();
window.setView(camera);
window.draw(content);
window.display();
}
return EXIT_SUCCESS;
}

9
General / sf::RenderTexture::isRepeated
« on: May 14, 2018, 03:53:53 am »
I researched but found nowhere.
For what practical purpose there is sf::RenderTexture::isRepeated ?

10
General / How to upgrade SFML from 2.4.2 to 2.5.0 (Codeblocks)?
« on: May 12, 2018, 08:10:00 pm »
I would like to upgrade to version 2.5.0.
But remember that it was not easy to make SFML work with CodeBlocks on my Windows, it was several manual steps.
I would like to know if to upgrade to the new version I would need to do a new full install, or is there any easier way?

11
General / Which method is faster?
« on: May 12, 2018, 05:20:21 pm »
If I will draw a sequence of 1000 rectangles, which would be better (and faster): to have 1 RectangleShape and make 1000 draws, or have an array of 1000 RectangleShapes and make 1 draw?

12
General / Views setcenter vs rotation problem
« on: April 26, 2018, 06:22:03 am »
  • I have a view with same dimensions of original window (500,300)


  • I apply view.zoom(2) to leave the view at half the size.


  • Now the view is centered. I want to move the view to the upper left corner of the original window. So I put view.setCenter(500,300);


  • The view is now correctly positioned in the upper corner of the original window. But now I want to rotate the view, making the center of the view its own top left corner, ie (0,0): view.setRotation(5);


As you can see, the center of the axis of rotation should be 0.0 but not respected.
The problem is that if I do view.setcenter (0,0), the whole view returns to the middle of the original window.
How to solve this?

13
General / What is the best way to group objects in SFML?
« on: April 25, 2018, 10:18:28 pm »
If I have for example 3 different shapes in SFML, and I want to rotate them all relative to a single center, as if these 3 shapes were inside a square, what would be the best shape?
Would it be leaving them inside a view and rotating the view?
Or is there some more practical way?

14
General / SFML Pixel Perfect Collision limited to a view?
« on: April 25, 2018, 07:58:47 pm »
In this code I have one view (white, zoom 2) and the original window, also one sprite for a car and one sprite for a wall...

Code: [Select]
#include <SFML/Graphics.hpp>
#include "collision.hpp"

#define windowWidth  1000
#define windowHeight 600

int main()
{
    sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Views");

    sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
    view.zoom(2);

// car
    sf::Texture imgCar;
    Collision::CreateTextureAndBitmask(imgCar, "carro.png" );
    sf::Sprite car;
    car.setTexture(imgCar);
    car.setPosition(0, (windowHeight - imgCar.getSize().y) / 2);

// wall
    sf::Texture imgWall;
    Collision::CreateTextureAndBitmask( imgWall, "barreira.png" );
    sf::Sprite wall;
    wall.setTexture(imgWall);
    wall.setPosition(windowWidth - imgWall.getSize().x, 0);

    sf::RectangleShape background (sf::Vector2f(windowWidth, windowHeight));
    background.setFillColor(sf::Color::White);


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        if (!Collision::PixelPerfectTest(car, wall))
            car.move(0.1, 0);

        window.clear();
        window.setView(view);
        window.draw(background);

        window.setView(window.getDefaultView());
        window.draw(car);
        window.draw(wall);
        window.display();
    }

    return 0;
}

... if both car and wall are related with the main window,  I get a perfect car collision with the wall.





Now if I put the car inside the view ...

Code: [Select]
window.clear();
window.setView(view);
window.draw(background);
window.draw(car);

window.setView(window.getDefaultView());
window.draw(wall);
window.display();

... the collision is detected as if the wall were within the boundaries of the view (which is zoomed in).



How can I make the collision detection independent of the view?

15
General / Views vs window confusion
« on: April 24, 2018, 09:41:52 pm »
I have this single code...

#include <SFML/Graphics.hpp>

#define windowWidth  600
#define windowHeight 300

int main()
{
   sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Views");

   sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
   view.zoom(2);
   window.setView(view);


   sf::RectangleShape back (sf::Vector2f(windowWidth, windowHeight));
   back.setFillColor(sf::Color::White);

   sf::RectangleShape rect (sf::Vector2f(200, 100));
   rect.setFillColor(sf::Color::Red);
   rect.setPosition(windowWidth - rect.getSize().x, windowHeight - rect.getSize().y); // position in the lower right corner

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

        window.clear();
        window.draw(back);
        window.draw(rect);
        window.display();
    }

    return 0;
}


...which might position the red rectangle in the lower right corner of the window.



However, when I zoom the view in (as in the code), it obviously moves along with the entire window.
I have some doubts:

   
  • To correct the positioning of the red rectangle and place it in the lower right corner of the global window, I currently have to do some calculations considering the zoom factor, original rectangle size, etc. Is there any easier way to position this rectangle in the lower-right corner of the global window?
  • How do I prevent some objects from being resized by the zoom of the view?
  • What do I have to do to have multiple active views in the same window?

Pages: [1] 2
anything