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

Pages: [1] 2
1
General / Re: Capture image data from portion of the screen?
« 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.  ;)




2
General / Re: Capture image data from portion of the screen?
« 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);

3
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 11:39:54 am »
To get maximum performances you should do the pixel conversions into your own array (std::vector<sf::Uint8>) and then use Texture::update. In other words, drop sf::Image, which is not suitable for realtime image manipulation.

Do you mean create my own array, then pass a pointer to the texture update function? Is the formatting top left to bottom right? RGBARGBARGBA? What if I don't need alpha channel?

Quote
Drop to or by?
Drop to. (Yes, I know it's a very significant drop from 1,300!)

4
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 10:46:13 am »
In other words, instead of loading image into texture, actually write the pixel info directly into the already existing texture?

I don't see why it wouldn't be possible... Surely the texture is made up of pixel information..? Just need to find the address in memory and write it in.

EDIT: There's two lines that severely drop the FPS (from a base of 1,300 FPS)

(When commenting out all other code in the loop...)

Drop to about 30FPS
BitBlt(hMemoryDC, 0, 0, x, y, hScreenDC, 0, 0, SRCCOPY);

Drop to about 65FPS
captureImage.setPixel(x,y, sf::Color(GetBValue(thisColor), GetGValue(thisColor), GetRValue(thisColor)));
(this one is in two for loops scanning every pixel)

Drop to about 250FPS
captureTexture.loadFromImage(captureImage);


EDIT: I managed to increase the FPS of the streaming from 15FPS to about 40FPS by disabling the Windows Aero theme!? I suppose this means bitblt has less work to do. But I still must use bitblt otherwise it won't work.

5
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 10:35:38 am »
Why does it slow down? For example...

If I disable updating the texture, I get 30FPS then gradually decreases to about 20FPS
If I enable updating the texture, I get 20FPS > 15FPS.

I think perhaps the way I am streaming it is wrong? (FPS should be stable IMO)
Also, updating the texture seems to drop FPS by 5-10FPS. Maybe there's an alternative? Can I set the texture to some kind of dynamic/streaming mode?

(and yes, this is in 'Release' mode.)

6
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 09:20:48 am »
YAY I got it streaming!!!!!!

Could you please explain how the code works?

EDIT: Updated code. Actually runs better now. Still a tiny bit choppy, but I'm not sure if that's a code problem or maybe I'm maxing out my computer (the capture is after all 1600x900).

Seems like there's many lines of code that I don't need in the stream. Here's my stream code:
/////////// OUR LOOP TO STREAM ///////////////////////////////
                BitBlt(hMemoryDC, 0, 0, x, y, hScreenDC, 0, 0, SRCCOPY);
                GetDIBits( hMemoryDC , hBitmap , 0 , bm.bmHeight , pixel , &bmpInfo , DIB_RGB_COLORS );

                j = 0;
                for(y = 0; y < bm.bmHeight; ++y){
                        for(x = 0; x < bm.bmWidth; ++x){
                                COLORREF thisColor = pixel[j++];
                                captureImage.setPixel(x,y, sf::Color(GetBValue(thisColor), GetGValue(thisColor), GetRValue(thisColor)));
                        }
                }

                captureTexture.loadFromImage(captureImage);
                //////////////////////////////////////////////////////////////

EDIT: Checked the frame-rate, I get about 15FPS. I was hoping to get at least 30-60FPS. Does anyone have any suggestions in how I could speed it up?

7
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 08:55:36 am »
YAAAY!  :D Thanks very much Grimshaw  :-* :-* :-*

It works on mine too! Now I just have to get it streaming - though I should hopefully be able to figure that one out on my own.

I do wonder however how efficient it is to load bitmap into an image, then load the image into a texture, then load the texture into a sprite before drawing? (not saying it's wrong... but is this okay?)

8
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 07:11:07 am »
It's okay, I don't want anyone to be unhappy here.  :-*

Maybe I should have pointed out that I am building my first C++ application (if I exclude 'cout << Hello world' and 'SFML Works!'). ;D

It's not that I want people to do everything for me and I just lay back. I would just like someone to explain in layman terms how to do things so I can both get the job done as well as understand what I've done.

9
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 06:56:10 am »
I'm sure you are like some people, very good at reading APIs and Wikipedia articles, even if its about things you know nothing about. Not everyone is like you. Most of the time when I read APIs I get completely lost and have no idea what they're on about.

If I had a bit more knowledge in these things maybe it would be easier...

Anyway, it's hardly my fault it's so damn difficult! That you need to type so much code, read so much documentation to do something this simple... And then when you finally have a 'bitmap' stored in memory you still can't use it, because it's a different type of 'bitmap'...  >:(

10
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 06:39:15 am »
You misinterpreted/exaggerated what I was trying to say. Don't take it personally.   ::)

What I meant to say was that I asked some people who understand what I'm trying to do for the Windows part and then update my thread here... (so if the code changed you didn't think I was just randomly changing stuff - for the windows part, anyway)

This is an SFML forum after all, I can't expect anyone here to know Windows stuff, let alone specifically what I'm trying to do. It's hard to find people who know both SFML and Windows to a high degree, and I cannot figure out the Windows stuff out on my own since it's completely new to me.

11
General / Re: Capture image data from portion of the screen?
« on: February 06, 2014, 06:26:40 am »
Here is an update of the code with some help from other people in other forums who know a bit more about windows functions.

#include <Windows.h>
#include <SFML/Graphics.hpp>

int main()
{
        // (1) get the device context of the screen
        // Definition: The CreateDC function creates a device context (DC)
        //      ..for a device using the specified name.
        HDC hScreenDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);  

        // (2) and a device context to put it in
        // Definition: The CreateCompatibleDC function creates a memory
        //      ..device context (DC) compatible with the specified device.
        HDC hMemoryDC = CreateCompatibleDC(hScreenDC);

        // (3) Gets the users screen size in x and y dimensions
        // Definition: The GetDeviceCaps function retrieves device-specific
        //      ..information for the specified device.
        int x = GetDeviceCaps(hScreenDC, HORZRES);
        int y = GetDeviceCaps(hScreenDC, VERTRES);

        // (4) maybe worth checking these are positive values
        // Definition: The CreateCompatibleBitmap function creates a bitmap
        //      ..compatible with the device that is associated with the specified
        //      ..device context.
        HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, x, y);

        // (5) get a new bitmap
        // Definition: The SelectObject function selects an object into the
        //      ..specified device context (DC). The new object replaces the previous
        //      ..object of the same type.
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);

        // Definition: The BitBlt function performs a bit-block transfer of the
        //      ..color data corresponding to a rectangle of pixels from the specified
        //      ..source device context into a destination device context.
        BitBlt(hMemoryDC, 0, 0, x, y, hScreenDC, 0, 0, SRCCOPY);


        // Don't need this apparently
        //hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);

        //////////////////////////////////////////////////////////////////////////////////

        // Create the SFML Window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");

        // Load the bitmap from memory into texture
        sf::Texture Texture;
        Texture.loadFromMemory(hOldBitmap,sizeof(hOldBitmap));

        // Load the texture into a sprite
        sf::Sprite Sprite;
        Sprite.setTexture(Texture);

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

        window.clear();
                window.draw(Sprite);
        window.display();
    }

        // clean up
        DeleteDC(hMemoryDC);
        DeleteDC(hScreenDC);

    return 0;
}
 

Still crashes however when run... Though I think it is an SFML issue. However, I'm not confident that the Windows part is completely right either..

12
General / Re: Capture image data from portion of the screen?
« on: February 05, 2014, 01:25:28 pm »
Yeah, I already saw that one. I cannot get the code to build however.

13
General / Re: slow reaction to mouse event
« on: February 05, 2014, 07:09:37 am »
Try and see if there is an alternative to using Event for mouse moved/position similar to my previous example.

14
General / Re: slow reaction to mouse event
« on: February 05, 2014, 06:55:21 am »
I'm a newbie to SFML, but I think it may be because you're using Event which is slower.

Try something like: if(sf::Mouse::isButtonPressed(sf::Mouse::Left))

15
General / Re: Capture image data from portion of the screen?
« on: February 05, 2014, 06:34:44 am »
 :'(

Is there anyone experience in this that can make a working code? I have looked at almost a dozen codes through google and haven't found anything that works, let alone integrate it into SFML.

Pages: [1] 2