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

Pages: [1]
1
Window / Can't make CTRL + mouse wheel work
« on: May 24, 2020, 12:51:05 pm »
Hello,

I'm sure i'm doing something stupid, i tried many combinations without success, certainly a syntax mistake but can't figure out what do do

the problem is that the
if (event.key.control)
is always true event if ctrl key is not pressed

Here is part of my code :

case sf::Event::MouseWheelMoved:
        {
            if(sf::Mouse::HorizontalWheel)
            {
                int8_t delta = event.mouseWheel.delta;
                std::cout << "wheel movement: " << delta << std::endl;
                for(uint16_t i=0; i<selected_chan.size() ;i++)
                {
                    if(ch(selected_chan[i])get_channel_number()!=0)//si le circuit a ete cree
                    {
                        uint8_t res = 0;
                        uint8_t niv = ch(selected_chan[i]) get_level();

                        if(ch(selected_chan[i])get_mode()==false)
                        {
                            if(event.key.control)
                            {
                                cout << "control" << endl;
                                res = 2.55;
                            }
                            else
                            {
                                res = scroll_resolution*2.55;
                            }

thanks by advance for your answer

2
Graphics / Passing the sf::font to a class
« on: May 14, 2020, 04:27:46 pm »
hello,

I have a performance problem with my program, i'm using a class that i use multiple (up to 2048) times. Graphics of the class are drawn in the class.

The graphics consists in a vertex array and some dynamic string text that are processed in the class. To use text, i load the font for each instance of the class, wich is not optimal. As loading 2048 times the same font is not a good idea.

What i want to do is to make the class use a font that is out of the class in order to load it only once. But, i really don't even know where to start. I tried to make the font a pointer, but could not make it work.

What can i do to load an external sf::font in a class ?

thanks by advance

RLF

3
Graphics / Using the Vertex Array
« on: May 11, 2020, 05:30:27 pm »
Hello,

I'm trying to use Vertex Array to rebuild a drawing i made with simples quads :

i'm happy with this graphics but as it is in a class and the class can be called several times (up to 2048 times), the rendering time is so long because it creates for every time the class is called 3 rectangles. On those rectangles, some dynamic text showing values wich will refreshed regularly.

Here is the current code for the 3 rectangles :

// Underground Rectangle
    sf::RectangleShape unders(sf::Vector2f(50.f, 70.f));
    unders.setFillColor(sf::Color(0 , 0, 0));
    unders.setOutlineThickness(1.f);

    if(_channel_select == true)
    unders.setOutlineColor(sf::Color(255, 255, 255));
    else
    unders.setOutlineColor(sf::Color(255, 255, 255, 50));

    unders.setPosition(x+10, y+10);
    window.draw(unders);
    // Channel strip rectangle
    sf::RectangleShape channel_strip(sf::Vector2f(50.f, 15.f));
    channel_strip.setFillColor(sf::Color(20, 30, 60));
    channel_strip.setPosition(x+10, y+10);
    window.draw(channel_strip);
    // info strip rectangle
    sf::RectangleShape info_strip(sf::Vector2f(50.f, 20.f));
    info_strip.setFillColor(sf::Color(20, 30, 60));
    info_strip.setPosition(x+10, y+60);
    window.draw(info_strip);

the 2 last rectangles are overlapping the first, then text is drawn (not shown in the code i provided).

Now i think this should be drawn in a vertex array, but with examples of the library, i'm not sure of what to do.

i understood i can draw multiple rectangle in on array and found how to do. But how can i assign different colors to the different Quads of the array, or at least, is it possible to do this.

For the time beeing, i just draw the first rectangle in the array an can't figure out how to change its color, except with setteing color of each vertex but  i want a plain color and it is blended.

Here is my first part of code for the array :

 sf::Vertex vertex;
   
    sf::VertexArray ch_quad(sf::Quads, 4);


    vertex.color = sf::Color(255, 255, 255, 50); // the color is not shawn, the Quad remains black
    ch_quad[0].position = sf::Vector2f(10, 10);
    ch_quad[1].position = sf::Vector2f(60, 10);
    ch_quad[2].position = sf::Vector2f(60, 80);
    ch_quad[3].position = sf::Vector2f(10, 80);

    window.draw(ch_quad);


To be clear, here are my questions : Is it possible to assigne multiple plain color do different quad in the same vertex array and how, is what i'm trying to do is what i should do (using vertex array instead or rectangles), will i gain render time if i do so ? and if not, how can i gain render time ?

Thanks by advance for your answers !

4
Graphics / First drawing, the program crash after the 3rd rectangle
« on: May 06, 2020, 01:35:07 pm »
Hello, i'm exercising with drawing in SFML ...

I successfully drawn 2 rectangles that overlap.

What i want to do is a space here i can finally draw text (channel space for a lighting software)

i'm a first rectangle with borders, then another rectangle inside the first one, then another rectangle inside also.

The 2 first rectangles are OK, and the program runs, when i add the third rectangle in the code, the program crash immediatly. This drawing will result in a class later, but right now, i'm juste trying to draw things to see what i can do.

I'm not sure i'm doing the good thing to create what i want to do and if there is another best method for this, please tell me, i'm so new in using graphic libraries and kind of programming rookie who really want to learn to do the good things.

Wondering why is it crashing ?

Thx by advance.

Here is my code :

#include <SFML/Graphics.hpp>
#include <iostream>
#include "fonctionsdetexte.h"

using namespace std;

int main()
{
    sf::RenderWindow window(sf::VideoMode(800,600), "voici une fenêtre");
    window.setVerticalSyncEnabled(true);
    sf::Event event;
    sf::Font font;
    sf::Text text;
    sf::Vertex vertex;
if (!font.loadFromFile("OCRA_0.ttf"))
{
    cout << "font not loaded" << endl;
}

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

        while (window.pollEvent(event))
            {
            channel_job_core(event);
            }

    window.clear(sf::Color::Black);

    sf::RectangleShape unders(sf::Vector2f(50.f, 70.f));
    unders.setFillColor(sf::Color(0 , 0, 255));
    unders.setOutlineThickness(2.f);
    unders.setOutlineColor(sf::Color(255, 255, 255));
    unders.setPosition(10, 10);
    window.draw(unders);
    sf::RectangleShape channel_strip(sf::Vector2f(50.f, 20.f));
    channel_strip.setFillColor(sf::Color(255, 0, 0));
    channel_strip.setPosition(10, 10);
    window.draw(channel_strip);
    // RectangleShape 'info_strip' make the program crashes,
    // if commented, the program works and display the 2 first rectangle
    sf::RectangleShape info_strip(sf::Vector2f(50.f, 20.f));
    info_strip.setFillColor(sf::Color(255, 0, 0));
    info_strip.setPosition(10, 35);
    window.draw(info_strip);

    /*text.setFont(font);
    text.setString("wildcat");
    text.setCharacterSize(54);
    text.setFillColor(sf::Color::Red);
    text.setStyle(sf::Text::Bold | sf::Text::Underlined);
    window.draw(text);*/



    window.display();
    }

return 0;
}

 

5
Window / Accessing + key with shift= (ascii code 43)
« on: May 04, 2020, 04:47:27 pm »
Hello,

i tried to post on french forum but it seems that's it is not moving much there.

First, i'm a rookie in sfml and in C++

i successfully set up a event chain and some key are triggering properly what i want. For this program, i need to use + key using the shift= key but this key is not triggering sf::Keyboard::Add

Is there an alternative way of triggering this key or is it just not implemented ? if not, will it be one day ?

Subsidiary question. Is it possible to lock the shift key directly in the program because my program will be executed mostly on laptops that may no have a numpad and almost everything will have to deal with numbers. So the access will be direct on numbers instead of "&é"'(-è_çà".

Thanx by advance for your answers.

RLF

Pages: [1]
anything