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

Author Topic: Gradient Rectangle  (Read 5755 times)

0 Members and 1 Guest are viewing this topic.

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Gradient Rectangle
« on: August 20, 2014, 09:26:04 pm »
I was searching for how to use gradient, then I found this: http://en.sfml-dev.org/forums/index.php?topic=6750.0
I tried the code that laurent provided but it doesn't work. No errors, just a black screen.
Pieces of code in question:
sf::Vertex backgroundgr[] =
        {
                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(0, 1280), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(720, 0), sf::Color::Cyan),
                sf::Vertex(sf::Vector2f(720, 1280), sf::Color::Cyan)
        };

m_window.draw(backgroundgr, 4, sf::Quads);
Now, I don't know if I'm using it wrong, or if it just doesn't work.  :-\

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #1 on: August 20, 2014, 09:32:40 pm »
Just asking the obvious questions here:

Do you clear() before you draw()?
Do you display() after you draw()?

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #2 on: August 20, 2014, 09:35:09 pm »
Yep, both. Just thought those were too obvious to show it to you ;)

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Re: Gradient Rectangle
« Reply #3 on: August 20, 2014, 09:40:21 pm »
http://en.sfml-dev.org/forums/index.php?topic=16094.msg115303#msg115303 ?

That's not a rectangle.
And is your window 720, 1280?

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #4 on: August 20, 2014, 09:47:04 pm »
Uhm 1280 x 720, but even with 720, 1280 it should at least be drawn for a bit.

G.

  • Hero Member
  • *****
  • Posts: 1590
    • View Profile
Re: Gradient Rectangle
« Reply #5 on: August 20, 2014, 10:10:13 pm »
Yep, but are you going to post an SSCCE or is this thread not worth coming back?

>Good luck then. :D
« Last Edit: August 20, 2014, 10:49:18 pm by G. »

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #6 on: August 20, 2014, 10:35:37 pm »
Well I guess it's not worth for you to come back then.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Gradient Rectangle
« Reply #7 on: August 21, 2014, 01:09:44 am »
All primitive types must be defined in either clockwise or counter clockwise direction. Your code should be changed to the following.

Note: I changed the vertex order.
sf::Vertex backgroundgr[] =
        {
                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(0, 1280), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(720, 1280), sf::Color::Cyan)
                sf::Vertex(sf::Vector2f(720, 0), sf::Color::Cyan),
        };
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #8 on: August 21, 2014, 05:14:24 pm »
Kay thanks, but it didn't fix the problem.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Gradient Rectangle
« Reply #9 on: August 21, 2014, 05:31:19 pm »
Lets keep guessing here..... Or will you follow G.'s advice?
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #10 on: August 21, 2014, 05:37:17 pm »
FINE YA DINGUS, for you, because you're nice. Not for G...
#include <memory>
#include <iostream>

#include "StateMachine.hpp"
#include "Level1State.hpp"
#include "PlayState.hpp"
#include "GameState.hpp"
#include "StateMachine.hpp"
#include "MenuState.hpp"
#include "Application.hpp"

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>

int main() {
    sf::RenderWindow window( sf::VideoMode(1280, 720, 32), "Vieze kut" );
        sf::Vertex backgroundgr[] =
        {
                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(0, 1280), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(720, 1280), sf::Color::Cyan),
                sf::Vertex(sf::Vector2f(720, 0), sf::Color::Cyan),
        };
       
    while( window.isOpen() ) {
        sf::Event event;
        while( window.pollEvent( event ) ) {
            if( event.type == sf::Event::Closed ) {
                window.close();
            }
        }

                window.clear();
                window.draw(backgroundgr, 4, sf::Quads);
        window.display();
    }

    return EXIT_SUCCESS;
}
« Last Edit: August 21, 2014, 05:41:39 pm by teunissenstefan »

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Gradient Rectangle
« Reply #11 on: August 21, 2014, 06:02:12 pm »
Hmm okay so that alone works, but not if
sf::Vertex backgroundgr[4];
is set in header?

And if I just put
sf::Vertex backgroundgr[4] =
        {
                sf::Vertex(sf::Vector2f(0, 0), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(0, 1280), sf::Color::Blue),
                sf::Vertex(sf::Vector2f(720, 1280), sf::Color::Cyan),
                sf::Vertex(sf::Vector2f(720, 0), sf::Color::Cyan),
        };
in the .cpp it says: backgroundgr : undeclared identifier

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Gradient Rectangle
« Reply #12 on: August 23, 2014, 09:09:44 pm »
You can't just declare variables anywhere. Either declare the array of vertices as a local variable, or use a function... Then I recommend sf::VertexArray or at least std::array<sf::Vertex, 4> for value semantics. Plain C arrays should be avoided where possible.

By the way, this is not a SFML-related question... It might be worth having a look at a good C++ book :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything