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

Author Topic: LoadFromFile always fails  (Read 3910 times)

0 Members and 1 Guest are viewing this topic.

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
LoadFromFile always fails
« on: April 20, 2013, 07:28:37 am »
SFML forum,

 SFML 1.6  Visual C++ Express 2010

 I'm new to SFML and have a very simple "open a window" program
 called FirstWindow that works.

 Now I try to load an image with this code:
   sf::Image MyImage;
   MyImage.LoadFromFile("Sprite2.bmp");

 It compiles without errors but when I run it I get this message:
 "FirstWindow has encountered an error and must close".

 If I comment out the LoadFromFile command the program runs OK.

 The file Sprite2.bmp resides in the program folder and I
 can open it and see the bmp image.

 Any suggestions?

jerryd

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: LoadFromFile always fails
« Reply #1 on: April 20, 2013, 08:13:49 am »
You must recompile SFML (you downloaded the Visual Studio 2008 version, didn't you?).
Laurent Gomila - SFML developer

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: LoadFromFile always fails
« Reply #2 on: April 21, 2013, 02:20:59 am »
Laurent,
 Thanks for the reply.

 I'm following a tutorial at:
 http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php

 These totorials are for SFML 1.6 and Visual C++ 2010 Express
 so I never loaded Visual Studio 2008.  Also I don't know how
 to compile SFML.

 Can you give me some instructions?

jerryd


jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: LoadFromFile always fails
« Reply #3 on: April 21, 2013, 05:28:38 am »
Laurent,
 I realized that I could get all the instructions I
 needed on the net.

 I went through the entire tutorial on compiling SFML at:
 
 and got the sample program to work.

 I changed all the properties in my FirstWindow solution but
 got the same error message.


Here's my code:

#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

int main()
{
   // Render up a window called MyWindow
   sf::RenderWindow MyWindow(sf::VideoMode(800, 600, 16), "SFML Window");

   MyWindow.SetFramerateLimit(60); // Limit to 60 frames per second

   // load the image
   sf::Image MyImage;
   //MyImage.LoadFromFile("Sprite2.bmp");

   bool Running = true;
   while (Running)
   {
      // check if there are any events
      sf::Event MyEvent;
      while (MyWindow.GetEvent(MyEvent))
      {
         // Window closed by X
         if (MyEvent.Type == sf::Event::Closed) MyWindow.Close();

         // Escape key pressed
         if ((MyEvent.Type == sf::Event::KeyPressed) && (MyEvent.Key.Code == sf::Key::Escape))
            MyWindow.Close();
      }

      // Clear the screen to black
         MyWindow.Clear(sf::Color(0, 0, 0));

      // display the window pointed to by MyWindow
      MyWindow.Display();
   }
   return EXIT_SUCCESS;
}

 See anything wrong here?

jerryd
« Last Edit: April 21, 2013, 05:45:47 am by jerryd »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: LoadFromFile always fails
« Reply #4 on: April 21, 2013, 02:32:30 pm »
I recommend SFML 2, see here for the reasons.

In fact, we should start a broad campaign on YouTube to deprecate all the SFML 1.6 tutorials ;)

Also, use the [code=cpp] [/code] tags to show C++ code.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: LoadFromFile always fails
« Reply #5 on: April 21, 2013, 04:14:26 pm »
Quote
In fact, we should start a broad campaign on YouTube to deprecate all the SFML 1.6 tutorials ;)
Wanna go trolling for 2.0.  ;D Sounds awesome.

Maybe someone who can write good could start here: http://en.wikipedia.org/wiki/SFML
Quote
Supported languages

The number indicates the version for which the bindings are available:
Official bindings

    C++ : 1.6
    C : 1.6
    .NET : 1.6


External bindings

    Python : 1.6
    D : 1.3
    Ruby : RC-2.0
    OCaml : 1.6 and RC-2.0
    Java
Things like that are just stupid.
Back to C++ gamedev with SFML in May 2023

jerryd

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: LoadFromFile always fails
« Reply #6 on: April 22, 2013, 07:24:46 am »
SMFL forum,

 Found the problem.  I didn't have sfml-graphics-d.lib in the
 Linker INPUTS.

 I have downloaded and compiled SFML 2.0.
 I made a solution similar to this one but when I click on the
 "build" the compiler option is grayed out.  If I type F5 I get
 an error message that says:
 "LINK : fatal error LNK1561: entry point must be defined"

 What am I missing?

jerryd