SFML community forums
Help => General => Topic started by: Bacu on November 06, 2011, 09:17:13 am
-
Everything compiles and links properly, but when the application runs, all I get is an empty console window, and no SFLM window. Any ideas? The .dlls are in the same directory as the .exe. I get a bunch of "Cannot find or open the PDB file" in the debug when I run. Not sure if this is problem.
Any ideas?
-
SFML 1.6? ATI graphics card?
-
SFML 1.6? ATI graphics card?
Yes and yes.
-
=> Known bug ;)
-
=> Known bug ;)
Well, what can I do now? Is the library useless to me until it's fixed or what?
-
=> Known bug ;)
Well, what can I do now? Is the library useless to me until it's fixed or what?
Use SFML2.
-
=> Known bug ;)
Well, what can I do now? Is the library useless to me until it's fixed or what?
Use SFML2.
I assume that all of the tutorials that are for 1.6 will more or less work for 2.0?
-
=> Known bug ;)
Well, what can I do now? Is the library useless to me until it's fixed or what?
Use SFML2.
I assume that all of the tutorials that are for 1.6 will more or less work for 2.0?
Yes, and when they don't, it's probably because the name of something may have changed. For example, sf::Image has split into sf::Texture (what you want to use for rendering) and sf::Image (stored in memory only)
-
Laurent, I know SFML 2 hasn't officially been released as yet, but why not take down the 1.6 link? The more people who use 2, the better, and it's so stable now anyway.
It would also help stop problems like this :-)
-
SFML 1.6 is still the latest official version, I can't hide it.
Regarding the initial problem, static linking should also solve it ;)
-
Oh boy, more problems. I followed the instructions on using Cmake to put everything together, but I get this error:
CMake Error at CMakeLists.txt:131 (add_subdirectory):
add_subdirectory given source "src/SFML" which is not an existing
directory.
CMake Error at examples/ftp/CMakeLists.txt:8 (sfml_add_example):
Unknown CMake command "sfml_add_example".
Configuring incomplete, errors occurred!
groan.
-
Seems like your SFML directory is messed up. Try to download it again.
-
Seems like your SFML directory is messed up. Try to download it again.
Something was off with the download. The first time I extracted the .rar, it gave me an error. I downloaded and extracted over again but it kept happening; but if I extracted, got the error, then extracted and replaced all, I didn't get the error and Cmake did its job with no trouble.
But noooooooooow I've built the example and the same thing still happens. When I run the program, it also asks for sfml-window.dll and sfml-system.dll in addition to sfml-window-2.dll and sfml-system-2.dll. I tried using 1.6 dlls to no avail. Copying and renaming the -2.dlls gave errors.
-
Something is seriously messed up, it's like you're mixing SFML 1.6 and 2.0.
Remove everything related to SFML and try again.
-
Something is seriously messed up, it's like you're mixing SFML 1.6 and 2.0.
Remove everything related to SFML and try again.
alright, getting closer. Builds and runs and I get a window, but the window's 'X' close button doesn't seem to work, nor does the minimize, nor can I drag the window around. I can only close it by closing the console it's running from. The debug information says that it doesn't exit with "0" as its return value.
-
That tutorial doesn't treat events, so your window's close event is not used and the window isn't closed. Advance on the tutorials and you shall solve your problem.
-
That tutorial doesn't treat events, so your window's close event is not used and the window isn't closed. Advance on the tutorials and you shall solve your problem.
So it seems. Missed that line. Oh well. Time to move forward.
-
Alright, been smooth so far. The differences between the tutorial and the 2.0 library are actually proving to be a good learning tool, gotta dig to figure it out.
anyway, having an issue with sf::Image.load. Getting "Failed to load image "sprite.png". Reason : Unable to open file". sprite.png is in the same directory as the executable. What am I doing wrong?
//#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Events");
sf::Image Image;
if(!Image.LoadFromFile("sprite.png"))
{
//std::cout<<"Failed to load";
//return EXIT_FAILURE;
}
while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
App.Close();
}
//if(sf::Keyboard::IsKeyPressed(sf::Keyboard::A)) std::cout<<"A IS PRESSED";
App.Clear();
App.Display();
}
return EXIT_SUCCESS;
}
-
The working directory is not always the same directory as the executable, especially when you run the app from the IDE.
-
Trying to play around with this stuff. This bit of code is supposed to create Triangles at the center of the screen, give them random velocity and spin, then display their movement.
#include <SFML/Graphics.hpp>
#include <iostream>
#include <math.h>
#include <time.h>
#include <vector>
sf::Vector2f origin;
sf::Vector2f gravity;
int frames;
float getrand(float a, float b)
{
return ((b-a)*((float)rand()/RAND_MAX))+a;
}
struct Triangle
{
sf::Shape Tri;
sf::Vector2f Pos;
sf::Vector2f Vel;
float Spin;
Triangle()
{
Tri.AddPoint(0,10);
Tri.AddPoint(20,0);
Tri.AddPoint(20,20);
Tri.SetOrigin(10,10);
Tri.SetPosition(origin);
Pos = Tri.GetPosition();
Spin = getrand(-360.f,360.f);
Vel.x = getrand(-.5f,.5f);
Vel.y = getrand(-.5f,.5f);
}
void Draw(sf::RenderWindow &app)
{
app.Draw(Tri);
}
void Physics()
{
Vel = sf::Vector2f(Vel.x + gravity.x/frames ,Vel.y + gravity.y/frames);
Pos = sf::Vector2f(Pos.x + Vel.x/frames ,Pos.y + Vel.y/frames);
Tri.SetPosition(Pos);
Tri.Rotate(Spin/frames);
}
};
int main()
{
srand((unsigned)time(0));
origin.x = 400;
origin.y = 300;
gravity.x = 0;
gravity.y = 3;
std::vector<Triangle*> triangles;
sf::RenderWindow App(sf::VideoMode(800,600,32),"oh man");
int frames = 60;
App.SetFramerateLimit(frames);
while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))
App.Close();
}
App.Clear();
Triangle* ptr = new Triangle;
triangles.push_back(ptr);
for (unsigned long x = 0; x < triangles.size(); x++)
{
std::cout<<triangles.at(0)->Pos.x<<" "<<triangles.at(0)->Pos.y<<"\n";
triangles.at(x)->Physics();
triangles.at(x)->Draw(App);
}
App.Display();
}
return EXIT_SUCCESS;
}
Two problems. The first is Triangle::Physics(); turns Vel and Pos into + Pos {x=-1.#IND000 y=1.#INF000 } sf::Vector2<float>
+ Vel {x=-1.#IND000 y=1.#INF000 } sf::Vector2<float>
Am I doing something wrong here?
Second, if I change Triangle::Physics to only increment Pos every time it's called, The call to Triangle::Draw(App); never ends up producing anything onscreen. If I only create one Triangle and never call Physics, it will display at the middle of the screen.
-
I was dividing by 0, duh. okay, problem solved.
-
And now another question. How to statically link? all of the .lib are -d.
-
You must compile the static libs (disable BUILD_SHARED_LIBS in CMake).
-
today's problem. I've #included <SFML\Graphics>, but for some reason if I try to make an sf::RenderWindow or any other thing, it says that it's an unrecognized symbol. My autocomplete doesn't show up when I type the sf:: namespace, either. But when I tell VC to open the header files, it has no problems opening them, but apparently something's wrong here.
-
unrecognised symbol usually means that you aren't linking to the necessary libraries
-
unrecognised symbol usually means that you aren't linking to the necessary libraries
I've linked to all of the -s-d.libs in the proper order. I'm fairly certain I copied all of the settings over from the project file that worked properly.
-
today's problem. I've #included <SFML\Graphics>...
It should be SFML/Graphics.hpp
-
today's problem. I've #included <SFML\Graphics>...
It should be SFML/Graphics.hpp
That's what I meant.
-
problem routed. I was being a stupid ameteur and including .cpp files that ended up making some knotted wreath of infinite self-reference.
-
Peculiar error. no clue on this one.
my code all other source files compile and link properly.
#include <vector>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include "core.h"
#include "state.h"
#include "state_game.h"
Core::Core()
{
WIDTH = 800;
HEIGHT = 600;
DEPTH = 32;
TITLE = "SpaceGame";
Window.Create(sf::VideoMode(WIDTH, HEIGHT, DEPTH), TITLE);
states.push_back(new State_Game(this));
}
int Core::run()
{
while (Window.IsOpened())
{
while (Window.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed) Window.Close();
}
if (states.empty())
{
return 1;
}
states.back()->process();
states.back()->render(Window);
Window.Display();
}
return 0;
}
void Core::popState()
{
Core::states.pop_back();
}
void Core::pushState(State* newState)
{
Core::states.push_back(newState);
}
Error output
1>c:\sfml\sfml2\include\sfml\window\window.hpp(479): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\sfml2\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\sfml2\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>c:\sfml\sfml2\include\sfml\graphics\rendertarget.hpp(304): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1> c:\sfml\sfml2\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1> c:\sfml\sfml2\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1> This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
-
You're trying to copy a RenderWindow instance somewhere (this is probably implicit/hidden), which is not allowed.
-
Probably this line here.
states.back()->render(Window);
I'm guessing the signature for render is
void render(sf::RenderWindow Window);
or something like that. Change it to
void render(const sf::RenderWindow& Window);
-
Probably this line here.
states.back()->render(Window);
I'm guessing the signature for render is
void render(sf::RenderWindow Window);
or something like that. Change it to
void render(const sf::RenderWindow& Window);
winner winner. that was it.
-
Actually, the methods you are likely to call on the RenderWindow in your render method are likely going to be Draw, and Display, both of which are not const methods. Thus, you should not pass a reference to const, but just a reference, as a reference to const will not allow you to call any methods that are not const-qualified.
Use
void render(sf::RenderWindow& Window);
basically any time you want to pass a non-integral type (not an int, float, etc) for example (std::vector, sf::RenderWindow, sf::Texture, etc), you should be passing by reference, not by copy. When you write
void someMethod(sf::Texture Texture);
you are copying ALL of the data that is held in the instance you are passing as a parameter, and you should opt to pass by reference
void someMethod(sf::Texture& Texture);
However, passing by reference allows you to change the original object that was passed in. To promise you wont change anything, you can pass a reference to const
void someMethod(const sf::Texture& Texture);
but then you are limited to using methods of sf::Texture that are const qualified for example
unsigned int GetWidth () const
however you would not be allowed to call
void Update (const Uint8 *pixels)