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

Pages: [1]
1
Graphics / Draw items from queue/stack
« on: February 28, 2015, 05:41:16 am »
What I am trying to do, is have the ability to draw shapes from outside threads that get stored, drawn in the event loop, cleared, and rinse and repeat. I was thinking of using a stack, but I am getting errors left and right when I try to define my type as sf::Drawable.

Here is my main.cpp code:

// Render thread
void RenderThread()
{
        gRender.EventLoop(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
}

int main()
{
        ...

        HANDLE hRenderThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)RenderThread, 0, 0, 0);
        SetThreadPriority(hRenderThread, THREAD_PRIORITY_HIGHEST);

        ...
}

Here is my CRender class:

#pragma once

// Includes
#include <Windows.h>
#include <stdio.h>
#include <stack>
#include <SFML/Graphics.hpp>

// CRender Class
class CRender
{

private:

        //
        // Variables
        //

        sf::RenderWindow m_hWindow;
        //std::stack<sf::Drawable> s;


public:

        //
        // Variables
        //

        //
        // Methods
        //

        // Event loop
        void EventLoop(int width, int height)
        {
                m_hWindow.create(FindWindow(NULL, "Untitled - Notepad"));

                // Make transparent
                HWND hwnd = m_hWindow.getSystemHandle();
                SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);


                // Keep running as long as window is open
                while (m_hWindow.isOpen())
                {
                        // check all the window's events that were triggered since the last iteration of the loop
                        sf::Event event;
                        while (m_hWindow.pollEvent(event))
                        {
                                // "close requested" event: we close the window
                                if (event.type == sf::Event::Closed)
                                        m_hWindow.close();
                        }

                        m_hWindow.clear();

                        //for (int i = 0; !s.empty(); ++i, s.pop())
                        //{
                                // Broken
                                //sf::Drawable toDraw = (sf::Drawable *) s.pop();
                        //}

                        m_hWindow.display();
                }
        }

        void DrawBox(int x, int y, sf::Color color, int size, int thickness)
        {
                // Build the box
                sf::RectangleShape box;

                // Set transparent
                box.setFillColor(sf::Color::Transparent);

                // Set thickness
                box.setOutlineThickness(thickness);

                // Set origin
                sf::Vector2f origin((x - size / 2), (y - size / 2));
                box.setOrigin(origin);

                // Set color
                box.setOutlineColor(color);

                sf::Vector2f bsize((x + size / 2), (y + size / 2));
                box.setSize(bsize);

                //s.push(box);
        }
};

extern CRender gRender;

Few comments:
- Yes, I am testing using Notepad...
- For some reason, transparency isint working. I am trying to make the window completley transparent and only show what is being drawn on top of Notepad.
- I have multiple threads that will call DrawBox() which is why I am trying to queue/store the draw shapes.

I am brand new to SFML so any help would be appreciated.

Thanks.

Pages: [1]
anything