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

Pages: [1] 2 3
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 / Re: Vector of class not storing separate Textures
« on: June 02, 2018, 02:58:23 pm »
Now I realize that vector push_back does not work for Texture, since push_back does not save the whole image of the Texture object, but only the object pointer.
So I can not reuse the same Texture object twice, because the second image will overlap the first and as two push_backs point to the same memory address:

        sf::Texture tex;
        vector<sf::Sprite> vecImg;
        sf::Sprite img;

        tex.loadFromFile("car-red.png");
        img.setTexture(tex);
        vecImg.push_back(img);
        tex.loadFromFile("car-black.png");
        img.setPosition(200, 200);
        vecImg.push_back(img);

        debug(vecImg[0].getTexture());
        debug(vecImg[1].getTexture());

Code: [Select]
vecImg[0].getTexture()=00000066C8D4F428
vecImg[1].getTexture()=00000066C8D4F428

3
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?

4
Since I am still a beginner in C++, I am gradually discovering the most common practices in this language, and after reading several opinions, I have realized that global variables are contraindicated in more than 90% of cases because it is dangerous and difficult to control.
I am refactoring my code and I have managed to resolve this error.
Thank you again.

5
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?

6
General / Re: Visual Studio 2017 and SFML 2.5.0
« on: May 29, 2018, 11:55:08 pm »
Perfect!
Thank you very much.

7
General / Re: Visual Studio 2017 and SFML 2.5.0
« on: May 29, 2018, 10:58:03 pm »
Of course, I had put SFML_STATIC only in the debugger. Now it's ok.
Thank you!  :)

Just one more thing:
In order to not generate the console screen in the release version, under "Linker-> System-> Subsystem", I switched from "Console (/ SUBSYSTEM: CONSOLE)" to "Windows (/ SUBSYSTEM: WINDOWS)".
But with this latter option, it generates this error when compiling:

Code: [Select]
1>------ Build started: Project: teste, Configuration: Release x64 ------
1>MSVCRT.lib(exe_winmain.obj) : error LNK2001: unresolved external symbol WinMain
1>C:\Users\Rogerio\Desktop\c++\Visual Studio\teste\x64\Release\teste.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "teste.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How to solve this?

8
General / Re: Visual Studio 2017 and SFML 2.5.0
« on: May 29, 2018, 09:38:09 pm »
I was able to install the Visual C++ 15 (2017) - 64-bit with static libraries.
Debug is working fine.

But when compiling a "release", I get:

Code: [Select]
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::CircleShape::CircleShape(float,unsigned __int64)" (__imp_??0CircleShape@sf@@QEAA@M_K@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QEAA@VVideoMode@1@AEBVString@1@IAEBUContextSettings@1@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QEAA@EEEE@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::display(void)" (__imp_?display@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QEAA_NAEAVEvent@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QEBA_NXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Window::close(void)" (__imp_?close@Window@sf@@QEAAXXZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::Color const sf::Color::Green" (__imp_?Green@Color@sf@@2V12@B)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QEAAXAEBVDrawable@2@AEBVRenderStates@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __cdecl sf::Shape::setFillColor(class sf::Color const &)" (__imp_?setFillColor@Shape@sf@@QEAAXAEBVColor@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QEAA@PEBDAEBVlocale@std@@@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QEAA@III@Z)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl sf::CircleShape::~CircleShape(void)" (__imp_??1CircleShape@sf@@UEAA@XZ)
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl sf::String::~String(void)" (__imp_??1String@sf@@QEAA@XZ)
1>C:\Users\Rogerio\Desktop\c++\Visual Studio\sfml-vc15-64\x64\Release\sfml-vc15-64.exe : fatal error LNK1120: 17 unresolved externals
1>Done building project "sfml-vc15-64.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is my configuration to Release.
What is wrong?


9
Because of double buffering and clear-dispaly is non-optional

I learned it is necessary to put window.display inside the loop to avoid processor overload since it inserts the necessary breaks within the frame rate limit. Still, it would be more logical to have a command just for that, not window.display, which is constantly rendering something repeated, unnecessarily.
Now, I realize that the loop needs to consistently send the clear, the draw, and the display (even when the program is paused). Does not this burden the gpu unnecessarily?
Is not there a better way?

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

11
General / Re: [SOLVED] High CPU usage with almost nothing
« on: May 23, 2018, 03:57:48 pm »
Perfect.
Thank you very much!

12
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;
}

13
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?

14
General / Re: Visual Studio 2017 and SFML 2.5.0
« on: May 21, 2018, 08:50:46 pm »
The tutorial doesn't talk about static dlls, because that's not a thing.

From https://www.sfml-dev.org/tutorials/2.5/start-vc.php:
Quote
If you want to get rid of these DLLs and have SFML directly integrated into your executable, you must link to the static version. Static SFML libraries have the "-s" suffix: "sfml-xxx-s-d.lib" for Debug, and "sfml-xxx-s.lib" for Release.
In this case, you'll also need to define the SFML_STATIC macro in the preprocessor options of your project.

I do not want to argue, I just want to solve the problem. The file provided does not have the static DLLs. How to solve this?

15
General / Re: Visual Studio 2017 and SFML 2.5.0
« on: May 21, 2018, 06:40:52 pm »
Thank you. Now I understand what the static and dynamic library is.
But the tutorial https://www.sfml-dev.org/tutorials/2.5/start-vc.php talks about the static dlls, the link available for download https://www.sfml-dev.org/files/SFML-2.5.0-windows-vc15-32-bit.zip brings only dynamic libraries.
Is not this contradictory? Should not the static DLLs be included together?

Pages: [1] 2 3
anything