SFML community forums

Help => General => Topic started by: Viruses on December 16, 2011, 03:13:15 am

Title: SFML Window not showing!!!
Post by: Viruses on December 16, 2011, 03:13:15 am
So i linked with SFML 1.6 and MinGW but when build and run the code, all i get is a blank console window, not the SFML one. When i cross out the console window, it stays for like 8 seconds(as if its frozen) and then it terminates. I don't know what i did wrong. I tried reinstalling everything but the same problem still occurs. I've had SOO much problems with SFML installation with codeblocks.I've been trying to get SFML to run for the past like 4 days.So help would be incredibly appreciated! Thanks!
Title: SFML Window not showing!!!
Post by: OniLinkPlus on December 16, 2011, 06:58:21 am
Complete and minimal code, please. Seriously, why is it so difficult to figure out that we don't have access to your code? We need to see your code to see the problem.
Title: SFML Window not showing!!!
Post by: CJ_COIMBRA on December 16, 2011, 09:18:41 pm
Assuming your problem is not code related, I believe I had a similar (if not the same) problem than this one. I get this frozen window and if I wait for a very long time the game would start like if it was running on extremely low FPS rate. Couldn´t find any solution as it was somehow related to my video card + OS since the same code executed fast enough in several other computers with varied OSs. Changing from Code::Blocks to Visual Studio didn´t help either. I gave up and returned my computer to the original OS.
Title: SFML Window not showing!!!
Post by: Viruses on December 16, 2011, 11:51:34 pm
Alright fine here is the code im sorry:

Code: [Select]

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




int main()
{
    sf::RenderWindow Game(sf::VideoMode(800,600,32),"Amazing");




    while(Game.IsOpened())
    {
        sf::Event Event;

        while(Game.GetEvent(Event))
        {
            switch(Event.Type)
            {
                case sf::Event::Closed:
                Game.Close();
                break;

                default:
                break;
            }
        }

        Game.Clear(sf::Color(0,255,255));
        Game.Display();


    }

    return 0;
}




So, I build and run and all i get is a console window.
Title: SFML Window not showing!!!
Post by: Anata on December 17, 2011, 02:30:12 am
The Type of "Build Target" is "Console application" or "GUI Application" ?
Title: SFML Window not showing!!!
Post by: Haikarainen on December 17, 2011, 02:42:24 am
Quote from: "Anata"
The Type of "Build Target" is "Console application" or "GUI Application" ?



This shouldn't matter. Delete the #include <SFML/Window.hpp> btw, you dont need it. If that fixes the problem then thats nice.


Are you running linux? Have you tried to debug it in codeblocks?
Title: SFML Window not showing!!!
Post by: Viruses on December 17, 2011, 03:37:24 am
I tried both build targets console and GUI it doesnt work. And also deleting "Window.hpp> doesnt help. And I use windows operating system, not linux. And i work in codeblocks.And i built it in debug and release and i still get the blank console window. It appears as if theres nothing i can do. I would do SDL but SDL is in C which means its not object oriented. I like C++ ALOT more than C. So tht's why i want to do SFML...but theres just so much problems...

EDIT: I can make a video of the linking ive done with codeblocks and SFML and stuff..but i don't know how to show a video or screenshot on this forum. If there's anything else you can think of, PLEASE suggest.Thanks in advance!
Title: SFML Window not showing!!!
Post by: Haikarainen on December 17, 2011, 04:08:53 am
Dude, debug it! Put the buildtarget to debug, then press F8, and tell us any errors.
Title: SFML Window not showing!!!
Post by: Viruses on December 17, 2011, 04:25:44 am
Ok so i debugged it under Debugw but while its debugging i still get the same blank console window. When i cross it however, it still statys for like 8 secs and then terminates but i dont think the debugger stops because there is an option that says "Stop Debugger" which means its still running... Then when i try to stop it, it says "Trying to pause the running process..." and it doesnt stop unless i cross out the window. So what now?
Title: SFML Window not showing!!!
Post by: Haikarainen on December 17, 2011, 09:33:57 am
Quote from: "Viruses"
Ok so i debugged it under Debugw but while its debugging i still get the same blank console window. When i cross it however, it still statys for like 8 secs and then terminates but i dont think the debugger stops because there is an option that says "Stop Debugger" which means its still running... Then when i try to stop it, it says "Trying to pause the running process..." and it doesnt stop unless i cross out the window. So what now?


Might be a bug in 1.6, i know from experience 2.0 is more stable, so try dling/compiling/setting up 2.0 and use the exact same code, except change GetEvent to PollEvent
Title: SFML Window not showing!!!
Post by: Viruses on December 17, 2011, 08:00:36 pm
But a lot of other people don't have this problem.. and btw i didn't have to build 2.0 myself i got the bin and lib stuff from a website which had already built it. So I tried everything and linked it and dlled it watever but it still showed the same blank console window. However, one doubt i have is that when i try to use pollevent, it gives me an error but when i use GetEvent it runs fine. Does this mean that this isn't actually 2.0 and maybe i should build 2.0 myself?
Title: SFML Window not showing!!!
Post by: Viruses on December 17, 2011, 09:15:41 pm
YES I FINALLY SOLVED IT!!!!!!!! Someone else had posted a workaround on this forum or something and the workaround was downloading this random dll from a website and putting it in my project directory.

http://www.kn00tcn.net/site/cities-in-motion-startup-crash-fix/


It finally showed up like normal!!However, i scanned this dll and it said no threat but can i be positive that its no threat? The dll is called "atigktxx.dll" . Will this change anything in my code or computer?
Title: SFML Window not showing!!!
Post by: Tex Killer on December 18, 2011, 01:30:21 am
Viruses, might not help, but do you use an ATI card? SFML 1.6 did have a problem with those cards.
Title: SFML Window not showing!!!
Post by: Viruses on December 18, 2011, 02:07:57 am
Well, i went to dxdiag and i went to the device tab. It said " Name: Ati radeon"   and then some number so yea i guess i use ATI. But how would i fix it?
Title: SFML Window not showing!!!
Post by: Tex Killer on December 18, 2011, 03:28:24 am
Just using SFML2 should be enough, I think.
Title: SFML Window not showing!!!
Post by: Viruses on December 18, 2011, 04:39:07 am
I tried building SFML 2.0 and it was too hard. I got errors and stuff..
Title: SFML Window not showing!!!
Post by: Viruses on December 18, 2011, 08:08:14 am
Nevermind got SFML 2.0 to work and it solved the issue. However , there arent many SFML tutorials out there on topics like animation or collistion detection. If you know where i could find basic tutorials BUT ALSO it goes to an advanced level then please let me know.
Title: SFML Window not showing!!!
Post by: Haikarainen on December 18, 2011, 09:06:40 pm
Quote from: "Viruses"
Nevermind got SFML 2.0 to work and it solved the issue. However , there arent many SFML tutorials out there on topics like animation or collistion detection. If you know where i could find basic tutorials BUT ALSO it goes to an advanced level then please let me know.


Dont look for SFML specific tutorials for functions that SFML doesn't directly offer.

For animation; Create a resourcemanager to store images/tiles/animations, use timers , textures(from your resuorcemanager) and sprites to make the magic happen.

For collisiondetection; Either use boxes and check intersection(sf::Rect::Intersects() offer this functionality directly, its easy to do it by yourself however), use circles, OR cache the textures on init and create a collisionmap based off alpha (2d-bool-array is good), and then check them pixels.

Good luck!
Title: SFML Window not showing!!!
Post by: Viruses on December 19, 2011, 12:29:11 am
Well i don't really get frame based animation. I can't find a good tutorial on how to use SetSubRect() for frames. And for collision i can just check if the position is intersecting with another position and then go from there. But the animation part i don't get how to do.

EDIT: I don't get how to do pixel stuff. So how do you even acess pixels?
Title: SFML Window not showing!!!
Post by: Tex Killer on December 19, 2011, 01:49:56 am
Viruses, I think you should try the first collision aproach described by Haikarainen, as you seem new to all of this.

About the SetSubRect, it is described on the tutorials. Basically, you'll make one big image with all the frames of your animation, put a subrect on the region of the image that have the current frame, and change the subrect when time is due for the next frames.
Title: SFML Window not showing!!!
Post by: Viruses on December 19, 2011, 10:36:31 pm
I understand WHAT to do for frame based animation. The only thing i don't get are the parameters. So on the tutorials it said from pixel 10,10 to pixel 20,20 or something. I absolutely didn't get the pixel part. So the parameters confused me.
Title: SFML Window not showing!!!
Post by: Viruses on December 20, 2011, 03:27:57 am
I know this might sound a little noob but i really need a good and basic explanation. This has to do with shaders. First of all, what are shaders? I really need a basic explanation starting from like literally scratch cause the only thing i know about them is that theyre important in game programming and that they have to do with graphics. Second of all , how do you begin to program shaders for your SFML projects? If theres a good beginnner tutorial, please say. And last of all(not really with shaders, or maybe it is) is there any way to import animations or cool effects in SFML? I mean IMPORT, not CODE so make them in another software then import to SFML. If there isn't then how do you do special effects? A really really good example of what i might want is : http://www.youtube.com/watch?v=jDhVwx7bBS4 .    These are like the main questions i've had for some time so please reply and thanks a ton!
Title: SFML Window not showing!!!
Post by: Tex Killer on December 20, 2011, 06:47:10 am
Viruses, that effect combines particles with some image filters... by the looks of it, you seems pretty new to all of this. I think you should begin with easier things, like simple frame-based animations.

About your pixel doubts, a pixel is a point in an image. It is identified as two coordinates: X and Y. The 10, 10 pixel, as you've said, is the point located on the 10th column and 10th line of the image.

