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

Author Topic: Why is Render Window appearing blank?  (Read 4410 times)

0 Members and 1 Guest are viewing this topic.

tonyd5

  • Newbie
  • *
  • Posts: 3
    • View Profile
Why is Render Window appearing blank?
« on: October 05, 2015, 04:03:32 am »
Hi I'm pretty new to sfml and new to this forum so this might be a stupid question...

     I'm gradually adding functionality and objects to Render Window.

     Then, every so often the window will appear as blank when I run the code.

     Begins to happen more and more frequent as keep adding objects to the window.

I fixed the issue by having the window open on a button press event vs opening as soon main() starts running.

What I think is happening is that the code that is setting up the all the object positions and behavior is taking to long and the window gets stuck at event poles that include code dependent on objects and variables that are still in process of being declared.

^^Is that what is happening? Should I include some sort of delay mechanism before displaying a Render Window as a good practice?


I have screen shots attach to show what I am talking about.





Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Why is Render Window appearing blank?
« Reply #1 on: October 05, 2015, 07:14:38 am »
Please provide a minimal complete example.

Make sure you adhere to the clear-draw-display cycle as outlined in the tutorial. It must be followed.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

tonyd5

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Why is Render Window appearing blank?
« Reply #2 on: October 06, 2015, 01:52:49 am »
The code for this window is a thousand lines or so... But this is how it is laid out:

int main()
{

       win=sf::RenderWindow("name",----);

       /*  Do many more things  */       

     
       while(1)
       {
                 void Pole_Events_for_Window_Function(sf::RenderWindow& win, &(many more varables));

                 /*  Pole_Events for other windows   */

        }

}


void Pole_Events_for_Window_Function(sf::RenderWindow& win, &(many more varables))
{
        /* Do a millions things */
   
        win.clear();

        win.draw( for many objects);

        win.display()

}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Why is Render Window appearing blank?
« Reply #3 on: October 06, 2015, 03:35:43 am »
As a programmer you won't get very far if you can't be bothered to read stuff that has been said in tutorials or in linked threads.

Nexus asked you to provide a complete and minimal example and he even gave you the link right to what you need to read. You didn't even do that.... your code is neither complete or minimal.

He also mentioned something else that may cause your issue. If you read the mentioned tutorial regarding the drawing cycle you will see a huge difference between your code and the tutorial code. Try to see if you can find the difference (hint, it has something to do with polling events).
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Why is Render Window appearing blank?
« Reply #4 on: October 07, 2015, 06:35:26 pm »
it seems that you forgot to dispatch window messages  :)

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Why is Render Window appearing blank?
« Reply #5 on: October 08, 2015, 12:12:08 am »
it seems that you forgot to dispatch window messages  :)

Please stop trying to answer these C++ questions if you have never used SFML outside of the SFML.Net binding. Window.DispatchEvents() is exclusive to the SFML.Net binding.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Why is Render Window appearing blank?
« Reply #6 on: October 08, 2015, 01:21:51 am »
it seems that you forgot to dispatch window messages  :)

Please stop trying to answer these C++ questions if you have never used SFML outside of the SFML.Net binding. Window.DispatchEvents() is exclusive to the SFML.Net binding.

Actually I means call to the Window.pollEvent...
So, C++ version allows to omit this call and it will not affect window behavior?
It very interest, so how message pump works in C++ version if there is no one call from the main loop?
Window message queue should be processed from the main thread...

Usual C++ message pump looks something like this:
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
}
 

for game loop it's better to use PeekMessage instead of GetMessage.

And it actually what I means when I talking about "dispatch window messages". DispatchMessage is not related to C# it's windows API

I'm not sure about OpenGL, but Direct3D actively uses window messages for monitoring window state and send's some messages. So, if message pump didn't works, your Direct3D application also will not works properly. I think that OpenGL uses the same approach with window subclassing...
« Last Edit: October 08, 2015, 01:38:24 am by mkalex777 »

tonyd5

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Why is Render Window appearing blank?
« Reply #7 on: October 08, 2015, 02:01:22 am »
Ok i'm going to rephrase this question.

Most of the time the window opens and display everything correctly. Every once in a while it will appear as a blank window even though there are no changes in the code. Has anyone ever seen or heard of this, or has an idea of what could cause this so. I fixed the problem by delaying the window display until I click on a GUI button I made, which is how I wanted it to prompt anyway.

The code associated with this window is spread across 5 header files. I'm pretty sure you don't want to sift through 10 pages code. I assure you the pollevents->clear->draw->display routine is there, that is not the problem.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Why is Render Window appearing blank?
« Reply #8 on: October 08, 2015, 03:39:32 am »
-Code.. I think?-

What in the name of all that is holy are you talking about? Absolutely nothing you have mentioned in this thread has anything to do with the question at hand.

I dont mean to make this a personal attack but I have seen some of your other threads and messages and it seems you have a very very loose grip on C++ and SFML so please for the love of god can you refrain from "answering" questions you know nothing about?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Why is Render Window appearing blank?
« Reply #9 on: October 08, 2015, 07:50:20 am »
When the window is white do you get any output on the console?

Also we don't want to see your current code base, instead you should throw out any none essential parts while making sure that the issues still occurs. That way you get a minimal (one file) and compilable (no need for any code addtions) example everyone can test. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything