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

Author Topic: Image Not Showing  (Read 3861 times)

0 Members and 1 Guest are viewing this topic.

Auron

  • Newbie
  • *
  • Posts: 15
    • MSN Messenger - videogamefreak101@hotmail.com
    • View Profile
Image Not Showing
« on: August 05, 2009, 07:10:40 pm »
Hey Guys,

I went through the examples and tried displaying an image on the screen, but it won't shop up. My code is right and it compiles without errors, but the window is blank. Here's my code.

Code: [Select]

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <wchar.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>

#include "player.h"
#include "vehicle.h"

int main()
{
    sf::RenderWindow App(sf::VideoMode(800,600,32), "Car Junker - DarkScar Games");
   
    const sf::Input& Input = App.GetInput();
   
    bool Logo_Screen = true;
    bool Title_Screen = false;
   
    sf::Image TitleScr;
    sf::Image LogoScr;
   
    if(!TitleScr.LoadFromFile("Title.png"))
    {
        return EXIT_FAILURE;
    }
    sf::Sprite TitleSprt(TitleScr);
   
    if(!LogoScr.LoadFromFile("Logo.png"))
    {
        return EXIT_FAILURE;
    }
    sf::Sprite LogoSprt(LogoScr);
   
    LogoSprt.SetImage(LogoScr);
   
    bool LeftKeyDown = Input.IsKeyDown(sf::Key::Left);
    bool RightKeyDown = Input.IsKeyDown(sf::Key::Right);
    bool UpKeyDown = Input.IsKeyDown(sf::Key::Up);
    bool DownKeyDown = Input.IsKeyDown(sf::Key::Down);
    bool SpaceDown = Input.IsKeyDown(sf::Key::Space);
    bool LeftMouseDown = Input.IsMouseButtonDown(sf::Mouse::Left);
    bool RightMouseDown = Input.IsMouseButtonDown(sf::Mouse::Right);
    unsigned int MouseX = Input.GetMouseX();
    unsigned int MouseY = Input.GetMouseY();
   
    Player* gPlayer = new Player();
    Vehicle* gVehicle = new Vehicle();
   
    sf::Clock Clock;
   
    while(App.IsOpened())
    {
        sf::Event Event;
       
        App.SetFramerateLimit(60);
       
        while(App.GetEvent(Event))
        {
           
            if(Event.Type == sf::Event::Closed)
            {
                App.Close();
            }
           
            if(Event.Key.Code == sf::Key::Escape)
            {
                App.Close();
            }
           
            if(Event.Key.Code == sf::Key::Left)
            {
                LeftKeyDown = true;
                gPlayer->X = gPlayer->X - 5;
            }
            else if(Event.Key.Code == sf::Key::Right)
            {
                RightKeyDown = true;
                gPlayer->X = gPlayer->X + 5;
            }
            else if(Event.Key.Code == sf::Key::Up)
            {
                UpKeyDown = true;
                gPlayer->Y = gPlayer->Y - 5;
            }
            else if(Event.Key.Code == sf::Key::Down)
            {
                DownKeyDown = true;
                gPlayer->Y = gPlayer->Y + 5;
            }
        }
       
        App.Draw(LogoSprt);
       
        App.Clear(sf::Color(0,0,0,0));
       
        App.Display();
    }
   
    return EXIT_SUCCESS;
}

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Image Not Showing
« Reply #1 on: August 05, 2009, 07:56:13 pm »
http://www.sfml-dev.org/wiki/en/faq#my_sprite_isn_t_displayed_but_a_white_square ( ? )

About your code :
-> you should use the C++ version of time.h, math.h, ... : ctime, cmath, c... . Exept for string.h. You should use std::string instead of char* ( from string header ) .
-> here you need only SFML/Graphics.hpp and cstdlib. ( You don't the other ones. )
-> there are two new, but no delete.
-> you should create more function.
and more.
SFML / OS X developer

Auron

  • Newbie
  • *
  • Posts: 15
    • MSN Messenger - videogamefreak101@hotmail.com
    • View Profile
Image Not Showing
« Reply #2 on: August 05, 2009, 08:25:39 pm »
Ah, ok, I'll try re-working my code.

EDIT: I used SetImage(), but nothing is still displayed on the screen.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image Not Showing
« Reply #3 on: August 05, 2009, 10:50:01 pm »
You're testing Event members without first checking which type of events it is. So you may, for example, retrieve the event's key code when it is a MouseMove event (which results in undefined behaviour).
Laurent Gomila - SFML developer

Auron

  • Newbie
  • *
  • Posts: 15
    • MSN Messenger - videogamefreak101@hotmail.com
    • View Profile
Image Not Showing
« Reply #4 on: August 06, 2009, 05:26:26 am »
Ah, ok, I need read the docs more carefully then.

forrestcupp

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Image Not Showing
« Reply #5 on: August 07, 2009, 09:26:52 pm »
You're clearing the screen after you draw things.  That's why you don't see anything on the screen.

Also what Laurent said about the event checking is pretty obvious, too.

Auron

  • Newbie
  • *
  • Posts: 15
    • MSN Messenger - videogamefreak101@hotmail.com
    • View Profile
Image Not Showing
« Reply #6 on: August 08, 2009, 10:35:56 pm »
Yes, I am working on it. I have a got an image to show up on the screen. I just need to work with the SFML library more to get the hang of things.