Jump to content

  • Log In with Google      Sign In   
  • Create Account

C++ & SFML?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#1 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 October 2013 - 01:50 AM

I'm new to C++ and I wanted to try SFML.

 

So I downloaded visual studio 2012 and the SFML 2.1 zip file. Extracted it to C:/sfml2.1

 

And I followed the instructions. I also disabled the 'Precompiled header' option in  'configuration -> C/C++ -> Precompiled headers' as suggested by another thread here on gamedev.

 

But I'm getting this error:

The program can't start because sfml-system-d-2.dll is missing from your computer. Try reinstall...

Any ideas?

 

Thanks in advance!



Sponsor:

#2 Dragonsoulj   Crossbones+   -  Reputation: 2126

Like
1Likes
Like

Posted 15 October 2013 - 01:58 AM

You need that .dll file in your .exe file directory for it to run.



#3 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 October 2013 - 01:59 AM

Hm. The tutorial on sfml-dev.org didn't say that.

 

Where can I find it then?



#4 Dragonsoulj   Crossbones+   -  Reputation: 2126

Like
2Likes
Like

Posted 15 October 2013 - 02:00 AM

Do a search on the SFML download for those .dlls. All "-d" files are debug, all without are regular "release" versions.



#5 afflicto   Members   -  Reputation: 127

Like
1Likes
Like

Posted 15 October 2013 - 02:01 AM

I found them and it works! ;D

 

Thanks for the quick reply btw!



#6 Dragonsoulj   Crossbones+   -  Reputation: 2126

Like
1Likes
Like

Posted 15 October 2013 - 02:04 AM

You are welcome. Glad I could help. I think there is mention somewhere on the site about the DLLs.

By the way, from the Visual Studio tutorial page:

 

 

Now compile the project, and if you linked to the dynamic version of SFML, don't forget to copy the SFML DLLs (they are in <sfml-install-path/bin>) to the directory where your compiled executable is. Then run it, and if everything is ok you should see this:

Edited by Dragonsoulj, 15 October 2013 - 02:04 AM.


#7 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 October 2013 - 02:10 AM

Oh... I guess my patience is not top notch today :P



#8 Dragonsoulj   Crossbones+   -  Reputation: 2126

Like
2Likes
Like

Posted 15 October 2013 - 02:11 AM

It happens. Future reference. It also mentions how to do static linking.



#9 wintertime   Members   -  Reputation: 1877

Like
1Likes
Like

Posted 15 October 2013 - 08:37 AM

Or just add the bin directory of SFML to the path, then you dont need to copy the dll files every time you make a new project. Just remember users of your program need them.



#10 dejaime   Crossbones+   -  Reputation: 4119

Like
0Likes
Like

Posted 15 October 2013 - 09:13 AM

You can get SFML liked statically to remove the need for dll. Static linking reduces the final size of the program, but possibly makes updates bigger.

I use static linking for convenience.



#11 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 15 October 2013 - 10:37 PM

I see. I did some stuff with the words 'linking' and 'sfml_static' I dno if that was linking.



#12 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 03:26 AM

I have a question. What's going on in the Dog::Dog() constructor there?

Class Dog {
    private:
        Pig pig;
        Cat cat;
}

Dog::Dog()
    : pig(1)
    , cat()
{
}

Coming from other OOP languages, I find this strange tongue.png


Edited by afflicto, 16 October 2013 - 03:27 AM.


#13 BitMaster   Crossbones+   -  Reputation: 4433

Like
1Likes
Like

Posted 16 October 2013 - 04:13 AM

It's just an initializer list.

#14 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 07:37 AM

Ah, I see. thanks :)



#15 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 07:44 AM

I have another question. in SFML there is a templated Vector2 class.

 

I've been trying to extend it for the past few hours but damn...

 

Here's my code:

#pragma once
#include <SFML/Graphics.hpp>
#include <cmath>

template <typename T>
class Vector2 : sf::Vector2 {

public:
	T mag();
	void normalize();
	void invert();
	void decrease(T i);
	void reset();
	void limit(int i);
};

template <typename T>
T Vector2<T>::mag() {
	return sqrt(this->x*2 + this->y*2);
}

Edited by afflicto, 16 October 2013 - 07:44 AM.


#16 wintertime   Members   -  Reputation: 1877

Like
1Likes
Like

Posted 16 October 2013 - 08:40 AM

I would not do it that way. By deriving from that class that is not much more than a struct with a constructor, you are overcomplicating this and you will have to copy the vectors you get from sfml into your new type before you can use those methods. You better just make some free functions in the same way most of the functionality for using sf::Vector2 is done.

Though you should think again before doing that, the SFML vectors are just a tiny thing for communicating with that library and you may be much better off with using a real vector/matrix library like GLM: http://glm.g-truc.net



#17 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 08:51 AM

Hm.. ok. I'll look into that, thanks!



#18 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 09:44 AM

I run into another issue.

 

I have a class 'Game'. and when instantiated, I want to store the instance on a static member of the 'Game' class but some code in SFML complains about NonCopyable.

 

I tried storing a reference, reference to a pointer and a the dereferenced object to no avail.

 

Here's the class:

class Game
{
	private:
		sf::RenderWindow mWindow;
		
	protected:
		std::vector<Entity> entities;

	public:
		static Game instance;
}

and the implementation:

Game::Game()
	: mWindow(sf::VideoMode(640, 480), "SFML!")
{
	//set the game instance
	Game::instance = *this;
}

Here's the full error:

error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable'	c:\sfml2.1\include\sfml\window\window.hpp	477	1	sfmltest2

What's going on here?


Edited by afflicto, 16 October 2013 - 09:44 AM.


#19 wintertime   Members   -  Reputation: 1877

Like
0Likes
Like

Posted 16 October 2013 - 10:54 AM

That means you should not do that with the RenderWindow as it was intentionally made not copyable to prevent errors.

Also singletons should be avoided as much as possible. Just create your objects somewhere and only pass a reference to as little functions through their arguments as possible and needed, to not get into the trap of creating spaghetti code.



#20 afflicto   Members   -  Reputation: 127

Like
0Likes
Like

Posted 16 October 2013 - 11:08 AM

I was able to make it work.

 

It's not exactly a singleton. I just need my input object, sound object, gui object etc to access each other.

 

I think passing things around all the time is more like spaghetti code than to have 1 single place to store a reference to something. Less typing as well.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS