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

Pages: 1 ... 16 17 [18] 19 20 ... 22
256
Graphics / Re: how to set background.
« on: July 14, 2021, 03:52:33 am »
setTexture() doesn't take a pointer. It's prototype is:
void setTexture(const Texture& texture, bool resetRect = false);
The texture parameter is a reference. Doing sprite.setTexture(&texture); would be a compile error.


257
General / Re: Reason: Unable to open file
« on: July 04, 2021, 03:59:42 pm »
The default working directory for Visual Studio is $(ProjectDir), which is the directory where the .vcxproj file is located.
The setting for this is in the project properties under Debugging / Working Directory.

Common ones you can include in the setting:
$(ProjectDir) - Where the .vcxproj file is.
$(SolutionDir) - Where the .sln file is.
$(TargetDir) - Where the .exe is put during a build.
(Note: all of these expand to an absolute path with a slash on the end)

I tend to do all of my settings (intermediate, output, etc) relative to the .sln. So I use: $(SolutionDir)bin\
But $(TargetDir) would work too.

258
General / Re: Sprites-mouse input
« on: June 27, 2021, 08:44:50 am »
The problem here is because SFML is doing double buffering.
Here's how it works: You have 2 buffers (memory for full windows). At any instance one will be the back buffer (where you draw) and one will be the front buffer (which is seen on the monitor). Calling the display() method swaps the two buffers. So you typically construct the scene entirely in the back buffer, then when finished do the display so that work becomes visible and you can wipe and start drawing again in the other buffer.

Usually this is fine since every frame you clear the buffer and draw everything, so after a swap (display() call) it all gets done again. But in your situation without the clear and only drawing everything once, half your draw calls go to one buffer and half to the other. Your tabla.jpeg is only drawn once, so it will flicker on and off because you only drew it in one buffer, not both.

Some solutions:
1 - stop double buffering. I have no idea if SFML allows that, I think it's hard coded to do it (had a quick look, didn't see a way) since 99% of use cases benefit from it.
2 - do everything twice. Draw, display, draw again, display again. That way both buffers will get everything. Not a nice solution but it would probably work.
3 - Render Texture. A render texture is like a back buffer but you own it and can draw into it when you want. You can put a render texture on a sprite or shape and draw it to the window like normal, but you can also draw into the render texture. Drawing to the render texture isn't double buffered.

Some rough pseudocode:
Draw board into the render texture
While window open
   If mouse pressed
      Draw tile into render texture
   End
   Clear window
   Draw render texture
   Display
End

Some code for render textures is shown here: https://www.sfml-dev.org/tutorials/2.5/graphics-draw.php under the off screen drawing section.

259
General / Re: error generating makefile .exe file
« on: June 23, 2021, 11:17:49 pm »
I don't use VSCode for C++, so just guessing here, but if you needed to type bin/main.exe instead of main.exe then the working directory for VSCode isn't the bin directory.
When you run an exe from explorer, the working directory is the directory where the exe is.
All of the sfml dlls need to be in either the system path or the working directory (ie. bin if running from explorer).

260
General / Re: Code crashes upon using font.loadFromFile
« on: June 22, 2021, 08:40:49 pm »
You have only a single back slash between src and Roboto.
A single backslash will attach to the next character (the R) and change it, so the name is invalid.

261
Window / Re: How to check if sf::RenderWindow is fullscreen?
« on: June 17, 2021, 12:01:39 pm »
Yep, plus usually fullscreen is a mode that behaves differently, it doesn't only mean the window is the size of the screen (since borderless windowed is the size of the screen but isn't "fullscreen").

There's a function in WindowBase that tells you if the window is fullscreen, but it's private so can't be called from user code.  (WindowBase::getFullscreenWindow() returns 0 if the window isn't fullscreen).

262
Graphics / Re: Inheritance from Shape
« on: June 06, 2021, 03:24:40 pm »
It looks like this isn't using inheritance, it appears to be aggregation of rectangleshape (it's got a pointer to one). But we'd need to see the whole class to see where it might be going wrong.

263
General / Re: Undefined reference to
« on: June 05, 2021, 05:34:32 pm »
I saw on reddit that these errors will come from using the wrong SFML for your compiler.
From your top lines, looks like you are trying to use the Visual Studio 2017 (VC15) version of SFML with MingW (which is GCC, not Visual Studio). So you need to download the GCC version of SFML.

At least from what I just read, been many years since I used MingW for ARM development. :)

