Spout SDK for noobs

Home Forums Spout Developer Spout SDK for noobs

This topic contains 9 replies, has 2 voices, and was last updated by  leadedge 1 week ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #4017

    laurin_d
    Participant

    Hey hey. I did a symple code using Processing to resive i spout texture but it was to slow. So i need to do it in c or c++. I am quite new in coding c and i am not able to get the exampl patch running in visual studio or bloodshed def. I dont know how to import or build the Projekt. I know that are basics but maybe someone here can do some noob instructions to just run the examplecode to start working from that.

    #4018

    leadedge
    Keymaster

    I think it is important to find out why the Processing sketch is so slow before tackling development with C++ if you are new to it.

    The Spout texture sharing part of the Processing sketch should not be too slow. It’s possible that it is starting with Memoryshare mode which is slower than texture sharing.

    When the receiving sketch starts to receive from a sender, you will see in the console window which mode is initialized. Do you see “Spout initialized memory sharing”?

    If you do, the cause must be found or a C++ application will be just as slow. Usually this is caused by incorrect Optimus graphics settings for a laptop or incompatible graphics hardware.

    You can also run the Spout demo sender and receiver to find out if they are slow, as well as other applications that support Spout.

    If you wish to develop with C++, I suggest staying with Openframeworks and Visual Studio if you can. From what I can see, Dev-C++ by BloodshedSoftware uses a MingW based compiler and you will probably need to use SpoutLibrary instead of the source code directly. However, if you wish to stay with Dev-C++, using SpoutLibrary is not difficult and you should look at the example source code.

    Otherwise I will try to give some step-by-step instructions.

    Unfortunately the Openframeworks examples are out of date and the project files are for Visual Studio 2012, so they will not build immediately with Visual Studio 2017.

    The following assumes that you have installed Openframeworks 10 and Visual Studio 2017 and can successfully build the “examples\templates\emptyExample” or any of the other examples.

    To build Spout SDK example with Visual Studio 2017 :

    1) Install Spout 2.006
    2) In your Openframeworks folder create a new folder “SpoutSDK” at the same level as “myApps”
    3) Double click the Spout icon on your desktop and a folder will open in File Explorer.
    4) Copy the source files from “..\Spout2\SPOUTSDK\SpoutSDK” to the SpoutSDK folder you just created
    5) Copy the “..\Spout2\SPOUTSDK\Examples\ofSpoutExample” folder to the “myApps” folder of Openframeworks.
    6) Open Visual Studio 2017
    7) File > Open > Project/Solution
    8) Browse to the ofSpoutExample folder and select “ofSpoutExample.sln”
    9) Allow re-targeting “Upgrade to v141”
    10) Change from “Debug” to “Release” mode.
    11) Expand the “SpoutSDK” folder in the Solution Explorer
    12) Double click on “Spout.h” – does it open or give an error that it cannot be found?
    13) If it opens OK, skip to step 17.
    14) Highlight all the SpoutSDK files, RH click and “Exclude from project”
    15) RH click on the SpoutSDK folder in the Solution Explorer > Add > Existing item
    16) Browse to apps\SpoutSDK, highlight all the Spout SDK source files and OK.
    17) RH click on the ofSpoutExample project in the Solution Explorer and “Build”
    18) The project should build successfully. There will be warning errors but you can ignore them.
    19) On the menu bar, choose Debug > Start without debugging (or you can use Ctrl-F5).
    20) The example sender should start.

    To create an example receiver

    1) Browse to “..\apps\myApps\ofSpoutExample\src\ofSpoutReceiver”
    2) Highlight and copy both “ofApp.cpp” and “ofApp.h”
    3) Move up one level to the “src” folder
    4) Paste and replace the two files.
    5) Go back to Visual Studio – accept the changed files if there is a warning
    6) RH click on the ofSpoutExample project in the Solution Explorer and “Rebuild”
    7) Repeat steps 18 and 19
    8) The example receiver should start.

    Please post your experiences here. But I still believe you should first investigate why the Processing sketch is so slow. If you can share the sketch I will look at it.

    #4019

    laurin_d
    Participant

    First:
    Thanksu for the respond.
    The thing in processing was not the performance of spout. For my task i have to read some pixels and convert them to rgb values in int and send them as udp via lan to a raspberry pi. The most performance took the conversation in processing becouse i have no pointer control. So i thought i use C and take a look to a easy IDE. i try to use the dll and Lib as you told and faild. but now i have the Visualstudio 2017 and it works fine. ofRisiver is working and i can edit and use it. thats realy fine. openFrameworks feels just like processing and do a good job.
    One last question. in the code you get the localTexture from spout (spoutreceiver.ReceiveTexture). is it posible to work directly with the shared texture and do not copy it like in the (spoutreceiver.ReceiveTexture). its ok if there is no way but it would be nice.
    TY so far
    Laurin

    #4020

    laurin_d
    Participant

    First:
    Thanksu for the respond.
    The thing in processing was not the performance of spout. For my task i have to read some pixels and convert them to rgb values in int and send them as udp via lan to a raspberry pi. The most performance took the conversation in processing becouse i have no pointer control. So i thought i use C and take a look to a easy IDE. i try to use the dll and Lib as you told and faild. but now i have the Visualstudio 2017 and it works fine. ofRisiver is working and i can edit and use it. thats realy fine. openFrameworks feels just like processing and do a good job.
    One last question. in the code you get the localTexture from spout (spoutreceiver.ReceiveTexture). is it posible to work directly with the shared texture and do not copy it like in the (spoutreceiver.ReceiveTexture). its ok if there is no way but it would be nice.
    TY so far
    Laurin

    #4021

    leadedge
    Keymaster

    OK I understand. I am glad you have it working.

    Yes you can work directly with the shared texture. But first you might try to receive into RGB pixels. Create the RGB image memory buffer (unsigned char) and use “ReceiveImage” with GL_RGB for the glFormat argument. Integer pixels are not supported though so you would need to convert.

    To work with the shared texture, use ReceiveTexture without a texture argument e.g.

    ReceiveTexture(char* Sendername, unsigned int &width, unsigned int &height);

    Then access the texture with :

    BindSharedTexture();
    .
    OpenGL code
    .
    UnBindSharedTexture();

    #4024

    laurin_d
    Participant

    So if i do ReceiveImage without texture ill get the buffer on ram and the readback is allready done in the spoutSDK? I thought i have to convert my texture to ofPixel and after Pix.getColor?

    #4025

    leadedge
    Keymaster

    ReceiveImage will receive into a pixel buffer and you can specify RGB so your conversion to RGB int is easier with a simple loop through the pixel data.

    ReceiveTexture can be used without a receiving texture and you will have an RGBA OpenGL texture within Spout that you can work with directly as you say. But you have to use OpenGL functions to access it.

    If you want to convert to ofPixels from ofTexture, then you will need to receive into an Openframeworks RGBA texture. You will then need to convert the RGBA ofPixels to the RGB int buffer somehow. Using getColor for every pixel would probably be too slow.

    You can explore these options for best performance.

    #4026

    leadedge
    Keymaster

    P.S. to get ofPixels from ofTexture you can use :

    void ofTexture::readToPixels(ofFloatPixels &pixels)

    (https://openframeworks.cc/documentation/gl/ofTexture/#show_readToPixels)

    Then you have a raw pointer to the rgba pixel data within ofPixels :

    (https://openframeworks.cc/documentation/graphics/ofPixels/#show_getData)

    Then you can use a loop to convert to RGBA char to RGB int by skipping alpha in the loop.

    #4030

    laurin_d
    Participant

    thank you so far.
    my app is working and i am so glad i did it in cpp. i did it now with “readToPixels” and its working fine. i also tryed with receiveImage but i dont know the arguments i have to ask for.in the example you ask for:

    “if(spoutreceiver.ReceiveTexture(SenderName, width, height, myTexture.getTextureData().textureID, myTexture.getTextureData().textureTarget)) {
    what i ask for a immage?

    and the other question is if i want to move all spout receive stuff from ofApp to a ofTimer thread it cant initialice. if i ask: “if(spoutreceiver.CreateReceiver(SenderName, width, height, true)) in ofTimer its not working. i moved all stuff from off app to a timer and its not working. maybe you know something about that? would be nice else i have very high framerate in ofApp.
    Laurin

    #4031

    leadedge
    Keymaster

    For receiveImage you need a buffer to receive into.

    The easiest way might be to create an RGB unsigned char buffer with malloc or new, as well as a second integer buffer that you need. Once you have the buffer pointer (say unsigned char * rgbpixels) you can receive into it with :

    if(spoutreceiver.ReceiveImage(SenderName, width, height, rgbpixels, GL_RGB)) {

    convert from unsigned char to integer here

    … etc
    }

    OK that’s interesting with the timer thread. I am not sure what is happening there. I would keep CreateReceiver in update or draw and set an initialization flag to use in the timer thread. I am not sure whether the timer thread can access that flag and you would have to look into that. Maybe the flag would need to be a static variable. I am not sure without trying some code.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.