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

Author Topic: 1st Demo Using SFML - Only Get Console Window - HELP  (Read 10462 times)

0 Members and 1 Guest are viewing this topic.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
1st Demo Using SFML - Only Get Console Window - HELP
« on: January 19, 2009, 02:11:00 pm »
1st Demo Using SFML - Only Get Console Window - HELP

Hi,

I am new to SFML.
I am using Microsoft Vista OS and my C++ IDE is Code::Blocks.
I followed the instructions properly to set up SFML with Code::Blocks.
I entered this simple demo from SFML web site:

Code: [Select]
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

 int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(640, 640), "SFML window");

     // Load a sprite to display
     sf::Image Image;
     if (!Image.LoadFromFile("cute_image.jpg"))
         return EXIT_FAILURE;
     sf::Sprite Sprite(Image);

     // Create a graphical string to display
     sf::Font Arial;
     if (!Arial.LoadFromFile("arial.ttf"))
         return EXIT_FAILURE;
     sf::String Text("Hello SFML", Arial, 50);

     // Load a music to play
     sf::Music Music;
     if (!Music.OpenFromFile("nice_music.ogg"))
         return EXIT_FAILURE;

     // Play the music
     Music.Play();

     // Start the game loop
     while (App.IsOpened())
     {
         // Process events
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             // Close window : exit
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }

         // Clear screen
         App.Clear();

         // Draw the sprite
         App.Draw(Sprite);

         // Draw the string
         App.Draw(Text);

         // Update the window
         App.Display();
     }

     return EXIT_SUCCESS;
 }


It builds OK, but when I run it, I only get one console window with no 640x640 window. Also I see no test sprite, text, and OGG music playing? (I do have the test sprite JPG, font, and OGG in the directory of the executable.)

When I build above source in Code::Blocks under Windows Vista, I get the follow output:
Code: [Select]
-------------- Build: Debug in SFML_Beginning ---------------

Compiling: main.cpp
Linking console executable: bin\Debug\SFML_Beginning.exe
Info: resolving sf::Font::ourDefaultCharset      by linking to __imp___ZN2sf4Font17ourDefaultCharsetE (auto-import)
Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE (auto-import)
Info: resolving vtable for sf::Stringby linking to __imp___ZTVN2sf6StringE (auto-import)
C:\Program Files\CodeBlocks\MinGW\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.
Output size is 67.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 1 warnings


Again I am new to SFML.
If you can help me make this work I would appreciate it greatly.


JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
http://www.SilentHeroProductions.com
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
Re: 1st Demo Using SFML - Only Get Console Window - HELP
« Reply #1 on: January 21, 2009, 01:11:12 pm »
I don't see anything really wrong with your code.
Although, I'm not sure this is doing what you think it is:
Quote from: "JeZ-l-Lee"

Code: [Select]

     // Start the game loop
     while (App.IsOpened())


See here
I think IsOpened will only return false when the window has not been created.
I would recommend something like this:
Code: [Select]

bool Done = false;
while (!Done)
{
    //Render...
}


Quote from: "JeZ-l-Lee"

Code: [Select]
-------------- Build: Debug in SFML_Beginning ---------------

Compiling: main.cpp
Linking console executable: bin\Debug\SFML_Beginning.exe
Info: resolving sf::Font::ourDefaultCharset      by linking to __imp___ZN2sf4Font17ourDefaultCharsetE (auto-import)
Info: resolving vtable for sf::Spriteby linking to __imp___ZTVN2sf6SpriteE (auto-import)
Info: resolving vtable for sf::Stringby linking to __imp___ZTVN2sf6StringE (auto-import)
C:\Program Files\CodeBlocks\MinGW\bin\ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.
Output size is 67.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 1 warnings


This is what concerns me.
I've never seen these auto-import messages.
I'm wondering if you're using SFML DLLs and not defining SFML_DYNAMIC.
Is that it?

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Re: 1st Demo Using SFML - Only Get Console Window - HELP
« Reply #2 on: January 21, 2009, 04:41:01 pm »
Quote from: "dewyatt"
I think IsOpened will only return false when the window has not been created.

Calling App.Close(); will make it false.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #3 on: January 23, 2009, 05:14:55 am »
Oh yeah. I wasn't very awake when I wrote all that...

Liosan

  • Newbie
  • *
  • Posts: 11
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #4 on: January 26, 2009, 10:14:15 am »
Any update on this subject?

I'm getting exactly the same problem - only the console window on a project that should contain a normal SFML window.

The problem occured after a migration from SFML 1.3 to 1.4. The project compiles fine with MinGW using g++ 4.0, I link against dynamic, non-debug libraries with the dll-s in place. I can't link against the static libraries, because I get linkage errors. Apart from that, everything works - except that the window doesn't show :)

The same project compiles and opens fine with Visual Studio.

Any insight?

EDIT: the window is created using:

Code: [Select]

    sf::VideoMode currentVideoMode = sf::VideoMode::GetDesktopMode();
    mRenderWindow = new sf::RenderWindow( sf::VideoMode(800, 600, currentVideoMode.BitsPerPixel), "Warsztat Game" );

    assert( mRenderWindow && "CGame::CGame(): unable to create RenderWindow\n" );
and the assertion doesn't fire.

Liosan

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #5 on: February 04, 2009, 03:13:40 pm »
Hi,

This is known bug in 1.4 version.
If you have a USB joystick plugged into computer then unplug it and rerun your SFML application, should work now!


JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
http://www.SilentHeroProductions.com
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Liosan

  • Newbie
  • *
  • Posts: 11
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #6 on: February 18, 2009, 01:17:16 pm »
Well, ok. But I don't have one plugged in, I haven't even seen an USB joystick.

I do have several bluetooth HIDs (human interface devices) installed, but not plugged in (for example a Wii remote). Do you think this can be the issue?

Liosan

Liosan

  • Newbie
  • *
  • Posts: 11
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #7 on: March 08, 2009, 06:48:26 pm »
I'm sorry to double post... but is there any more insight on this?

Liosan

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #8 on: March 08, 2009, 07:00:39 pm »
Quote from: "Liosan"
Well, ok. But I don't have one plugged in, I haven't even seen an USB joystick.

I do have several bluetooth HIDs (human interface devices) installed, but not plugged in (for example a Wii remote). Do you think this can be the issue?

Liosan


have you tried unplugging them?

Bonafide

  • Newbie
  • *
  • Posts: 18
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #9 on: March 09, 2009, 04:17:05 am »
Hey guys, I'm having a similar problem, but different (not the joystick issue). The difference is that my code will not run UNLESS I omit a few lines of code from it, and I don't see why those few lines would be a problem to the program. I've ran the same code in other instances (drafts, etc) and it has ran without problem.

I know there are two areas within the code that draws santa and the block twice, that isn't the problem, I've changed it around when trying to run the program - to no avail.

Here's the problematic code:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include "Collision.h"
#include "Map.h"

using namespace std;
using namespace sf;


int main()
{
//Load collision
Collision coll;  

// Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

    // Load the sprite image from a file
    sf::Image imgBlock;
    if (!imgBlock.LoadFromFile("blocks.jpg"))
        return EXIT_FAILURE;

sf::Image imgSanta;
if (!imgSanta.LoadFromFile("santa.png"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite block(imgBlock);
sf::Sprite santa(imgSanta);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

/*///////////////////////////////////////////////
//Declare map & level variables
MAP map;

char level[1600][640];

//Open file stream;
ifstream file;

//Load
map.mapLoad(file, level);

//num holder
int num;

//Display
for(int y = 0; y < 1600; y++)
{
for(int x = 0; x < 640; x++)
{
num = level[y][x];

if(num == '1')
{
  block.SetPosition(x*32, y*32);
  App.Draw(block);
}
if(num == '2')
{
App.Draw(santa);
}
}
}
////////////////////////////////// */

if (App.GetInput().IsKeyDown(sf::Key::Left))
{
if(coll.detectCollision(santa, block) != true)
{
santa.Move(-100 * ElapsedTime, 0);
}
else
{
santa.SetPosition((santa.GetPosition().x + 3), (santa.GetPosition().y));
}
}
if (App.GetInput().IsKeyDown(sf::Key::Right))
{
if(coll.detectCollision(santa, block) != true)
{
santa.Move(+100 * ElapsedTime, 0);
}
else
{
santa.SetPosition((santa.GetPosition().x - 3), (santa.GetPosition().y));
}
}
if (App.GetInput().IsKeyDown(sf::Key::Up))
{
if(coll.detectCollision(santa, block) != true)
{
santa.Move(0, -100 * ElapsedTime);
}
else
{
santa.SetPosition((santa.GetPosition().x), (santa.GetPosition().y) + 3);
}
}
if (App.GetInput().IsKeyDown(sf::Key::Down))
{
if(coll.detectCollision(santa, block) != true)
{
santa.Move(0,  100 * ElapsedTime);
}
else
{
santa.SetPosition((santa.GetPosition().x), (santa.GetPosition().y) - 3);
}
}

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sf::Key::A)) santa.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::D)) santa.Rotate(+ 100 * ElapsedTime);

        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(santa);
App.Draw(block);

        // Display window contents on screen
        App.Display();
    }
    return EXIT_SUCCESS;
}


Here's the code that won't make the program run unless omitted (its in the code above):
Code: [Select]

/*///////////////////////////////////////////////
//Declare map & level variables
MAP map;

char level[1600][640];

//Open file stream;
ifstream file;

//Load
map.mapLoad(file, level);

//num holder
int num;

//Display
for(int y = 0; y < 1600; y++)
{
for(int x = 0; x < 640; x++)
{
num = level[y][x];

if(num == '1')
{
  block.SetPosition(x*32, y*32);
  App.Draw(block);
}
if(num == '2')
{
App.Draw(santa);
}
}
}
////////////////////////////////// */


Map class, if that's the issue:
Code: [Select]

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

using namespace sf;
using namespace std;

#define HEIGHT 1600;
#define WIDTH 600;



class MAP
{
public:
void mapLoad(ifstream& file, char level[1600][640]);

};

void MAP::mapLoad(ifstream &file, char level[1600][640])
{
//Input map file
file.open("level.txt");

//Holds the information line by line
std::string line;

//Height of the file
int fileHeight = 0;

while(std::getline(file, line))
{
for(int fileWidth = 0; fileWidth < 10; fileWidth++)
{    
  level[fileHeight][fileWidth] = line.at(fileWidth);
}    
fileHeight++;
}

//Close file stream
file.close();
}


All help is appreciated!

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #10 on: March 09, 2009, 05:22:01 am »
have you tried using a debugger or manually debugging? (using debug couts and printfs to try to figure out where exactly the problem is occurring? ) it could be a problem in the file.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #11 on: March 09, 2009, 07:47:55 am »
The stack is certainly too small to contain 1600x640 char ;)

Try declaring your array at global scope, or dynamically (using a std::vector).
Laurent Gomila - SFML developer

Bonafide

  • Newbie
  • *
  • Posts: 18
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #12 on: March 09, 2009, 07:23:39 pm »
Thanks, it's working now.

The problem was that I forgot to change the array dimensions to the results of 1600/32 and 640/32, which is 50 and 20 respectively.

Liosan

  • Newbie
  • *
  • Posts: 11
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #13 on: March 11, 2009, 08:10:31 pm »
Quote from: "Astrof"
Quote from: "Liosan"
I do have several bluetooth HIDs installed, but not plugged in ...


have you tried unplugging them?


... I haven't... any other ideas? :D

Liosan

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
1st Demo Using SFML - Only Get Console Window - HELP
« Reply #14 on: March 11, 2009, 10:07:09 pm »
I would try unplugging them and then trying it, or downloading the latest source through the SVN.  

but you said that the program works fine in Visual Studio?

 

anything