264
General / Re: Strange problem with sprite collision
« on: June 04, 2021, 03:06:43 pm »
This:
   int i = 0, j = 0;

    while(i < vectorHeroes.size())
    {

        while(j < vectorHeroes.size())
        {

Should be:
   int i = 0;

    while(i < vectorHeroes.size())
    {
        int j = 0;
        while(j < vectorHeroes.size())
        {
So j gets reset to zero every time i increments.
Otherwise this would happen... (let's say vectorHeroes.size() is 4)
i is 0
   j is 0
   j is 1
   j is 2
   j is 3
i is 1
   j is 4 so while loop is skipped
i is 2
   j is 4 so while loop is skipped
i is 3
   j is 4 so while loop is skipped




265
General / Re: Strange problem with sprite collision
« on: June 04, 2021, 01:14:10 pm »
You aren't resetting j to zero when the while(j < vectorHeroes.size()) loop is started again.

Or for a bit of a saving, you can halve the comparisions by starting the j loop with the value of i+1, then do the collision response to both objects. This makes it so the loops won't do (for example) object 5 vs 10 and 10 vs 5, only the first happens and does the work of both.
(Hope that made sense, just got home from a VERY long day at work)

266
It definitely makes it easier when what is happening that isn't correct is stated.

But at a guess, it looks like your animation update function isn't using deltaTime, so the animation doesn't advance frames. Probably a totalTime+=deltaTime; should be in there.

267
so what should I use to get the binary without corrupting the data?
As Stauricus said, the easiest way to get stuff into SFML is to use the open/load functions. Music::openFromFile can load wav, ogg and flac. Texture::loadFromFile can load bmp, png, tga, jpg, gif, psd, hdr and pic.

But if you do want to open a binary file yourself (handy for things not part of SFML like save files, maps, etc), here's an quick example.
#include <fstream>
#include <filesystem>

int main()
{
    // Path to file
    std::filesystem::path p = "raw.dat";
    std::error_code ec;
    // Get the size of the file
    auto size = std::filesystem::file_size(p,ec);
    // Make sure no errors happened when getting the size
    if (!ec)
    {
        // Allocate enough memory for it
        char* data = new char[size];
        // Open the file for binary reading
        std::fstream in("raw.dat", std::ios::binary | std::ios::in);
        // If it opened...
        if (in.good())
        {
            // Read in the file
            in.read(data, size);
            // You now have the entire file sitting in data
        }
        // Release memory now that we are done
        delete[] data;
    }
    return 0;
}
 
This is using C++17, it added the file system stuff that can check the size of a file.
Also some may prefer to use a vector or something for the data, but I just stick to simple new/delete (yeah, I learned C++ long before std existed)

268
That loop is corrupting the data.
Wav files are binary data, they don't have lines as such. The getline function looks for end of line characters (which will be coincidental, since there's no lines to end) and strips them away. So the result in file will be missing bytes.
Wav is just waveform data, so you probably won't notice, but more complex formats like compressed textures will be corrupted.

Anyway, Texture has loadFromMemory, which is the equivalent of Music's openFromMemory.

269
Graphics / Re: How to optimize multiple draws
« on: May 21, 2021, 09:22:07 am »
What does a cell look like? If it's just a solid colour representing it's status, then you could use a texture. Set it's pixels to represent the cells. Then you can have any size (well, up to 8192x8192, maybe 16384x16384 depending on gfx card and if sfml lets it) with a single draw call.

For example:
                sf::Texture tex;
                tex.create(64, 64);

                sf::Image img;
                img.create(64, 64);

                img.setPixel(10, 20, sf::Color::Red);
                tex.update(img);
 
This makes a texture (which you'd use for a sprite or quad, etc) and an image. You can change the cells in the image using setPixel, then when all cell statuses are up to date, call tex.update(img) to upload the current image to the texture.

If the cells aren't simple blocks, something more complicated might be needed. (Shader, or multi pass blending)

270
Graphics / Re: SOLVED SFML can not open window.hpp
« on: May 21, 2021, 09:04:32 am »
Edit: Oh, I see the thread is now titled as solved. Cool. Ignore the below then. :)

No, there is a window.hpp include in graphics.hpp (line 32 in my version).

What did you set your include path to in your compiler? The graphics.hpp one is explicitly <SFML/Window.hpp> so it's looking in the include path for that. So you'd need to have External\include as part of the include path.
In visual studio c++, the addition includes setting is either relative to the project (where the .vcxproj file is) or an absolute path. If you are using mingw or something, that's not my area. :)

If you aren't sure how to get the correct include path, let us know the absolute path of where your window.hpp file is (for example c:\sdks\External\include\SFML\window.hpp) and the absolute path for your project file (for example C:\Users\kojack\source\repos\ConsoleApplication24\ConsoleApplication24.vcxproj).


Pages: 1 ... 16 17 [18] 19 20 ... 22
anything