SFML community forums
Help => Graphics => Topic started by: morando on March 15, 2012, 12:32:44 pm
-
I tried to search but could not find what i need.
How to set texture for vertices array:
sf::Vertex* vert = new sf::Vertex[6];
...//fill vertices
...
??? SetTexture(???) ; // WHAT?
window.Draw( vert, 6, sf::Triangles);
Thanks for your time.
-
window.Draw(vert, 6, sf::Triangles, &texture);
Which is in fact a shortcut for this:
sf::RenderStates states;
states.texture = &texture;
window.Draw(vert, 6, sf::Triangles, states);
sf::RenderStates allow to set the texture, shader, transform and blend mode to use for the current draw operation (even when drawing sprites or text -- although some states are overriden in this case).
-
Thanks.
-
Why use sf::Vertex* vert = new sf::Vertex[6];
And not just an sf::VertexArray?
-
Why use sf::Vertex* vert = new sf::Vertex[6];
And not just an sf::VertexArray?
It sounds strange, the question is usually "why sf::VertexArray and not a simple Vertex[]?" ;)
sf::VertexArray is a wrapper around std::vector<sf::Vertex> + sf::PrimitiveType. Nothing more.
However, std::vector<sf::Vertex> (at least) would be better than this raw array of vertices managed manually.
-
Hmmm. I can't get this right. if image has alpha channel nothing is displayed, and if it does not then it only shows vertex color:
int main() {
...
sf::Texture tex;
if(!tex.LoadFromFile("smoke.tga"))
{
return 1;
}
sf::RenderStates rs;
rs.Texture = &tex;
rs.BlendMode = sf::BlendNone;
float size = 50.0f;
sf::Vector2f pos(400.0f, 300.0f);
sf::Vertex vertices[6];
vertices[0].Color = sf::Color(255,255,255,255);
vertices[0].Position.x = pos.x + size;
vertices[0].Position.y = pos.y + size;
vertices[0].TexCoords = sf::Vector2f(1.0f, 1.0f);
vertices[1].Color = sf::Color(255,255,255,255);
vertices[1].Position.x = pos.x + size;
vertices[1].Position.y = pos.y - size;
vertices[1].TexCoords = sf::Vector2f(1.0f, 0.0f);
vertices[2].Color = sf::Color(255,255,255,255);
vertices[2].Position.x = pos.x - size;
vertices[2].Position.y = pos.y - size;
vertices[2].TexCoords = sf::Vector2f(0.0f, 0.0f);
vertices[3].Color = sf::Color(255,255,255,255);
vertices[3].Position.x = pos.x + size;
vertices[3].Position.y = pos.y + size;
vertices[3].TexCoords = sf::Vector2f(1.0f, 1.0f);
vertices[4].Color = sf::Color(255,255,255,255);
vertices[4].Position.x = pos.x - size;
vertices[4].Position.y = pos.y - size;
vertices[4].TexCoords = sf::Vector2f(0.0f, 0.0f);
vertices[5].Color = sf::Color(255,255,255,255);
vertices[5].Position.x = pos.x - size;
vertices[5].Position.y = pos.y + size;
vertices[5].TexCoords = sf::Vector2f(0.0f, 1.0f);
...
wnd.Draw( vertices, 6, sf::Triangles, rs);
here is a image "smoke.tga"(32bits, uncompressed tga):
http://fs10u.sendspace.com/processupload.html
Is just a green circle with
(http://www.dodaj.rs/f/2P/sP/kKD9uvt/2012-03-1518-28-18.jpg)
-
Read the doc: TexCoords are in pixels, they are not normalized.
-
Thats it hanks.
But its strange that i have specified BlendNone yet it shows no white "borders" aroung green circle? Whats wrong?
-
But its strange that i have specified BlendNone yet it shows no white "borders" aroung green circle? Whats wrong?
I don't get it. Maybe you could show a screenshot?
-
Ok. Here is a test src:
#include <iostream>
#include <SFML/Graphics.hpp>
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")
int main()
{
try
{
sf::RenderWindow wnd(sf::VideoMode( 200, 200, 32 ), "Test vertices");
sf::Texture tex;
if(!tex.LoadFromFile("smoke.tga"))
{
throw std::runtime_error("Failed to load texture!");
}
float tw = (float)tex.GetWidth();
float th = (float)tex.GetHeight();
sf::Transform transform;
transform.Translate(100.0f, 100.0f);
sf::RenderStates rs;
rs.Transform = transform;
rs.Texture = &tex;
rs.BlendMode = sf::BlendNone;
float size = 50.0f;
sf::Vertex vertices[6];
vertices[0].Color = sf::Color(255,255,255,255);
vertices[0].Position.x = size;
vertices[0].Position.y = size;
vertices[0].TexCoords = sf::Vector2f(tw, th);
vertices[1].Color = sf::Color(255,255,255,255);
vertices[1].Position.x = size;
vertices[1].Position.y = -size;
vertices[1].TexCoords = sf::Vector2f(tw, 0.0f);
vertices[2].Color = sf::Color(255,255,255,255);
vertices[2].Position.x = -size;
vertices[2].Position.y = -size;
vertices[2].TexCoords = sf::Vector2f(0.0f, 0.0f);
vertices[3].Color = sf::Color(255,255,255,255);
vertices[3].Position.x = size;
vertices[3].Position.y = size;
vertices[3].TexCoords = sf::Vector2f(tw, th);
vertices[4].Color = sf::Color(255,255,255,255);
vertices[4].Position.x = -size;
vertices[4].Position.y = -size;
vertices[4].TexCoords = sf::Vector2f(0.0f, 0.0f);
vertices[5].Color = sf::Color(255,255,255,255);
vertices[5].Position.x = -size;
vertices[5].Position.y = size;
vertices[5].TexCoords = sf::Vector2f(0.0f, th);
while(wnd.IsOpen())
{
sf::Event event;
while( wnd.PollEvent(event) )
{
switch(event.Type)
{
case sf::Event::Closed:
{
wnd.Close();
return false;
}break;
};
}
wnd.Clear(sf::Color(0, 0, 0));
wnd.Draw( vertices, 6, sf::Triangles, rs);
wnd.Display();
}
}
catch( const std::runtime_error& e)
{
std::cout << e.what() << std::endl;
std::cin.ignore();
return EXIT_FAILURE;
}
std::cin.ignore();
return EXIT_SUCCESS;
}
render screenshot:
(http://www.dodaj.rs/f/31/yK/24RfLDDw/render.jpg)
tga image in Photoshop (saved as 32bits uncompressed). i have recolored "borders" to be blue for easier explaination:
(http://www.dodaj.rs/f/2v/5s/3WVVEexk/photoshop.jpg)
Image uploaded to sendspace:
http://www.sendspace.com/file/zqgnlg
I expected render (with BlendNone) to show blue "borders" aroun green circle.
I expected this with BlendNone (edit in Photoshop):
(http://www.dodaj.rs/f/2v/xR/nLSf0Sb/1/render.jpg)
-
It was a bug, it's fixed now. Thanks for your feedback :)
-
Why don't you release prebuilt binaries?
Why do everybody likes this stupid CMake? Its junk generator!
Oh god why are you tortuering me??? O why did you make my life harder?
I dont understand this from tutorial (I am using VS2010):
With Visual C++, you can either run CMake from the "Visual Studio command prompt" available from the start menu, or call the vcvars32.bat file of your Visual Studio installation; it will setup the environment variables properly.
> your_visual_studio_folder\VC\bin\vcvars32.bat
> cmake
Do i need both of these programs? Whats with this combination?
What to choose here for VS2010 c++
(http://www.dodaj.rs/f/1O/yd/2yQwQZZe/sfml-simple-and-fast-mul.jpg)
a vs 2010 or NMake makefiles?
-
For example, to generate a Visual Studio 10 solution, you must choose "Visual Studio 10". To generate makefiles usable with Visual C++, select "NMake makefiles".
What is a difference beetwen vs2010 and Visual c++ in this context?
Now i don't know what to choose?
What is NMake makefiles JOM?
-
Why don't you release prebuilt binaries?
Because it's a development version, it's not finished yet.
Why do everybody likes this stupid CMake? Its junk generator!
What do you suggest instead?
Don't denigrating something just because you don't understand it ;)
Oh god why are you tortuering me??? O why did you make my life harder?
If you take some time to understand what you do, not only you'll learn useful stuff, but you'll realize that it's much simpler than what you think. Blindly following steps in a tutorial is good if you want things done quickly, but it's not enough in the long run.
I dont understand this from tutorial (I am using VS2010)
vcvars32.bat will set the appropriate environment variables so that you can then use the VC++ compiler. You need to call it before doing anything with VC++ (except running the Visual Studio IDE, of course).
Then, "cmake" (or "cmake-gui") simply runs CMake.
So yes you need to call both, in this order.
a vs 2010 or NMake makefiles?
Whatever you like. I recommend NMake makefiles, so that you can compile with a simple "nmake" in the console.
"Visual Studio 2010" will create a solution that you can open in the IDE.
What is a difference beetwen vs2010 and Visual c++ in this context?
Visual Studio is the IDE, Visual C++ is the compiler.
What is NMake makefiles JOM?
JOM is a tool written by the Qt team to enable multi-core compilation with nmake (which doesn't support it natively).
-
Ok. i manage somehow to make solution for vs2010 and compiled debug & release libs of SMFL. Now to replace all function names to lowercase :cry: