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

Author Topic: Just Declaring a View Makes Screen Blank  (Read 1639 times)

0 Members and 1 Guest are viewing this topic.

memerson.d

  • Newbie
  • *
  • Posts: 4
    • View Profile
Just Declaring a View Makes Screen Blank
« on: August 05, 2019, 09:29:01 pm »

I am using the below code to display a map. However, when I uncomment the mainView declaration, all my graphics disappear. This occurs even if I do not call setView on my window.

I know the view needs arguments to work correctly, but I removed them just messing around to see if anything would work. Why are things changing without calling setView? any ideas?

Quote
int main()
{


   //Get Window Size

   int screenWidth = sf::VideoMode::getDesktopMode().width;
   int screenHeight = sf::VideoMode::getDesktopMode().height -22;



   //Create Window
   sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

   window.setSize( sf::Vector2u(screenWidth, screenHeight) );
   window.setPosition( sf::Vector2i(0, 0) );


   //sf::View mainView;


   //window.setView(mainView);

   //Init Game

   Map map;

   map.initMap();

   //Main loop
   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         //Window Closed
         if (event.type == sf::Event::Closed)
            window.close();      
      }

      //Drawing
      window.clear();

      map.drawMap(window);

      window.display();
   }

   return 0;
}

memerson.d

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Just Declaring a View Makes Screen Blank
« Reply #1 on: August 05, 2019, 10:20:26 pm »
So an update:

The view works correctly with the circle example given in the tutorial, but the circle is only drawn if I don't declare my Map class.

I went through and commented out all the SFML functions in my Map class, and the draw event, but just having the Map object in my Main file makes the circle not render.

At this point my Map class is essentially just a 2d array being constructed so I am not sure why it would affect the rendering of anything (It had a vertex array as well before I commented it out).

The reverse seems to be true as well. If I have the circle declared, my map will not render, even if I do not draw the circle.


Is there any chance this is because I have included Graphics.hpp in both files?
« Last Edit: August 05, 2019, 10:44:37 pm by memerson.d »

Hapax

  • Hero Member
  • *****
  • Posts: 3381
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Just Declaring a View Makes Screen Blank
« Reply #2 on: August 06, 2019, 05:02:44 pm »
The view is empty. Try assigning a shape (size and centre) first.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

memerson.d

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Just Declaring a View Makes Screen Blank
« Reply #3 on: August 06, 2019, 11:21:50 pm »
I have done that. I think I mentioned in my first post that it does not have any arguments in this example because I removed them while just messing with the code trying to get something to work.

A point I was trying to make was that just declaring the view:
Quote
sf::View mainView;
and then doing nothing else at all with it, would stop anything from rendering, which is very odd to me. I would guess that I would have to at least call setView for anything to change, but that doesn't appear to be the case.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Just Declaring a View Makes Screen Blank
« Reply #4 on: August 07, 2019, 07:56:53 am »
As long as we don't see your Map class, we can't help much. And don't post it directly, try to find the most minimal piece of code that reproduces the problem (remove unnecessary variables and functions) ;)
Laurent Gomila - SFML developer

 

anything