By the way, importing game content from external editors into your game (such as animations) should be handled by yourself, unless you use someone's engine instead of making one.
Title: SFML Window not showing!!!
Post by: Viruses on December 20, 2011, 10:56:58 pm
I've often said this in other forums or places. When i ask about effects and advanced topics and how to do it, i dont mean im going to start on that advanced a level just as a beginner. Im obviously going to start with frame based animation. I just wanted to know as a heads up so in the future i could do it. And what is an image filter? And you said i should handle animation from external software by myself. Well, i don't know what file formats SFML can use for animations. So how would i go about doing that? Because in my opinion making an animation in a software meant especially for animations is going to be better than coding the animation. And as i said earlier, i will start with frame based but id still like to know. Thanks again!
Title: SFML Window not showing!!!
Post by: Tex Killer on December 21, 2011, 02:27:34 am
SFML does not handle animations. It handles resource loading, printing and some basic options. You should code the importing of an animation file, if you use one, and let SFML handle the printing of the correct frame at each screen refresh (wich is the correct frame is up to you, as well as where you get it from - here comes SubRect, of wich we talked about earlier).

What you are asking is for some high level features, but SFML is a low level library. All high level stuff should be made on top of SFML.
Title: SFML Window not showing!!!
Post by: Viruses on December 21, 2011, 09:58:20 pm
And how exactly should i go about doing that?(not the code please, just the theory or explanation)
Title: SFML Window not showing!!!
Post by: Viruses on December 21, 2011, 10:44:42 pm
Actually ill worry about shaders later. First, i have a problem with sprites. When making a game where you want a sprite to disappear with an effect or  just disappear when a bullet hits it or something, how do you delete it in runtime? Is there a special function that automatically deletes the sprite when called?
Title: SFML Window not showing!!!
Post by: OniLinkPlus on December 22, 2011, 05:18:43 am
You delete the sprite by not drawing it.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 22, 2011, 11:18:50 am
At every screen refresh (usually 60 per second), you must redraw everything on the screen. If you don't draw something, it will not be on the screen anymore.
Title: SFML Window not showing!!!
Post by: Viruses on December 23, 2011, 12:37:21 am
Ok... But how would you tell it that? Thats what im asking. Is there a special function that does opposite of:

Code: [Select]


screenameorwatever.Draw(spritename);




In this case a sprite is drawn on the screen.
But is there a function that would undraw the sprite from the screen or something?
Title: SFML Window not showing!!!
Post by: OniLinkPlus on December 23, 2011, 01:16:16 am
Quote from: "Viruses"
Ok... But how would you tell it that? Thats what im asking. Is there a special function that does opposite of:

Code: [Select]


screenameorwatever.Draw(spritename);




In this case a sprite is drawn on the screen.
But is there a function that would undraw the sprite from the screen or something?
No, there isn't. You just... don't draw it.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 23, 2011, 04:37:29 am
Make an if, and the sprite will only draw if the requeriments of the if are met.
Title: SFML Window not showing!!!
Post by: Viruses on December 23, 2011, 10:46:00 pm
@OniLink10

Dude you don't understand what i was saying. If you draw a sprite in a game(like in a spaceshooter) then its DRAWN. So if a bullet hits it, it DISAPPEARS and you score a point.. What your saying makes no sense... "You just...dont draw it"  you have to draw stuff for games. So is there something that undraws the sprite?
Title: SFML Window not showing!!!
Post by: Pyrius on December 23, 2011, 10:53:10 pm
Yes, in fact, there is. You have an if statement that checks whether the ship has been hit before drawing it.

EDIT: Oh, and if you aren't already, I recommend clearing the screen every frame and redrawing it. That's what you're supposed to do, and from what you've said it seems you aren't doing this.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 12:37:51 am
And how do i redraw the screen every frame? Every tutorial ive seen so far on SFML, and thats like every tutorial availible, all it does for the "set up" is it makes a while loop and checks for events. So the game loop. I dont know about how to CODE the frame thing.. And also, i cant believe i have to repeat this, I HAVE TO DRAW THE THING ON THE SCREEN AND THEN CHECK IF ITS HIT AND THEN IF IT IS, UNDRAW IT.   Please read that like 5 times and then reply. The if statement doesnt make sense because how will the user know where to hit the enemies if the user cant see it? So it has to be DRAWN first and then UNDRAWN if the enemy is hit..
Title: SFML Window not showing!!!
Post by: Tex Killer on December 24, 2011, 02:14:01 am
Viruses, to clear the screen every frame, use
Code: [Select]
App.Clear(sf::Color(red, green, blue))
About the if, lets see everyting from another perspective:

You must re-draw the "thing" every frame that the "thing" will appear on the screen. It is possible to make an if to check if the "thing" has already been hit, and you only re-draw it if still hasn't. Simply as that.

At the beggining the "thing" will be draw because it was not hit. When it is hit, the if makes the code not draw the "thing" and the "thing" will not be on the screen anymore, since you've already cleared the screen at the start of the current loop.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 04:19:18 am
Okay well i always use App.Clear()... Lol. So ive been clearing the screen 60 times anyways. But i dont get the whole if statement thing you said. Ill give some example code:

Code: [Select]



while(runningstuff)
{
blah blah;

App.Clear();

App.Draw(sprite);

   if(collisiondetectioncode)
   {
     
       BUT WHAT DO I PUT HERE? Is there a function that UNDRAWS the     sprite? THATS THE WHOLE QUESTION IM ASKING!
     


   }

}





