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.


Topics - Tima32

Pages: [1]
1
Window / WinEvent
« on: July 11, 2021, 01:50:44 am »
Is there a way to get windows events other than using the SetWinEventHook function?

2
Window / My app is not receiving touch events.
« on: June 04, 2021, 10:18:08 pm »
My application is not receiving touch events.
The touchscreen works well, tested in Chrome.
cout << "E: " << event_e.type << endl;
if (event_e.type == Event::TouchBegan)
{
        cout << event_e.touch.finger << endl;
}
 
What could I have missed?
SFML 2.5.1
Windows 10
Visual Studio 19

3
General / GPU info
« on: May 26, 2020, 04:46:07 pm »
How to get information from video memory and GPU load?

4
Graphics / Memory leak when loading textures in multi-thread
« on: October 15, 2018, 12:07:59 am »
There is a memory leak:
void _1()
{
        Texture t_up;
        t_up.loadFromFile(String(L"GUI\\Textures\\Up.png"));
}

while (1)
        {
                Thread t(&_1);
                t.launch();
                t.wait();
        }
 

No memory leaks:
void _1()
{
        Texture t_up;
        t_up.loadFromFile(String(L"GUI\\Textures\\Up.png"));
}

while (1)
        {
                _1();
        }

How to load textures in a multi-thread and not get memory leaks?
SFML 2.5.0 Visual Studio 15

5
Graphics / problems with view
« on: July 23, 2018, 12:26:21 pm »
I make a window that can be moved with the mouse, but when it is at the right or bottom side of the window it disappears. What am I doing wrong?
View save_view = parent_window->getView();

        RectangleShape background;
        background.setPosition(0, 0);
        background.setSize(Vector2f(width, height));
        background.setFillColor(fon_color);
        background.setOutlineThickness(outlain_size);
        background.setOutlineColor(border_color);

        RectangleShape handl;
        handl.setPosition(-outlain_size, -header_height);
        handl.setSize(Vector2f(width + outlain_size*2, header_height));
        handl.setFillColor(border_color);
       
        View view = parent_window->getView();
        view.setCenter(parent_window->getSize().x / 2 - x, parent_window->getSize().y / 2 - y);
        parent_window->setView(view);
        parent_window->draw(background);
        parent_window->draw(handl);
        parent_window->setView(save_view);

6
Graphics / How to make pixel shadows?
« on: June 04, 2018, 06:19:34 pm »
I want to make similar shadows in my game, but I do not know how.

I'll take the library, the article, whatever.

7
Graphics / button error
« on: February 10, 2018, 08:26:50 pm »
I can not understand the reason for the error.

Unhandled exception at 0x000007FED080264D (sfml-graphics-2.dll) in Test.exe: 0xC0000005: violation of access rights when reading at 0x0000000000000000.

Video:

Project:
https://drive.google.com/file/d/15NDtyPFyfFMrHVf64q3HNxGbd4psblGR/view?usp=sharing


For those who do not want to download the project.
main.cpp:
#include "SFML/Graphics.hpp"
#include <iostream>
#include <windows.h>
#include <list>
#include <thread>

#include "Button.h"

using namespace std;
using namespace sf;

Font font;

void m2()
{
        RenderWindow MainWindow;
        MainWindow.create(VideoMode(640,480), L"Test");
        //window.setVerticalSyncEnabled(true);
        MainWindow.setFramerateLimit(60);//&#1082;&#1086;&#1083;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1082;&#1072;&#1076;&#1088;&#1086;&#1074; &#1074; &#1089;&#1077;&#1082;&#1091;&#1085;&#1076;&#1091;

        //Button button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 50, 50, 11);
        Button *button = new Button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 5, 5, 11);
        Button *button2 = new Button(L"LOL", font, 60, 5, 20);

        while(MainWindow.isOpen())
        {
                Vector2i pixelPos = Mouse::getPosition(MainWindow);//&#1079;&#1072;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1082;&#1086;&#1086;&#1088;&#1076; &#1082;&#1091;&#1088;&#1089;&#1086;&#1088;&#1072;
                Vector2f pos = MainWindow.mapPixelToCoords(pixelPos);//&#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1080;&#1084; &#1080;&#1093; &#1074; &#1080;&#1075;&#1088;&#1086;&#1074;&#1099;&#1077; (&#1091;&#1093;&#1086;&#1076;&#1080;&#1084; &#1086;&#1090; &#1082;&#1086;&#1086;&#1088;&#1076; &#1086;&#1082;&#1085;&#1072;)
               
                Event event;
                while(MainWindow.pollEvent(event))
                {
                        //&#1077;&#1089;&#1083;&#1080; &#1084;&#1099; &#1085;&#1072;&#1078;&#1084;&#1077;&#1084; &#1085;&#1072; &#1082;&#1085;&#1086;&#1087;&#1082;&#1091; &#1079;&#1072;&#1082;&#1088;&#1099;&#1090;&#1100;
                        if(event.type == Event::Closed)
                                MainWindow.close();

                        //&#1053;&#1072;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        while(true)
                        {
                                if(button->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                if(button2->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                break;
                        }

                        //&#1054;&#1090;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        {
                                button->released();
                                button2->released();
                        }

                        //&#1050;&#1083;&#1080;&#1082; &#1084;&#1099;&#1096;&#1080;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left)
                        do{
                                if(button->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 1" << endl; button2->setText(L"EEE!!");break;}
                                if(button2->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 2" << endl; button2->setText(L"Long long text on button2");break;}
                        }while(0);

                        //&#1055;&#1088;&#1072;&#1074;&#1099;&#1081; &#1082;&#1083;&#1080;&#1082;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Right)
                        {
                        }
                }

                MainWindow.clear(Color(45, 45, 48));
                bool tr = 1;
                button->draw(MainWindow, pos.x, pos.y, &tr);
                button2->draw(MainWindow, pos.x, pos.y, &tr);
                MainWindow.display();
        }

        delete button;
        delete button2;

        return;
}

int main()
{
        SetConsoleCP(1251);// &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1082;&#1072; &#1082;&#1086;&#1076;&#1086;&#1074;&#1086;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099; win-cp 1251 &#1074; &#1087;&#1086;&#1090;&#1086;&#1082; &#1074;&#1074;&#1086;&#1076;&#1072;
    SetConsoleOutputCP(1251); // &#1091;&#1089;&#1090;&#1072;&#1085;&#1086;&#1074;&#1082;&#1072; &#1082;&#1086;&#1076;&#1086;&#1074;&#1086;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099; win-cp 1251 &#1074; &#1087;&#1086;&#1090;&#1086;&#1082; &#1074;&#1099;&#1074;&#1086;&#1076;&#1072;

        font.loadFromFile("tahoma.ttf");

        thread func_thread(m2);
        //Sleep(5000);

        RenderWindow MainWindow;
        MainWindow.create(VideoMode(640,480), L"Test");
        //window.setVerticalSyncEnabled(true);
        MainWindow.setFramerateLimit(60);//&#1082;&#1086;&#1083;&#1083;&#1080;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086; &#1082;&#1072;&#1076;&#1088;&#1086;&#1074; &#1074; &#1089;&#1077;&#1082;&#1091;&#1085;&#1076;&#1091;

        //Button button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 50, 50, 11);
        Button *button = new Button(L"&#1050;&#1085;&#1086;&#1087;&#1082;&#1072;", font, 5, 5, 11);
        Button *button2 = new Button(L"EEE!!", font, 60, 5, 20);

        while(MainWindow.isOpen())
        {
                Vector2i pixelPos = Mouse::getPosition(MainWindow);//&#1079;&#1072;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1082;&#1086;&#1086;&#1088;&#1076; &#1082;&#1091;&#1088;&#1089;&#1086;&#1088;&#1072;
                Vector2f pos = MainWindow.mapPixelToCoords(pixelPos);//&#1087;&#1077;&#1088;&#1077;&#1074;&#1086;&#1076;&#1080;&#1084; &#1080;&#1093; &#1074; &#1080;&#1075;&#1088;&#1086;&#1074;&#1099;&#1077; (&#1091;&#1093;&#1086;&#1076;&#1080;&#1084; &#1086;&#1090; &#1082;&#1086;&#1086;&#1088;&#1076; &#1086;&#1082;&#1085;&#1072;)
               
                Event event;
                while(MainWindow.pollEvent(event))
                {
                        //&#1077;&#1089;&#1083;&#1080; &#1084;&#1099; &#1085;&#1072;&#1078;&#1084;&#1077;&#1084; &#1085;&#1072; &#1082;&#1085;&#1086;&#1087;&#1082;&#1091; &#1079;&#1072;&#1082;&#1088;&#1099;&#1090;&#1100;
                        if(event.type == Event::Closed)
                                MainWindow.close();

                        //&#1053;&#1072;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonPressed && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        while(true)
                        {
                                if(button->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                if(button2->pressed(event.mouseButton.x, event.mouseButton.y))
                                {break;}
                                break;
                        }

                        //&#1054;&#1090;&#1078;&#1072;&#1090;&#1080;&#1077;
                        if (event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left)//&#1077;&#1089;&#1083;&#1080; &#1085;&#1072;&#1078;&#1072;&#1090;&#1072; &#1082;&#1083;&#1072;&#1074;&#1080;&#1096;&#1072; &#1084;&#1099;&#1096;&#1080;
                        {
                                button->released();
                                button2->released();
                        }

                        //&#1050;&#1083;&#1080;&#1082; &#1084;&#1099;&#1096;&#1080;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Left)
                        do{
                                if(button->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 1" << endl; button2->setText(L"EEE!!");break;}
                                if(button2->click(event.mouseButton.x, event.mouseButton.y))
                                {cout << "&#1050;&#1085;&#1086;&#1087;&#1082;&#1072; 2" << endl; button2->setText(L"Long long text on button2");break;}
                        }while(0);

                        //&#1055;&#1088;&#1072;&#1074;&#1099;&#1081; &#1082;&#1083;&#1080;&#1082;
                        if (event.type == event.MouseButtonReleased && event.mouseButton.button == Mouse::Right)
                        {
                        }
                }

                MainWindow.clear(Color(45, 45, 48));
                bool tr = 1;
                button->draw(MainWindow, pos.x, pos.y, &tr);
                button2->draw(MainWindow, pos.x, pos.y, &tr);
                MainWindow.display();
        }

        delete button;
        delete button2;

        return 0;
}

Button.h:
#pragma once
#include "SFML/Graphics.hpp"
#include <iostream>
using namespace sf;
using namespace std;

class Button
{
public:
        Button(wchar_t *PText, Font &font, float x, float y, int CharacterSize);
        ~Button();
        void draw(RenderWindow &window, int x, int y, bool *tr);
        void setPosition(float x, float y);
        void setText(wchar_t *PText);
        void setTextColor(Color &color);
        void setColor(Color &color);
        void setGuidanceColor(Color &color);
        void setPressColor(Color &color);
        void setCharacterSize(int CharacterSize);
        bool pressed(int x, int y);
        void released();
        bool released(int x, int y);
        bool click(int x, int y);

private:
        Text *text;
        RectangleShape *Rectangle;
        Color *CStandart;
        Color *GuidanceColor;
        Color *PressedColor;
        int *positionX;
        int *positionY;
        float *width;
        float *height;
        bool *Pressed;

        bool activityZoneCheck(int x, int y);
};

Button.cpp:
#include "Button.h"


Button::Button(wchar_t *PText, Font &font, float x = 0, float y = 0, int CharacterSize = 11)
{
        Rectangle = new RectangleShape;
        text = new Text;
        CStandart = new Color(Color(45, 45, 48));
        GuidanceColor = new Color(Color(62, 62, 64));
        PressedColor = new Color(27, 27, 28);
        positionX = new int(x);
        positionY = new int(y);
        width = new float(0);
        height = new float(16);
        Pressed = new bool(0);

        //Rectangle->setPosition(x,y);
        Rectangle->setFillColor(*CStandart);

        text->setString(PText);
        text->setFont(font);
        text->setCharacterSize(CharacterSize);
        text->setColor(Color(255, 255, 255));

        setPosition(x, y);
}
Button::~Button()
{
        delete text;
        delete Rectangle;
        delete CStandart;
        delete GuidanceColor;
        delete PressedColor;
        delete positionX;
        delete positionY;
        delete width;
        delete height;
        delete Pressed;
}
void Button::draw(RenderWindow &window, int x, int y, bool *tr)
{
        if(*tr && activityZoneCheck(x, y) && !*Pressed)
        {
                Rectangle->setFillColor(*GuidanceColor);
                *tr = 0;
        }
        else if(!*Pressed)
                Rectangle->setFillColor(*CStandart);


        window.draw(*Rectangle);
        window.draw(*text);
}
void Button::setPosition(float x, float y)
{
        *positionX = x;
        *positionY = y;
        Rectangle->setPosition(x,y);
        FloatRect Bounding_Rectangle(text->getLocalBounds());
        text->setPosition(x+4,y);

        *width = (Bounding_Rectangle.width + 8) * 1.02;
        *height = (Bounding_Rectangle.height + 4)*1.35;

        Rectangle->setSize(Vector2f(*width, *height));
}
void Button::setText(wchar_t *PText)
{
        text->setString(PText);
        setPosition(*positionX, *positionY);
}
void Button::setTextColor(Color &color)
{
        text->setColor(color);
}
void Button::setColor(Color &color)
{
        *CStandart = color;
}
void Button::setGuidanceColor(Color &color)
{
        *GuidanceColor = color;
}
void Button::setPressColor(Color &color)
{
        *PressedColor = color;
}
void Button::setCharacterSize(int CharacterSize)
{
        text->setCharacterSize(CharacterSize);
        setPosition(*positionX, *positionY);
}
bool Button::pressed(int x, int y)
{
        if(activityZoneCheck(x, y))
        {
                Rectangle->setFillColor(*PressedColor);
                *Pressed = 1;
                return 1;
        }
        return 0;
}
void Button::released()
{
        Rectangle->setFillColor(*CStandart);
        *Pressed = 0;
}
bool Button::released(int x, int y)
{
        if(activityZoneCheck(x, y))
        {
                Rectangle->setFillColor(*CStandart);
                *Pressed = 0;
                return 1;
        }
        return 0;
}
bool Button::click(int x, int y)
{
        return activityZoneCheck(x, y);
}
//pivate:
bool Button::activityZoneCheck(int x, int y)
{
        if(x >= *positionX && x <= *positionX+*width && y >= *positionY && y <= *positionY+*height)
                return true;
        else
                return false;
}

8
Graphics / Text Box
« on: January 31, 2018, 02:43:41 pm »
Good day!
I'm writing my TextBox so that the text does not go beyond the window, I use
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, getSize().x, getSize().y);
window.draw(text);
glDisable(GL_SCISSOR_TEST);
But how do I use it if I have more than one window?

9
Graphics / Memory leak when using text.getLocalBounds ()
« on: January 10, 2018, 07:19:51 pm »
при использовании "text[*Number_of_lines].getLocalBounds()" происходит утечка памяти, в чем может быть причина?
Constructor:
ContextMenu::ContextMenu(Font &_font, int x, int y)
{
        Background = new RectangleShape;
        Highlighted_field = new RectangleShape;
        CStandart = new Color(27, 27, 28);
        GuidanceColor = new Color(45, 45, 48);
        Number_of_lines = new short int(0);
        text = (Text*) malloc (0 * sizeof (Text));
        font = new Font(_font);
        positionX = new int(x);
        positionY = new int(y);
        width = new float(0);
        height = new float(1);
        Visible = new bool(1);

        Background->setPosition(x, y);
        Background->setFillColor(*CStandart);

        Highlighted_field->setFillColor(Color(45, 45, 48));
        Highlighted_field->setPosition(x+1, y+1);
}
Destructor:
delete Background;
        delete Highlighted_field;
        delete CStandart;
        delete GuidanceColor;

        for (int i = 0; i < *Number_of_lines; i++)
        {
                text[i].~Text();
        }
        free(text);
        //operator delete[] (text);
        delete Number_of_lines;

        delete font;
        delete positionX;
        delete positionY;
        delete width;
        delete height;
        delete Visible;
Function with memory leak:
text = (Text*) realloc (text, (*Number_of_lines + 1) *  sizeof (Text));
        new (text + *Number_of_lines) Text;

        text[*Number_of_lines].setString(PText);
        text[*Number_of_lines].setFont(*font);
        text[*Number_of_lines].setCharacterSize(11);
        text[*Number_of_lines].setColor(Color(255, 255, 255));
        text[*Number_of_lines].setPosition(*positionX + 4, *positionY + 15 * *Number_of_lines);

        //*height = *height + 15;

        //There is a memory leak!
        FloatRect *Bounding_Rectangle = new FloatRect(text[*Number_of_lines].getLocalBounds());
        cout << Bounding_Rectangle->width << ", " << Bounding_Rectangle->height <<endl;
        //int temp_width = (Bounding_Rectangle->width + 8) * 1.02;
        //if(*width < temp_width)
        //{
        //      *width = temp_width;
        //}
        //Background->setSize(Vector2f(*width, *height + 1));//"+1"&#1088;&#1072;&#1084;&#1082;&#1072;
        delete Bounding_Rectangle;

        //Highlighted_field->setSize(Vector2f(*width - 2, 15));

        //*Number_of_lines = *Number_of_lines + 1;
        return *Number_of_lines;
Finally, a class call:
while(1)
        {
                ContextMenu *Menu_test = new ContextMenu(font, 50, 60);
                Menu_test->addString(L"Test");
                delete Menu_test;
        }

Pages: [1]