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

Pages: [1] 2
1
Graphics / Re: Passing the sf::font to a class
« on: May 25, 2020, 04:57:13 pm »

Quote
Are you using SFML 1?
nope, but this part of the 1.6 tutorial seems to still be ok ... This part disapeared in later versions.

Quote
Global SFML resources are never a good idea. Remember I said this :P
well, i'm not sure why, but i'll do ... this sounds so mysterious to me ! do you think what i've done is a bad solution ?

Quote
Same day?

int HapaxPostDate = 15;
int MyAnswerDate = 19;
int TimeForAnswer = MyAnswerDate - HapaxPostDate;
cout << "Response Lag : " << TimeForAnswer << " days" << endl;

i should have used uint16_t ...  :P

2
Window / Re: Can't make CTRL + mouse wheel work
« on: May 24, 2020, 01:06:32 pm »
OK, thank you very much !!! i'll do that

***EDIT***
works like a charm and will be usefull in other places of the code also... many thanx

Regard,

RLF

3
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

4
Graphics / Re: Passing the sf::font to a class
« on: May 19, 2020, 11:04:44 pm »
oooh yes that's a very late answer but i coulnd not finish without thanx,

We finally found the static method in the 1.6 SFML documentation. Old stuff are sometimes good stuff. This is not far of what you proposed. What is cool in code is that there a different way to do the same things and not only one good method.

Here is what we finally did :

in the main :

Channel::Init("kimberley_bl.ttf");
 

and in the class :

static sf::Font font;

bool Channel::Init(const std::string& fontFile)
{
    return font.loadFromFile(fontFile);
}
 
Creating multiple classes is now fast as hell ...

Regards,

RLF

5
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

6
Graphics / Re: Using the Vertex Array
« on: May 14, 2020, 04:19:19 pm »
You were right again,

the vertex were drawn stacked, i used the transform method and everything is in the right place ...

i will open another thread for the last question.

7
Graphics / Re: Using the Vertex Array
« on: May 12, 2020, 11:46:37 am »
Hello,

Thanks for your answer.

This is not exact, this might be an issue with my bad english.

Each rectangle you see is a separate entity wich is drawn in a class.

The vertex array has 16 Vertex, Background (white), another over background (black) and foreground (the 2 blue rectangles). i don't use a texture, only colors for vertex because i want the colors to change dynamically.
Text is drawn after the vertex.

for the 2 screenshots, you have a vertex version (the one with only 1 rectangle and no text on it plus 9 text with no rectangle. This is the bug i don't understand.

The screenshot with the rectangles that are drawn correctly is a non vertex array version and is drawn with rectangles.

The question : Why is my vertex not repeated correctly ? it should, because it is in a class. And why is the text  not dramwn on it ? i did respect the good drawing order, text is drawn after the vertex array.

Note that if i create a single object of the class, the render is OK but i want it to be ok with multiple objects of the class.

Here is my vertex array code :

sf::Vertex vertex;
    //vertex.position = sf::Vector2f(0, 0);
    sf::VertexArray ch_quad(sf::Quads, 16);


    vertex.color = sf::Color(255, 0, 0);
    // Draws under quad supposed to be outline (draw order)
    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);
    //insert here if / else for select color change
    ch_quad[0].color = sf::Color(255, 255, 255, 50);
    ch_quad[1].color = sf::Color(255, 255, 255, 50);
    ch_quad[2].color = sf::Color(255, 255, 255, 50);
    ch_quad[3].color = sf::Color(255, 255, 255, 50);
    //draws the inside under quad ad sets the color (black)
    ch_quad[4].position = sf::Vector2f(12,12);
    ch_quad[5].position = sf::Vector2f(58,12);
    ch_quad[6].position = sf::Vector2f(58,78);
    ch_quad[7].position = sf::Vector2f(12,78);
    ch_quad[4].color = sf::Color(0, 0, 0);
    ch_quad[5].color = sf::Color(0, 0, 0);
    ch_quad[6].color = sf::Color(0, 0, 0);
    ch_quad[7].color = sf::Color(0, 0, 0);
    //draws the channel strip
    ch_quad[8].position = sf::Vector2f(12,12);
    ch_quad[9].position = sf::Vector2f(58,12);
    ch_quad[10].position = sf::Vector2f(58,27);
    ch_quad[11].position = sf::Vector2f(12,27);
    ch_quad[8].color = sf::Color(20, 30, 60);
    ch_quad[9].color = sf::Color(20, 30, 60);
    ch_quad[10].color = sf::Color(20, 30, 60);
    ch_quad[11].color = sf::Color(20, 30, 60);
    //draws the info strip
    ch_quad[12].position = sf::Vector2f(12,60);
    ch_quad[13].position = sf::Vector2f(58,60);
    ch_quad[14].position = sf::Vector2f(58,78);
    ch_quad[15].position = sf::Vector2f(12,78);
    ch_quad[12].color = sf::Color(20, 30, 60);
    ch_quad[13].color = sf::Color(20, 30, 60);
    ch_quad[14].color = sf::Color(20, 30, 60);
    ch_quad[15].color = sf::Color(20, 30, 60);

    window.draw(ch_quad);
 ch.setFont(font);
    ch.setString(std::string("ch ") + chnbr.str());
    ch.setCharacterSize(12);
    ch.setLetterSpacing(0.3);
    ch.setFillColor(sf::Color(255, 255, 255));

    ch.setPosition(x+12, y+12); // Positionnement
    window.draw(ch);
    // Level Text
    lvl.setFont(font);
    lvl.setString(std::string("") + lvlstr.str());
    lvl.setCharacterSize(18);
    lvl.setLetterSpacing(0.3);
    lvl.setFillColor(sf::Color(255, 255, 255));

    lvl.setPosition(x+14, y+28); // Positionnement
    window.draw(lvl);
}
 


Regards,

8
Graphics / Re: Using the Vertex Array
« on: May 11, 2020, 07:12:22 pm »
Ok thanks, i successfully drawn my vertex but this calls many other questions :

as i said before, the vertex is drawn in an object. Before when i was creating multiple instance of the same objects, i had my rectangles drawn for every object. Nowthat i'm using vertex array, when i draw only one object, display is fine, but when i draw multiple objects, only the first is drawn.

Also, text disapear on the first and only vertex drawn (maybe under the vertex ?).

Does it means that only one instance of the vertex array can be drawn at the same time ?

Also, i'm loading font in the class, is it an issue ? i'm wondering if the font is loaded each time the object is created ans slows global performance ? in that case should i load it externaly and use a pointer ? i know this is more C++ general coding than SFML specific, but i'm there, so ...

***EDIT***

If you look at attachements, you can see the how it is with vertex array, and the how it should be (where all is drawn fine with rectangles)

Regards





9
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 !

10
Ok,

Thank you very much for your answers ... Time for coding all of this now. All 3 neurons at max activity !

11
Thanx for your answers,

i'm very grateful that you use your time to help.

I will try to be more clear but my english is not that fantastic !

First, the project on what i am working is a software lighting console used to control lighting during a show.

i am going to create a class named channel, this is the basic entity in a lighting console, a single channel is, to be simple, dedicated to manage one projector, basically adjusting its dimming level, or controling a moving light projector, wich is a little bit more tricky.

In the class i want to create, there will be all the code used to control level of the projector, if the channel is selected, its output ect ...

i want it as an object because we don't use only 1 channel, but several. My guess is that i can have the graphics code in the class, so i can make interact graphics with status of the channel :

for example : if selected, border is white, if not border is black ...

but i'm not sure if i can do that, if i have to create a single object for graphics or if my class with all the features of the channel can contain the codes for graphics.  This is actually my main question.

The interest graphics to be in the object is that if the object have not been created, mainly because there is no projector here to be controlled, i will not display anything.

i will work on vertex array, but i think i will need to fry a few neurons with  that ... but as usual i need to experiment ...

Thx
RLF

12
Ok, actually you are really a Hero ...

I moved the windows close event in the poll.event loop and it's not crashing anymore, you had the good intuition.

Channel_job_core does keyboard input treatment like filtering numbers, buffering number and number processing cases.

The drawing will be moved into a class, i'm just testing how to right now, it will not remain in the main but will be graphics of a particular object. Not really sure if i can process like that, but there will have an object named channel wich does several things and will contain it's own graphics. This object will repeat several times, up to 2048 times. Graphics for each channel will be repeated on a grid ...

do you think i should start right now with vertex array as it seems more complex to me ? i'm not sur i have understood everything yet. !!!

do i have to make a class with only the graphics of my channels or can it be contained in a class that also processes other things, even if they are related ?

13
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;
}

 

14
Window / Re: Accessing + key with shift= (ascii code 43)
« on: May 05, 2020, 12:49:16 pm »
Really cool,

thanx, i'll try that ! Anything about locking Shift in the program ?

RLF

15
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] 2
anything