So please clarify about "undrawing" or "unloading" the sprite.
Title: SFML Window not showing!!!
Post by: Sam42 on December 24, 2011, 04:33:40 am
The answer has been provided! You're missing the point of what everyone has been saying i'm afraid.

Every frame you blank the screen, draw whatever you want to draw, and then display it. This means that to remove something previously displayed  from the current display, you simply don't draw it anymore.

Code: [Select]

while(running)
{
// events
// logic

App.Clear(); // Blank the screen

   if(collision == false) // If there is no collision
   {
  App.Draw(sprite) // Draw the sprite
   }

   App.Display(); // Finally display what we've drawn this frame
}  


This is very simplistic, and you'll want to do a lot more than that with any actual game object, but it's the idea people have been trying to get across. You only call draw on the sprite during the frame if there is no collision, if there IS a collision, then draw doesn't get called, and the sprite will dissapear from the screen.

You don't actively undraw anything, at any point. Essentially, every frame you want to display a freshly drawn image.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 04:48:53 am
WOW! I get it!  I guess if the other people had provided code it wouldve been better but thank you for clearing that up. And btw, are shaders essential
or necessary for 2D games in SFML or something? Because just about everything confuses me about them. I have very limited knoweledge. So i know im going to have to learn it sooner or later but is it essential for now?
Title: SFML Window not showing!!!
Post by: Tex Killer on December 24, 2011, 06:06:56 am
We've been trying to teach you the logic behind it, so that you can make the code on your own. Giving working code might lead you to simply copy it without learning.

By the way, you don't need to learn shaders at all if you want to use SFML only. Of course, there are things that would not be possible without them, but the basics are provided just well by SFML.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 05:38:54 pm
Ok thank you. I'll stick with the basics for now. There is still one thing im confused about. I know you guys might've already explained it but i dont get it at all. I tried searching it up to no avail. There is only ONE tutorial on this website on SFML 2.0 and its not even about coding. So i have no where to go. Its animation. I dont get the subrect function still. I would appreciate some code and then maybe a screenshot of what it does so that i can see with the code and explanation and screenshot what it actually does. Or if there is another way to animate, please tell me. I would not ask on this forum if i could find any tutorials on it. Thanks!
Title: SFML Window not showing!!!
Post by: Tex Killer on December 24, 2011, 06:50:13 pm
Lets assume that your file have 30 frames, each 100px wide and 200px tall, so your image have width = 3000px, containing all the 30 frames, and height = 200px. You want to make a transition between all these frames with duration of 1 second.

It will be someting like this in current version of SFML 2:

Code: [Select]

...

sf::Clock Timer;
int CurrentFrame = 0;

while (App.IsOpened()) {
    if (Timer.GetElapsedTime() >= 1000 / 30) {
        CurrentFrame++;
        Timer.Reset();
    }
    YourSprite.SetSubRect(sf::Rect<int>(CurrentFrame * 100, 0, (CurrentFrame + 1) * 100 - 1, 200));
    App.Draw(YourSprite);
}

...


1000 / 30 is the aproximate duration, in milliseconds, of each frame. As you can see, you must manage the time and make the correct SubRect at each game loop iteration.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 07:52:18 pm
I still dont get the parameters of subrect... it should only have 2 simple parameters, the width and the height, but it gives me some other crap.
Title: SFML Window not showing!!!
Post by: Pyrius on December 24, 2011, 07:59:47 pm
No, you need the top left point, too. Otherwise the subrect could be anywhere on the image.

Code: [Select]

sf::Sprite::SetSubRect(Left, Top, Width, Height)


Those are the parameters. By the way, although there's only one tutorial, there is documentation. That could be helpful.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 08:14:57 pm
When i do this :    sf::Sprite::SetSubRect(0,0,60,60)     it gives me an error. Im trying to say that the subrect is in the 0,0 pixel or watever in the spritesheet and that the width and height of the subrect is 60. But it doesnt work.
Title: SFML Window not showing!!!
Post by: Pyrius on December 24, 2011, 08:20:34 pm
Can you show me the code? Just the line where you set the subrect.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 09:00:33 pm
Umm nvm i fixed the problem i had to do :  

Code: [Select]
sf::Sprite::SetSubRect(sf::IntRect(0,0,60,60));  

The int rect thingy. but now i have to understand the clock timer and hwo to make it switch frames. The only thing about switching frames i dont get is the "left" and "top" parameters. What does it mean by left or top?  Too general.  And also i need to understand the sf::Clock   functions. GetElapsedTime() and Reset(). I read the documentation but i got lost when it said you multiply the getelap.. by 1000 or something.
Title: SFML Window not showing!!!
Post by: Pyrius on December 24, 2011, 09:14:49 pm
Oops, I forgot about sf::IntRect. Anyways, say you have a 100x100 square. You want to crop the image to a 10x10 sprite in the middle. You would do this:

Code: [Select]

sf::Image image;

if(!image.LoadFromFile("100x100.png")
{
    return 0;
}

sf::Sprite sprite(image);
sprite.SetSubRect(sf::IntRect(45, 45, 10, 10));



The sprite is a rectangle with a height and width of 10, and whose leftmost pixel is at column 45 of the image from the left and whose topmost pixel is at row 45 of the image from the top.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 09:25:20 pm
Ok i see. Thanks!   And the Clock functions?  I don't understand them. When i had :          

Code: [Select]

float time = GetElapsedTime;
cout << time <<endl;




it just gave me a bunch of 1s and 2s. They werent even floats. So i have a few questions:  First, how do you control the time? So how do you code like if 2 seconds pass, go to next frame?  GetElapsedTime() is in seconds or milliseconds? And so far everyone has said that the GetElapsedTime() function gives you the amount of time AFTER the reset(). But what about the first loop?  Because look at this code:

Code: [Select]


sf::Clock clock;

while()
{

do all events and stuff..


clock.GetElapsedTime();
clock.Reset();

}


So after the Reset function it restarts. But what about when its the FIRST time? So the loop begins and sees the function GetElapsedTime().. but it hasnt seen reset yet so what happens?


Please clarify thanks!
Title: SFML Window not showing!!!
Post by: Pyrius on December 24, 2011, 09:35:43 pm
Well, first, you don't time the frames. A frame is one run through the game loop. sf::Clock::GetElaspsedTime() gets the time between when you last reset (or created) the clock and when you call the function. GetElapsedTime() in SFML 1.6 is seconds (float), but in SFML 2.0 it's in milliseconds (UINT32).

EDIT: I mixed up SFML 1.6 and SFML 2.0; changed it.
Title: SFML Window not showing!!!
Post by: Viruses on December 24, 2011, 10:17:59 pm
No..by frame i meant a frame in a spritesheet. So if i wanted to have 1 second before it switched (by using setsubrect) or half a second or so on. How do i manipulate the time?
Title: SFML Window not showing!!!
Post by: Pyrius on December 24, 2011, 11:11:56 pm
Code: [Select]

if(clock.GetElapsedTime() >= 1)
{
    sprite.SetSubRect(sf::Intrect(frame * width, animation * height, width, height));
    ++frame;

    clock.Reset();
}



This would change the frame every second, but try to problem solve on your own sometimes; it's very important in programming. "animation" is for if you have multiple animations in one spritesheet. The first frame would be 0 and the first animation would also be 0.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 25, 2011, 01:53:43 am
The code Pyrius gave now is very similar to the code I gave you earlier, but mine was for SFML 2.0.

Are you reading the documentation? About all of your answers are there, waiting for you to read.
Title: SFML Window not showing!!!
Post by: Viruses on December 25, 2011, 04:21:06 am
I dont like the documentation. Its too hard to find stuff. I find tutorials to be much more useful. And btw i tried the code but I got some messed up blinking really fast image. I tried changing the time but it failed. I didnt get a smooth animation. Here is my code:

Code: [Select]

 if(clock.GetElapsedTime() >= 20)
        {
            sprite.SetSubRect(sf::IntRect(frame * 68,frame2,68,68));
            ++frame;
            clock.Reset();
            if(frame > 5)
            {
                frame = 0;
                ++frame2;

            }
            Window.Draw(sprite);

        }


The "frame2" parameter was because the spritesheet had rows and colums. And then i put an inner if statement to check if the frames were greater than the number of "elements" in the spritesheet. So then it would reset back the frame to 0 and frame2 would be incremented because it was now on the second row, or third row and so on.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 25, 2011, 10:36:08 am
Your Draw call should be out of the ifs. The rest of the logic depends on which version of SFML you are using.

If you are using SFML2, one new frame every 20 milliseconds should be about 50 frames a second. I don't know if this is the speed you are after.

If you are using SFML 1.6, the frame will be changed each 20 seconds, what I find strange.

By the way, your logic was correct this time, except for the Draw part.
Title: SFML Window not showing!!!
Post by: Pyrius on December 25, 2011, 11:04:41 am
You just wrote "frame2", so the animation will move down one pixel when you increment it. Also, it might be easier to write "frame %= totalFrames" and have each animation in the image take up just one row.

Use this to help you get started: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx. Don't just copy and paste, though; I'd recommend making a different game and once the tutorials get more specific to the game he's creating, continue on your own.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 25, 2011, 05:54:42 pm
I havent saw that, sorry. Pyrius is right.
Title: SFML Window not showing!!!
Post by: Viruses on December 25, 2011, 06:39:16 pm
Its still messed up when i set it to 1 second. The spritesheet walks(somewhat) but a black thing comes over the little box in the corner which is the subrect. What i mean is, a black thing keeps flickering through the animation. There is no black in the spritesheet so..
Title: SFML Window not showing!!!
Post by: Anata on December 25, 2011, 06:52:19 pm
Smooth to false for this
Title: SFML Window not showing!!!
Post by: Viruses on December 25, 2011, 08:55:57 pm
Quote from: "Anata"
Smooth to false for this



What...?
Title: SFML Window not showing!!!
Post by: Pyrius on December 25, 2011, 09:13:02 pm
Code: [Select]

sf::Sprite::SetSmooth(false);



You could have checked the documentation to see what Anata meant, or searched the forums (at the top of the page under "SFML forums"). It should take less time to do that than wait for an answer. By the way, in SFML 2.0 smooth is false by default.
Title: SFML Window not showing!!!
Post by: Viruses on December 25, 2011, 10:10:45 pm
I can't see sf::SetSmooth in sfml 2.0 .  And if its default, then whyre you telling me to set it to false if its already there? Im confused..
Title: SFML Window not showing!!!
Post by: Pyrius on December 26, 2011, 12:31:43 am
You're using SFML 1.6.
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 05:21:51 am
Nope. I'm using SFML 2.0 because i use sf:PollEvent and it works. Also, I use another function thats in SFML 2.0. So i use SFML 2.0...
Title: SFML Window not showing!!!
Post by: Pyrius on December 27, 2011, 01:04:06 pm
Huh, I thought I saw sf::Sprite::SetImage() somewhere.... Maybe you've got the parameters of SetSubRect() wrong somehow and you're setting a subrect which doesn't exist completely in the image you loaded? When I do that I get a sort of cyan color, but it might be different from machine to machine. Also, in SFML 2.0, you use sf::Texture and sf::Sprite::SetTexture().
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 07:18:31 pm
Yep i use sf::Texture and sf::SetTexture too. So whatès my problem with the image flickering to black and then normal and then black...?
Title: SFML Window not showing!!!
Post by: Pyrius on December 27, 2011, 08:52:39 pm
Try drawing the image without SetSubRect(). If it's okay, the problem is probably with the parameters of SetSubRect(), and if you can't find the problem, show me the code and I'll try to find it.
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 09:06:56 pm
Without the subrect function, it simply shows the whole spritesheet, no flickering of black thing. The flickering only happens when its animated(using subrect).

Heres my whole program code:
Code: [Select]



#include <SFML/Graphics.hpp>



int main()
{

    sf::VideoMode vmode(800,600,32);
    sf::RenderWindow Window(vmode, "Animation Training");


    sf::Texture texture;
    texture.LoadFromFile("Walker.png");
    sf::Sprite sprite;
    sprite.SetTexture(texture);
    int frame = 0;
    int frame2 = 0;
    sf::Clock clock;



    while(Window.IsOpened())
    {
        sf::Event Event;

        while(Window.PollEvent(Event))
        {
            if(Event.Type == sf::Event::Closed || sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
            {
                Window.Close();
            }
        }

        Window.Clear(sf::Color::Cyan);

        if(clock.GetElapsedTime() >= 100)
        {
            sprite.SetSubRect(sf::IntRect(frame * 68,frame2,68,68));
            ++frame;

            if(frame > 5)
            {
                frame = 0;
                ++frame2;

            }
            if(frame2 > 5)
            {
                frame2 = 0;
            }
            clock.Reset();


        }


        Window.Draw(sprite);


        Window.Display();






    }





    return 0;
}


Oh yes and btw the whole sprite sheet is 340 by 340(in pixels).  And theres 5 columns and 5 rows of images(frames) in the sprite sheet. And frame2 is for when the subrect "moves" to the next row so i increment it by 1 when frame is greater then five and then when frame2 reaches the last frame in the last row and frame also reaches the last image in the last row, they both reset to 0 which restarts the animation process.
Title: SFML Window not showing!!!
Post by: Pyrius on December 27, 2011, 09:17:09 pm
You're moving the subrect down one pixel when frame is greater than 5; you need to move it down 68 pixels. In place of "frame2" if you write "frame2 * 68" it should be fine. Instead of the following:

Code: [Select]

if(frame2 > 5)
{
    frame2 = 0;
}



You can write "frame2 %= 5;". And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 09:28:12 pm
Wow. The animation just got so much better. It wasnt even properly walking lol now it is. However, it didnt solve the black flickering problem. So maybe i thought it was the spritesheet. But when i tried another one, there was no black but it was still flickering..
Title: SFML Window not showing!!!
Post by: Pyrius on December 27, 2011, 09:30:49 pm
Quote
And yes, the problem is with the parameters to SetSubRect(). You're checking if "frame" is greater than 5, which is true when it's 6 or higher. This means you're setting the top left corner to 408, 408.


Did you fix this?
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 10:37:53 pm
Code: [Select]


if(clock.GetElapsedTime() >= 100)
        {
            sprite.SetSubRect(sf::IntRect(frame * 128,frame2 *    128,128,128));
            ++frame;

            if(frame > 4)
            {
                frame = 0;
                ++frame2;

            }
            if(frame2 > 4)
            {
                frame2 = 0;
            }
            clock.Reset();


        }



This is my new code. I just changed the subrect parameters so now frame2 * 128 . Is there anything else i need to change?
Title: SFML Window not showing!!!
Post by: Pyrius on December 27, 2011, 10:52:43 pm
No, keep the "* 68", unless you changed the image size? Anyways, change "if(frame2 > 4){ frame2 = 0; }" to "frame2 %= 5;". You can check if frame is equal to 5 instead of if it's greater than 4; it's more readable.
Title: SFML Window not showing!!!
Post by: Viruses on December 27, 2011, 11:14:00 pm
its "* 128"  because remember i said i tried a new one and the black isnt there anymore but the animation still flickers? Well this one is bigger size so thats why. And i put " frame2 %= 5" and the animation messed up and the flickering was still there. And "frame2 == 5" is basically the same as "frame2 > 4" so.. Maybe it has to do with framerate or something?
Title: SFML Window not showing!!!
Post by: Pyrius on December 28, 2011, 12:00:10 am
"frame2 %= 5" should set frame2 to 0 when it reaches 5. I said to use '==' because it's more readable, not because it should fix anything. Make sure the image width and height are both 640 pixels.
Title: SFML Window not showing!!!
Post by: Tex Killer on December 28, 2011, 12:45:41 am
Viruses, try adding one extra line of code:

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

int main()
{

    sf::VideoMode vmode(800,600,32);
    sf::RenderWindow Window(vmode, "Animation Training");
    Window.EnableVerticalSync(true);
    ...
Title: SFML Window not showing!!!
Post by: Viruses on December 28, 2011, 04:47:59 pm
Still flickering..
Title: SFML Window not showing!!!
Post by: Viruses on December 29, 2011, 05:10:29 am
YES i FINALLY GOT IT NO FLICKERING A PERFECT ANIMATION! The problem was that i was actually drawing a subrect that was out of bounds of the spritesheet which meant it came up blank. Heres the updated code:

Code: [Select]

#include <SFML/Graphics.hpp>



int main()
{
    sf::RenderWindow Window(sf::VideoMode(800,600,32), "asdsad");

    sf::Clock clock;

    sf::Texture pic;
    sf::Sprite sprite;
    int frame,frame2;
    frame = 0;
    frame2 = 0;

    pic.LoadFromFile("SpriteSheet.png");

    sprite.SetTexture(pic);

    while(Window.IsOpened())
    {
        sf::Event Event;

        while(Window.PollEvent(Event))
        {
            if(sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
            {
                Window.Close();
            }


        }

            Window.Clear(sf::Color::Cyan);

            if(clock.GetElapsedTime() >= 100)
            {

                sprite.SetSubRect(sf::IntRect(frame * 128,frame2 * 128,128,128));

                ++frame;

                if(frame == 4)
                {
                    frame = 0;
                    ++frame2;
                }

                if(frame2 == 4)
                {

                    frame2 = 0;
                }

                clock.Reset();

            }





            Window.Draw(sprite);

            Window.Display();








    }


    return 0;
}



So you see i put frame == 4 and frame2 == 4 instead of frame and frame2 == 5. So now i was drawing the frames in the actual sprite sheet, not a subrect beyond it. :D Thanks for all advice i extremely appreciate it!
Title: SFML Window not showing!!!
Post by: Tex Killer on December 29, 2011, 05:14:57 am
Congratulations on solving your own error.  :D
Keep practicing and that will be very common.
Title: SFML Window not showing!!!
Post by: Pyrius on December 29, 2011, 02:33:11 pm
Good job; that's what I was trying to tell you :).
Title: SFML Window not showing!!!
Post by: Viruses on December 29, 2011, 05:10:34 pm
@Pyrius   Lol sorry shoulda looked at your advice more carefully :D   But thanks! Any ideas on how to make my OWN spritesheet?
Title: SFML Window not showing!!!
Post by: Tex Killer on December 29, 2011, 06:04:32 pm
Well, the simplest way would be with paint, but there is also photoshop and a lot others.

By the way, I still recommend you to enable vertical sync, as it would limit the frame rate to the maximum supported by the monitor, avoiding useless processing and image tearing.
Title: SFML Window not showing!!!
Post by: Pyrius on December 29, 2011, 09:37:37 pm
For a walking animation, this is helpful: http://www.manningkrull.com/pixel_art/tutorials/walking.asp. Don't copy it exactly, though, make your own character and follow the general idea. If you copy the legs pixel for pixel with different colors, you won't learn much.
Title: SFML Window not showing!!!
Post by: Viruses on January 01, 2012, 07:35:08 pm
Okay..Does anyone know of a site that has actually good sfml tutorials? Ive searched soooo much and all of the sites explain NOTHING.. I sort of know the basics but i still want to learn more about the sf namespace and such..and dont say documentation because its not like that explains it well.
Title: SFML Window not showing!!!
Post by: Tex Killer on January 01, 2012, 08:04:29 pm
The documentation works just well for myself. What do you expect?

By the way, there is a tutorial on making a complete game here: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx
Title: SFML Window not showing!!!
Post by: Viruses on January 02, 2012, 01:36:02 am
Ive already tried that website...
Title: SFML Window not showing!!!
Post by: Tex Killer on January 02, 2012, 03:00:51 am
So, what happened? Why are you asking for other?
Title: SFML Window not showing!!!
Post by: Viruses on January 02, 2012, 09:13:44 pm
Umm nvm.. I have a problem with coding. So, so far ive been coding in one file, the main.cpp . But ive noticed that when i was programming a game, it got way too confusing for one file. So then i made a class named Player. So now i had Player.h and Player.cpp . There were so much problems that i encountered. I want to organize it is that i will have the functions of Player all in that class. So Move() for example. Display() to display the player. But in order to display the player, you need a renderwindow object . Now this is where i got errors. When i put that Display() took an arguement of sf::RenderWindow()   (i did this arguement because in the main function i would pass my renderwindow object that id already made into the parameters) and therefor it would draw it. But in the header file of Player,   i dont know how to define a function that takes that arguement. I tried putting this:
Code: [Select]
 

void Display(sf::RenderWindow(sf::VideoMode(int,int,int), string);



Then in player.cpp i did this:

Code: [Select]


void Player::Display(sf::RenderWindow(sf::VideoMode(int,int,int), string);




The reason i put int int int and string is because the videomode takes those arguements and the string is for the title. So i got errors. Basically what i need is a way to organize my code into different files. Thats the whole thing. I just gave the above because its the main problem im having is putting variables of sf into the files..Thanks in advance!
Title: SFML Window not showing!!!
Post by: Serapth on January 02, 2012, 09:21:02 pm
That is some pretty fundamental C++ stuff you need to pick up here, people on this forum might be able to help you, but truth of the matter is you are asking the wrong people.

I would suggest you run through a tutorial or two, or pick up a book.  You need to get a bit more comfortable with the basics of C++ before you are really ready for SFML.  Try any of these resources (http://www.gamefromscratch.com/post/2011/08/04/I-want-to-be-a-game-developer.aspx#Cplusplus), the free ones will get you started, although I highly recommend the C++ Without Fear book if you are willing to outlay some cash.  It's one of the best beginner books I've read, although I sped read it as a non-beginner.
Title: SFML Window not showing!!!
Post by: Viruses on January 02, 2012, 09:58:40 pm
Lol ive been through more than 73 tutorials, a book, and other websites and you saying i have to learn the basics.. This is probably one of those things that werent taught so.. and this has to do with sfml. the sf::RenderWindow() parameters..
Title: SFML Window not showing!!!
Post by: Serapth on January 02, 2012, 10:09:54 pm
Quote from: "Viruses"
Lol ive been through more than 73 tutorials, a book, and other websites and you saying i have to learn the basics.. This is probably one of those things that werent taught so.. and this has to do with sfml. the sf::RenderWindow() parameters..



No, it really doesn't.  If you managed to read that many tutorials and they never covered defining functions, let alone classes, you really need to pick different tutorials.


void Display(sf::RenderWindow(sf::VideoMode(int,int,int), string);


That line for example is proof positive that you don't really understand the syntax of defining a member function.  You are combining aspects of a function declaration, implementation and call all in one.  I can't even decipher back to what you were even trying to do.

Coincidentally, if you want to pass a RenderWindow into a method Display you would define it in the .h as:


void Display(sf::RenderWindow&)

Then in the .cpp file, you would declare it as:

void Player::Display(sf::RenderWindow & renderWindow)
{
}

Note the lack of semi colon.  Another mistake in your example ( the semi colon at the end of the implementation ) is telling you need to work a bit more on the basics.  

But hey, whatever, good luck.
Title: SFML Window not showing!!!
Post by: Viruses on January 02, 2012, 11:34:26 pm
Umm i was just about to reply that i searched it up and i actually found that you gotta pass the address. But since i dont get why you cant just do this:

void Display(sf::RenderWindow) in the header file I guess i have to do the basics..
Title: SFML Window not showing!!!
Post by: Tex Killer on January 03, 2012, 12:54:55 am
Viruses, that way your RenderWindow would be copied every time the function is called, and that is not good.
Title: SFML Window not showing!!!
Post by: Vastrolorde on January 03, 2012, 07:12:25 pm
HAving the same problem, i get this console screen that freeses. I  have ATI video card and SFLM 1.6, and i use Code::Blocks. that .dll what was suggested here didnt work for me and SFLM2 i cant fnd, the snapshot of SFLM didnt work for me.
Title: SFML Window not showing!!!
Post by: OniLinkPlus on January 04, 2012, 02:47:11 am
Quote from: "Vastrolorde"
HAving the same problem, i get this console screen that freeses. I  have ATI video card and SFLM 1.6, and i use Code::Blocks. that .dll what was suggested here didnt work for me and SFLM2 i cant fnd, the snapshot of SFLM didnt work for me.
What's SFLM? This is a forum for SFML. ;)

You're experiencing the infamous ATi bug. Wait for SFML2 to be released, or try the static libraries for SFML 1.6.
Title: SFML Window not showing!!!
Post by: Viruses on January 05, 2012, 04:22:05 pm
Yoo dude i had the same problem i got the SFML 2.0 snapshot and built it with Cmake. If you dont know what im talking bout,just search it up on youtube or google. It worked perfectly for me!