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

Author Topic: custom shape type not appear in window  (Read 2507 times)

0 Members and 1 Guest are viewing this topic.

Dyavolski_most

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
custom shape type not appear in window
« on: January 06, 2015, 02:23:44 pm »
Hi. Just started programming. I have gone from c++ to winapi and now SFML
In the 2.2 tutorial for Shapes
Working through the tutorials one by one
 
http://www.sfml-dev.org/tutorials/2.2/graphics-shape.php

For bottom section about Custom shape type

My code manages to compile, but the shape isn't appearing

I thought maybe i was missing
window.draw()
because i did forget a few times during other parts
but I can't figure out what goes into the parentheses here

Any help is much appreciated 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: custom shape type not appear in window
« Reply #1 on: January 06, 2015, 02:30:43 pm »
Is your graphics driver uptodate?

Can you provide a minimal and complete example?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: custom shape type not appear in window
« Reply #2 on: January 06, 2015, 08:19:35 pm »
In addition to what exploiter said.

window.draw()
...
but I can't figure out what goes into the parentheses here

The tutorials probably cover this somewhere, but if you're ever unsure or want more details, that's what API documentation is for.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: custom shape type not appear in window
« Reply #3 on: January 07, 2015, 12:50:24 am »
As Ixrec said, the tutorials cover this, even in the one you linked.
It's here.

It's just the shape object that you created;

EDIT: You know there's something wrong when you accidentally finish a sentence with a semi-colon.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Dyavolski_most

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: custom shape type not appear in window
« Reply #4 on: January 07, 2015, 08:53:55 am »
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "This is the title");


class EllipseShape : public sf::Shape
{
public :
    explicit EllipseShape(const sf::Vector2f& radius = sf::Vector2f(0, 0)) : m_radius(radius)
    {
        update();
    }

    void setRadius(const sf::Vector2f& radius)
    {
        m_radius = radius;
        update();
    }

    const sf::Vector2f& getRadius() const
    {
        return m_radius;
    }

    virtual unsigned int getPointCount() const
    {
        return 30; // fixed, but could be an attribute of the class if needed
    }

    virtual sf::Vector2f getPoint(unsigned int index) const
    {
        static const float pi = 3.141592654f;

        float angle = index * 2 * pi / getPointCount() - pi / 2;
        float x = std::cos(angle) * m_radius.x;
        float y = std::sin(angle) * m_radius.y;

        return sf::Vector2f(m_radius.x + x, m_radius.y + y);
    }
private :

    sf::Vector2f m_radius;
};


    while (window.isOpen())
    {
         sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        window.clear();
        window.draw(/*What goes here?*/);
        window.display();
        }
    }
    return 0;
}

This is the code, mostly just what is on the tutorial.
I mainly think i am just missing window.draw(??)
I tried EllipseShape, shape, then just tried everything else i could think of

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: custom shape type not appear in window
« Reply #5 on: January 07, 2015, 08:57:55 am »
Quote
I tried EllipseShape, shape, then just tried everything else i could think of
C++ is a complex language, you cannot "guess" it. I strongly recommend that you read a good C++ book before playing with SFML.

To answer your problem: you need to create an instance of your class (and it makes no sense to declare the class inside the main function).
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: custom shape type not appear in window
« Reply #6 on: January 07, 2015, 09:02:03 am »
You seem to be lacking a basic understanding of how C++ works.  There are no variables called "shape" or "EllipseShape" anywhere in this program.  There are classes/types called sf::Shape and EllipseShape, but those are classes, not objects.

To solve your immediate problem you simply need to create an actual object:
EllipseShape anActualObjectOfTypeEllipseShape;
...
window.draw(anActualObjectOfTypeEllipseShape);

Like most software libraries, SFML assumes (and has to assume) that you already know the language it's written in.  If you weren't aware that classes are not the same thing as objects, you probably need to go read a good book on C++ before trying to use libraries written in that language.