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

Pages: 1 [2] 3 4 ... 34
16
Hmm, I had no errors with either version.

What're your system specs? Drivers up to date? SFML version?

17
window.setActive(false); needs to go in the thread you do not want to do OpenGL stuff, and window.setActive(); needs to go in the thread you want to do OpenGL stuff.

Here's a contrived modification of your original code that solves the event handling issues you'll see (ie: frozen window, can't move/resize, etc) if you don't handle events on the main thread.
#include <atomic>
#include <thread>

#include <SFML/Graphics.hpp>

std::atomic_bool run = true;

void render(sf::RenderWindow &window, sf::CircleShape &shape)
{
    window.setActive();

    while (run)
    {
        window.clear();
        window.draw(shape);
        window.display();
    }
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    window.setActive(false);
    std::thread t1(render, std::ref(window), std::ref(shape));

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

    if (t1.joinable())
        t1.join();

    return 0;
}

18
That's a different issue - as I recall, the correct way is to call setActive() on the OpenGL resource, (the sf::RenderWindow& in this case).

Also, as an fyi, I know some OS' don't allow event polling on anything other than the main thread. So you may encounter issues there in the future.

19
You want to use std::ref() for things you want to pass by reference to std::thread().

This is because std::thread() movies/copies by value.

20
General / Re: static GUI library statically linking SFML
« on: May 29, 2018, 11:21:52 pm »
If SFML is statically linked to its dependencies, then your SFUI library shouldn't need to link in SFML's dependencies.

(I'm looking at line 114 of your pastebin - your SFUI lib is linking SFML static libs AND its dependencies)

21
Graphics / Re: Getting camera images
« on: April 15, 2018, 09:33:58 pm »
This isn't the easiest thing to find (good) results for, so I'll give you some pointers.

You've got a few options.
  • ffmpeg (or some other program) - create a subprocess using the operating system API calling ffmpeg with parameters to the camera. You can set the subprocess to write to memory you own.
  • libffmpeg - the library version of ffmpeg
  • OpenCV - the library has image capturing functionality. A bit overkill if you just want to capture images (ie: not use the computer vision functionality), but the API is easy.
  • libuvc
  • If you're on Linux, you can use the v4l2 (Video for Linux 2) API. It's fairly straightforward, just expect to be doing a lot of C-style code (the equivalent-ish APIs on Windows are DirectShow or Windows Image Acquisition, iirc)
  • If it's a specific/specialized device, the manufacturer might have an official API/method for capturing images (ie: Raspberry Pi Camera, Intel RealSense, etc)

After that, it's a matter of converting the captured image to SFML types, as sjaustirni said.

Hope this points you in the right direction.

22
General / Re: Stun character
« on: April 01, 2018, 01:24:46 pm »
Overall game clock?

if(!player.stunned)
{
    player.playerMovement();
    if(conditionToStun)
        player.stunTime = gameClock.getElapsedTime();
}
else if(gameClock.getElapsedTime() - player.stunTime >= sf::seconds(3.0))
    player.stunned = false;
 

23
General / Re: GL.GetString on SFML.NET
« on: January 25, 2018, 05:52:51 pm »
Theoretically it should work! I didn't have a chance to test it.

If it doesn't, report back with the errors and I'll fix it when I have the chance.

24
General / Re: GL.GetString on SFML.NET
« on: January 25, 2018, 05:21:38 pm »
SFML.NET is in the midst of an overhaul (see PR: https://github.com/SFML/SFML.Net/pull/143). Once that gets merged, I've been planning to do a run-thru/check-over of the examples and such (including compiling new binaries, finally).

As for being able to call glGetString, I'd do something like this with P/Invoke (Assuming Windows):
static class GL
{
    public enum PlatformInfo
    {
        Renderer = 0x1F01,
    }

    [DllImport("OpenGL32", EntryPoint = "glGetString", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
    private static extern unsafe byte* GetString(int name);

    public static string GetString(PlatformInfo pi)
    {
        IntPtr ptr;
        unsafe
        {
            byte* str = GetString((int)pi);
            ptr = new IntPtr(str);
        }
        return Marshal.PtrToStringAnsi(ptr);
    }
}

25
General / Re: Problem with static linking - missing winmm.lib
« on: January 24, 2018, 06:57:05 pm »
There should be a WinMM.Lib file in (by default) C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.91\um\$(ARCH). Is this correct?

For reference, I have 10.0.16299.0 installed, and that is where it is located on my machine.

26
Audio / Re: How to make main thread wait for SoundRecorder to finish
« on: January 22, 2018, 09:51:53 pm »
I tried a new way of waiting for the audio thread to finish, and I found that returning false from onProccessSamples() somehow causes onStop() not to be called. Am I missing something? By always returning true from onProccessSamples(), I can manually call stop() from the main thread and have onStop() get called.

I took a quick look at the source and onStop() is only called when stop() is called. Which (to me) seems odd. I would expect onStop() to be called once recording is stopped for any reason, not just explicitly stopped (ie: at the end of sf::SoundRecorder::record() or sf::SoundRecorder::cleanup()).

Maybe we should start a discussion about remedying that.

27
Window / Re: Changing dynamically window contextsettings
« on: January 22, 2018, 09:38:04 pm »
It's also how a lot of games do it (ever had a game tell you to restart after changing some settings?)

28
Audio / Re: How to make main thread wait for SoundRecorder to finish
« on: January 21, 2018, 08:19:21 pm »
You could use a private std::promise that is initialized in onStart(), and calls it's set_value() method in onStop().
Then, provide a function that returns the std::future from the std::promise's get_future() method. Then all your working function (ie: main()) has to do is call the std::future's wait() (or one of the timeout versions) method.

Reusing and modifying your code:
#include <future>
#include <iostream>
#include <SFML/Audio.hpp>
 
struct CRecorder : sf::SoundRecorder
{
    CRecorder() { }
 
    ~CRecorder() { stop(); }
 
    bool onProcessSamples(const int16_t* samples, const size_t sampleCount)
    {
        std::cout << "CustomRecorder::onProcessSamples() [samples:" << sampleCount << ", done: ";
 
        // collect samples
        count += sampleCount;
 
        // return false when 22050 or more have been collected, otherwise return true
        // note that onProcessSamples may be called again (sometimes) even though we return false
        return count < 22050;
    }
 
    bool onStart()
    {
        std::cout << "CustomRecorder::onStart();" << std::endl;
        // reset the promise so it can be reused
        complete = std::promise<void>{};
        setProcessingInterval(sf::milliseconds(25));
        return true;
    }
 
    void onStop()
    {
        std::cout << "CustomRecorder::onStop();" << std::endl;
        // tell any listeners we're all done
        complete.set_value();
    }

    std::future<void> getCompleteSignal()
    {
        return complete.get_future();
    }
 
    size_t count = 0;

private:
    std::promise<void> complete;
};
 
int main()
{
    CRecorder r;
    std::cout << "starting audio capture" << std::endl;
    r.start();

    std::future<void> complete = r.getCompleteSignal();
   
    // do some other work if desired
    // ...
 
    // if a timeout is desired, wait_for() or wait_until() can be used instead
    complete.wait();
    std::cout << "done waiting" << std::endl;

    return 0;
}

Benefit of this method, is the thread calling std::future<T>::wait() can sleep, or busy wait, depending on the std library implementation.

If you'd want to be able to notify multiple threads, see std::shared_future

Another option would be std::condition_variable

29
DotNet / Re: SFML.Audio.Music System.DllNotFoundException
« on: January 14, 2018, 07:01:19 pm »
Did you match exe/dll architectures? (All x86, or all x64?)

30
SFML projects / Re: [Release][GUI] SFML + ImGui lib
« on: January 11, 2018, 04:26:32 pm »
Sure.

Here's the project layout:
Code: [Select]
./
  imgui/
    imgui.h
    ...
  imgui-sfml/
    imconfig-SFML.h
    imgui-SFML.h
    ...
  project/
    imconfig.h
    main.cpp

project/imconfig.h contains
#include <imgui-sfml/imconfig-SFML.h>

project/main.cpp contains
#include <imgui.h>
#include <imgui-sfml/imgui-SFML.h>

I have the project root directory, project/, and imgui/ folders as include directories, ie: "-I$PROJECT_DIR -I$PROJECT_DIR/project -I$PROJECT_DIR/imgui"
This is needed because imgui.h has #include "imconfig.h", and imgui-SFML.cpp has #include <imgui.h>

You'll also have to make sure you delete, (or rename) imgui/imconfig.h, otherwise you'll run into conflicts at compile time with your project/imconfig.h
Or you could even just use imgui/imconfig.h, and not have a project/imconfig.h

Pages: 1 [2] 3 4 ... 34