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

Author Topic: sf::View leaves screen black  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

Ninjaboi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.ninjasoftcorp.webs.com/index.html
sf::View leaves screen black
« on: January 24, 2012, 04:51:48 am »
I've been working with a 2D platformer, and have been trying to implement a view in the screen. I was able to do it in SDL rather easily, though in SFML I've been trying to use sf::View in order to create a view and then set the view in the window. However, whenever I try to set a view other than the default the window has, the screen is black ( when there should be a rendered character centered on the view ). I'm not sure if it's a problem with keeping the view alive, or that it's not allowing me to blit to the screen, but I've tried hacking at it for hours to no avail.

My code:

Code: [Select]

// First level of the game.
int Game::Level1()
{

// The center view of the camera.
sf::Vector2f CenterView( ( Jim_Character.GetXPosition()
                                             + (float)11.5 ),
   ( Jim_Character.GetYPosition()
                                             + (float)20 ) );

// Half the total size of the view.
sf::Vector2f HalfSizeOfView( 400, 300 );

//The camera view for the game.
sf::View Camera( CenterView, HalfSizeOfView );

// Sets the view to center Jim.
MainWindow.SetCameraView( Camera );

// Loop while MainWindow is still open.
while( MainWindow.IsOpen() )
{

// Loop and process events ( if any ) in queue.
while( MainWindow.GetEvents() )
{

// Perform if the user clicks the red 'X'.
if( MainWindow.WindowEventsType() == "Closed" )
{

// Close the main window.
MainWindow.CloseWindow();

}

// Perform if the user pressed the "Esc" key.
if( MainWindow.KeyboardKeyPressed() == "Escape" )
{

// Sets the default view on the window.
MainWindow.SetDefaultCameraView();
// Return to the main menu.
MainMenu();

}

// Perform if the user pressed the "A" key.
if( MainWindow.KeyboardKeyPressed() == "A" )
{

// If Jim is not trying to go outside the level.
if( Jim_Character.GetXPosition() > 0 ||
Jim_Character.GetXPosition() == 0 )
{

// Start moving Jim left.
Jim_Move_Left = true;

}

}

// Perform if the user pressed the "D" key.
if( MainWindow.KeyboardKeyPressed() == "D" )
{

// If Jim is not trying to go outside the level.
if( ( Jim_Character.GetXPosition() + 33 ) < Level_1_Width )
{

// Start moving Jim right.
Jim_Move_Right = true;

}

}

// Perform if the user released the "A" key.
if( MainWindow.KeyboardKeyReleased() == "A" )
{

// Start moving Jim left.
Jim_Move_Left = false;

}

// Perform if the user released the "D" key.
if( MainWindow.KeyboardKeyReleased() == "D" )
{

// Start moving Jim right.
Jim_Move_Right = false;

}

}

// If Jim is to be moved to the left.
if( Jim_Move_Left == true )
{

// If Jim is not trying to go outside the level.
if( Jim_Character.GetXPosition() > 0 ||
Jim_Character.GetXPosition() == 0 )
{

// Move him to the left 4.
Jim_Character.MovePositionX( -.50f );

}

}

// If Jim is to be moved to the right.
if( Jim_Move_Right == true )
{

// If Jim is not trying to go outside the level.
if( ( Jim_Character.GetXPosition() + 33 ) < Level_1_Width )
{

// Move him to the left 4.
Jim_Character.MovePositionX( .50f );

}

}

// Renders the load game graphic.
MainWindow.Render( Jim_Character.GetSprite() );

// Clears and updates window with new data.
MainWindow.Update();

}

// The program exits successfully, and the main window is closed.
return 0;

}


Note that I use a wrapper library I made myself that incorporates SFML 1.6 ( as well as several other smaller libraries + obvious heavy additions of my own ). Therefore, some of the code above will do things that SFML does, as well as other things too. The comments should be enough to clear up any misunderstanding though, but if not I can certainly clarify. If any more code needs to be added, just ask. I would cut some irrelevant code out of the state function, but I thought it would be better to see what it's supposed to do as a whole.

falconmick

  • Newbie
  • *
  • Posts: 17
    • View Profile
sf::View leaves screen black
« Reply #1 on: January 24, 2012, 07:43:50 pm »
I'm assuming you have an ATI card... ATI cards are stuffed atm for allota games, inc the graphics part of SFML

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
sf::View leaves screen black
« Reply #2 on: January 24, 2012, 09:00:56 pm »
The ATI problem, as far as I'm concerned, only happens on SFML 1.6.

If that is the case, using SFML 2.0 would solve the issue, but you would have to change some things on your code, specially if the new camelCase convention is adopted.

Ninjaboi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.ninjasoftcorp.webs.com/index.html
sf::View leaves screen black
« Reply #3 on: January 25, 2012, 03:48:19 am »
I've tested it on a machine with an NVIDEA GeForce 8200, as well as several other systems with integrated Intel video chipsets, same thing happens. Though I've wanted to upgrade to SFML 2.0, I've gotten used to 1.6 and have already started the project with it. I don't mind converting my existing code for 2.0, but only if I have to due to problems with 1.6. After this project I was already going to make the switch, but was hoping to finish this one before so.

Ninjaboi

  • Newbie
  • *
  • Posts: 13
    • View Profile
    • http://www.ninjasoftcorp.webs.com/index.html
sf::View leaves screen black
« Reply #4 on: January 26, 2012, 07:02:51 am »
Sorry for the double-post, but should I make the conversion to SFML 2.0 inside my library for my project? I have several parts of it made heavily with SFML 1.6, so it would take several hours to redo those parts to work with the rest of the library. I'd like to finish this project before making such a task done, but if there's no other way then I'll do it. Right now this is stopping progress in it's tracks, so I'm hoping to resolve this sooner rather than later ( not to sound pushy in the least, I'm referring to myself more than anything ).

I have a personal deadline to meet, with an actual deadline coming at the end of the week. So, I do want to resolve this in that it is either my mistake in design or implementation, or that it's a problem with the current version of the SFML library I'm using.