Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I can't get custom shapes to work  (Read 1702 times)

0 Members and 1 Guest are viewing this topic.

nfect

  • Newbie
  • *
  • Posts: 16
    • View Profile
I can't get custom shapes to work
« on: May 27, 2019, 05:22:54 pm »
I found some examples of roundedrectangles/elipses, yet I can't get them to work. Build is fine with no errors, yet ".draw" shows nothing :/ It's been 3 days I'm trying to get it to work, and since I'm a total newbie, it feels like I can't pin point what I'm doing wrong.

https://github.com/SFML/SFML/wiki/Source%3A-Draw-Rounded-Rectangle

here's the example I tryed, and for the elipses:

https://www.sfml-dev.org/tutorials/2.0/graphics-shape.php

With the first example, I create an hpp, and a cpp, copy and paste, create a new shape in the int main, ask to draw it, and nothing appears. I'm lost :/

I even tryed replacing the end of the code by the code from the original rectangleshape, and it works .

// this does not work, draw shows me a shape
    if(index >= myCornerPointCount*4)
        return sf::Vector2f(0,0);

    float deltaAngle = 90.0f/(myCornerPointCount-1);
    sf::Vector2f center;
    unsigned int centerIndex = index/myCornerPointCount;
    static const float pi = 3.141592654f;

    switch(centerIndex)
    {
        case 0: center.x = mySize.x - myRadius; center.y = myRadius; break;
        case 1: center.x = myRadius; center.y = myRadius; break;
        case 2: center.x = myRadius; center.y = mySize.y - myRadius; break;
        case 3: center.x = mySize.x - myRadius; center.y = mySize.y - myRadius; break;
    }

    return sf::Vector2f(myRadius*cos(deltaAngle*(index-centerIndex)*pi/180)+center.x,
                        -myRadius*sin(deltaAngle*(index-centerIndex)*pi/180)+center.y);

// this does

    switch (index)
    {
        default:
        case 0: return Vector2f(0, 0);
        case 1: return Vector2f(mySize.x, 0);
        case 2: return Vector2f(mySize.x, mySize.y);
        case 3: return Vector2f(0, mySize.y);
    }
« Last Edit: May 27, 2019, 10:34:03 pm by nfect »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: I can't get custom shapes to work
« Reply #1 on: June 02, 2019, 09:29:35 pm »
Do you still have a problem with this and if yes then can you create a minimal complete example of it?
Back to C++ gamedev with SFML in May 2023