-
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. :-\
-
Just asking the obvious questions here:
Do you clear() before you draw()?
Do you display() after you draw()?
-
Yep, both. Just thought those were too obvious to show it to you ;)
-
http://en.sfml-dev.org/forums/index.php?topic=16094.msg115303#msg115303 ?
That's not a rectangle.
And is your window 720, 1280?
-
Uhm 1280 x 720, but even with 720, 1280 it should at least be drawn for a bit.
-
Yep, but are you going to post an SSCCE or is this thread not worth coming back?
>Good luck then. :D
-
Well I guess it's not worth for you to come back then.
-
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),
};
-
Kay thanks, but it didn't fix the problem.
-
Lets keep guessing here..... Or will you follow G.'s advice?
-
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;
}
-
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
-
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 :)