Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Capture image data from portion of the screen?  (Read 17910 times)

0 Members and 1 Guest are viewing this topic.

Pheonix

  • Newbie
  • *
  • Posts: 27
  • Using SFML 2.1 with Win/Visual C++ (Newbie !!!)
    • View Profile
Re: Capture image data from portion of the screen?
« Reply #30 on: February 07, 2014, 01:00:28 am »
By streaming I mean just constantly executing the capture code over and over again, which is just GDI capture then loading the data into SFML for drawing.

Anyway, today I'm gonna get working on that vecor/update method and get back to you guys on how it went.

EDIT: I can't get texture update to work  :(
I'm just trying to test out how to update one pixel to get an idea of how to do it.

        sf::Texture myTexture;
        myTexture.create(1,1);

        std::vector<sf::Uint8> myVector;

        myVector.push_back(255); // RED
        myVector.push_back(0); // GREEN
        myVector.push_back(0); // BLUE
        myVector.push_back(0); // ALPHA

        myTexture.update(myVector);

 :-\

Also, should I be using push_back for this??

EDIT: I managed to get arrays to work, but not vectors. Why should I use vectors? (won't it be faster to use arrays - or were you thinking that I would be changing the size of the capture?)

        sf::Texture myTexture;
        myTexture.create(1,1);

        sf::Uint8 myArray[] = {255,0,0,255};

        myTexture.update(myArray);
« Last Edit: February 07, 2014, 05:12:21 am by Pheonix »
Using SFML 2.1 with Win/Visual C++ (Newbie !!!)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Capture image data from portion of the screen?
« Reply #31 on: February 07, 2014, 07:47:53 am »
Use std::vector to be safe on the memory management side (even if the size is constant, you won't be able to declare an array of this size on the stack). It won't be slower if you use it correctly (avoid dynamic allocations after init).

std::vector<sf::Uint8> pixels(width * height * 4);

pixels[(x + y * width) * 4 + 0] = r;
pixels[(x + y * width) * 4 + 1] = g;
pixels[(x + y * width) * 4 + 2] = b;
pixels[(x + y * width) * 4 + 3] = a;

texture.update(&pixels[0]);
Laurent Gomila - SFML developer

Pheonix

  • Newbie
  • *
  • Posts: 27
  • Using SFML 2.1 with Win/Visual C++ (Newbie !!!)
    • View Profile
Re: Capture image data from portion of the screen?
« Reply #32 on: February 07, 2014, 09:39:27 am »
80FPS!!!



I guess that solves my problem.  :)
Thanks very much everyone for your help. I strongly appreciate it.  :-*

Especially a big thanks to Grimshaw who took the time to write most of the Win code.  ;)



« Last Edit: February 07, 2014, 10:18:17 am by Pheonix »
Using SFML 2.1 with Win/Visual C++ (Newbie !!!)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Capture image data from portion of the screen?
« Reply #33 on: February 07, 2014, 10:42:48 am »
Would be nice if you could put the final code somewhere (wiki/your GitHub/etc). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything