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

Author Topic: Window doesn't display  (Read 2368 times)

0 Members and 1 Guest are viewing this topic.

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Window doesn't display
« on: June 15, 2009, 02:06:45 pm »
I am trying to make a some kind of tetris game and i'm having a problem with my window. This is my code. It might be a little long but its very easy to understand.

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

sf::RenderWindow Tetris(sf::VideoMode(800, 600, 32), "Dedris");


class Piece
{
public:

float BlockHeight;
float BlockWidth;
sf::Sprite mySprite;
};

class Cube : public Piece
{
public:
Cube(std::string CubeFile, sf::Image& ImageCube)
{
mySprite.SetImage(ImageCube);
sf::Vector2f SprSize = mySprite.GetSize();
BlockWidth = SprSize.x / 2;
BlockHeight = SprSize.y / 2;
mySprite.SetPosition(Tetris.GetWidth() / 2 - BlockWidth, 1);
}
};

class L : public Piece
{
public:
L(std::string LFile, sf::Image& ImageL)
{
mySprite.SetImage(ImageL);
sf::Vector2f SprSize = mySprite.GetSize();
BlockWidth = SprSize.x / 2;
BlockHeight = SprSize.y / 3;
mySprite.SetPosition(Tetris.GetWidth() / 2 - BlockWidth, 1);
}
};

class backL : public Piece
{
public:
backL(std::string backLFile, sf::Image& ImageBackL)
{
mySprite.SetImage(ImageBackL);
sf::Vector2f SprSize = mySprite.GetSize();
BlockWidth = SprSize.x / 2;
BlockHeight = SprSize.y / 3;
mySprite.SetPosition(Tetris.GetWidth() / 2 - BlockWidth, 1);
}
};

class I : public Piece
{
public:
I(std::string IFile, sf::Image& ImageI)
{
mySprite.SetImage(ImageI);
sf::Vector2f SprSize = mySprite.GetSize();
BlockWidth = SprSize.x;
BlockHeight = SprSize.y / 4;
mySprite.SetPosition(Tetris.GetWidth() / 2 - BlockWidth, 1);
}
};

class T : public Piece
{
public:
T(std::string TFile, sf::Image& ImageT)
{
mySprite.SetImage(ImageT);
sf::Vector2f SprSize = mySprite.GetSize();
BlockWidth = SprSize.x / 3;
BlockHeight = SprSize.y / 2;
mySprite.SetPosition(Tetris.GetWidth() / 2 - BlockWidth, 1);
}
};

int main()
{

sf::Event Termino;
while (Tetris.IsOpened())
{
while (Tetris.GetEvent(Termino))
{
if (Termino.Type == sf::Event::Closed)
Tetris.Close();

if ((Termino.Type == sf::Event::KeyPressed) && (Termino.Key.Code == sf::Key::Escape))
Tetris.Close();
}

sf::Image PieceImg1;
if (!PieceImg1.LoadFromFile("D:\\C++\\I.jpg"))
goto LoadError;
Cube myCube("D:\\C++\\cube.jpg", PieceImg1);

sf::Image PieceImg2;
if (!PieceImg2.LoadFromFile("D:\\C++\\I.jpg"))
goto LoadError;
L myL("D:\\C++\\L.jpg", PieceImg2);

sf::Image PieceImg3;
if (!PieceImg3.LoadFromFile("D:\\C++\\I.jpg"))
goto LoadError;
backL myBackL("D:\\C++\\LBack.jpg", PieceImg3);

sf::Image PieceImg4;
if (!PieceImg4.LoadFromFile("D:\\C++\\I.jpg"))
goto LoadError;
I myI("D:\\C++\\I.jpg", PieceImg4);

sf::Image PieceImg5;
if (!PieceImg5.LoadFromFile("D:\\C++\\I.jpg"))
goto LoadError;
T myT("D:\\C++\\T.jpg", PieceImg5);

sf::Sprite* show;
int random = sf::Randomizer::Random(1, 5);
switch(random)
{
case 1:
{
show = &(myCube.mySprite);
break;
}
case 2:
{
show = &(myL.mySprite);
break;
}
case 3:
{
show = &(myBackL.mySprite);
break;
}
case 4:
{
show = &(myI.mySprite);
break;
}
case 5:
{
show = &(myT.mySprite);
break;
}
Tetris.Clear();
sf::Clock my4Clock;
(*show).Move(0, 10);
while (my4Clock.GetElapsedTime() < 1.f);
my4Clock.Reset();
Tetris.Draw(*show);
Tetris.Display();
}
}
return 0;
LoadError:
return EXIT_FAILURE;
}

Help would be appreciated.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Window doesn't display
« Reply #1 on: June 15, 2009, 02:32:10 pm »
And what's your problem?
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Window doesn't display
« Reply #2 on: June 15, 2009, 04:11:57 pm »
My window doesn't display. All i can see is the blue title bar with the usual close, maximize, minimize buttons and nothing in the middle. Not even the usual black screen.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Window doesn't display
« Reply #3 on: June 15, 2009, 07:23:41 pm »
Some advice:

1. Do not use goto. In most cases, there is no reason to use it. The goto keyword interrupts your program flow, often leading to unexpected results (so-called spaghetti code).

2. Initialize your graphics once instead of every loop frame, which is extremely inefficient (especially loading images).

3. Structure your code, watch your indentation. Some of your code is never executed. This is also the cause of your error.

4. Use a debugger. By stepping through the program you can find out what's wrong in less than a minute.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: