Thats cause you use glfwPollEvents. If you only want to update when there is input, you need to use glfwWaitEvents.
The color of the window blinks repeatedly
2 hours ago, wintertime said:glfwWaitEvents.
Yes, it solved the issue and demonstrated that one frame is enough for that result. Thanks.
But would you please answer other questions I ask above too.
5 hours ago, test opty said:By the way, does this convey that OpenGL is mostly for developing games?
It mostly is for the development of software. Considering this is a game development site and that games are the most common real time software then it is only natural to assume your making a game.
5 hours ago, test opty said:I used the statements without the loop (removed the loop) but the resulting window is shown and immediately vanishing!
That is because you told it to run the code only once.
The code starts from the top and does everything once. With out your loop running the code, it only works once and is done. Your whole computer is running on loops like this, even as you read this.
5 hours ago, test opty said:It showed different values, say, from 75, 97 to 137 or over!
Yes that is how many times that loop can run on your computer. People with better computers will be able to run the loop many times more.
In short if I tell my computer do do something it will do it as many times as possible. That is why if you play old games without Vsync they run faster than you can play them.
5 hours ago, test opty said:That is, we have many iterations, just for a simple window! It's also strange for me.
Your loop tells it to fire the code when ever it can and so it will. You could limit the loop to running only once a second or what ever you feel like.
Software don't update everything every second, this is just a beginner program and you will get into more advance things as you move forward. For this reason if you monitored OpenGL's output you will often see the game running at 60fps and the menu's at around 8-12 fps.
If your wondering why computers work in these kinds of loops, it's so they can deal with huge amounts of repetitive tasks. There are old computers that worked with cranks, you would have had to turn the crank by hand to run a loop on the computer.
A Abacus is a computer that only updates when the user let's it. We just now power our modern Abacus with electricity.
On 12/4/2017 at 5:25 PM, Scouting Ninja said:Yes that is how many times that loop can run on your computer. ...
In short if I tell my computer do do something it will do it as many times as possible. That is why if you play old games without Vsync they run faster than you can play them.
I got all the other stuff except this part. First off, thanks.
Well, each frame is our resulting window and presumably every iteration copies the same frame as the prior one on the window! That is, coping equal frames onto each other! It does so because using the loop we tell it so. It's an infinite loop and if I don't close the window it should run forever! OK. But why 97 times or 137 or so while I haven't close the window, please?
On 12/5/2017 at 8:27 PM, test opty said:But why 97 times or 137 or so while I haven't close the window, please?
A bit confusing what your asking here.
First Vsync doesn't do the task 94-137 times. It limits it to as much your screen can do every frame. Because often your screen can't refresh as fast as the computer does. So the Vsync pauses the calculations and waits, making the image more stable.
If your asking why computers run at hundreds of loops per second, then think of it like this. My crank computer adds one to a value: value = value+1; so it's 1,2,3,4,5,6 etc. every time I crank.
Now if I wanted to count to a million I would need to crank it a million times. Instead I remove the crank and add a water wheel, I place the computer next to a river and now the river counts for me. Every time the wheel turns my value counts 7,8,9,10 ,11 etc.
When I stop my water flow using slice gates it stops the counter.
I want more speed so I remove my water wheel and add a electric motor. Now I am getting hundreds of turns per second. I also can cut my power to the wheel to stop it. This is a electric computer, like you are using now.
Except yours was build by brilliant people who perfected the systems over time and as a result we can run loops inside loops and use math for graphics.
Drivers tells your computer when to restrict the flow of electricity or when to open the gates as large as they can. That is why a AAA game causes the computer to heat up.
Your operating system also runs in loops like this and your software is often a loop inside the loop of a operating system.
Thank you. I got many things from your answer. There was some misunderstanding, but it got solved now.
The picture seems very meaningful but I can't read the text. Where can I find it's large size to read them please?
8 minutes ago, test opty said:The picture seems very meaningful but I can't read the text. Where can I find it's large size to read them please?
Sorry about that, it was a Pinterest image so you need a Pinterest account to see it at full quality. This is one I found with a quick image reverse search.
Hi, another question:
This function:
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
is called by this statement: glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); Here the parameters width and height aren't set, so how does the function above set its arguments to be used by glViewport?