handmade.network » Forums » Application rendering
MattHartley
Matt Hartley
19 posts
I like to program the things.
#12410 Application rendering
5 months, 1 week ago

I'm struggling to find good resources about how application rendering(as opposed to game rendering) is done.

Obviously you don't want to be updating the screen all the time for no reason. Do applications typically update the screen whenever they receive input? Do they update only the sections of the screen that have been affected?

I assume if you use the OS's api to create the default OS ui elements it handles the rendering and refreshing for you. But if you want to use something like OpenGL to do a custom ui, what are some good strategies for updating the screen and using minimal cpu?

Thanks.
Telash
Mikael Johansson
52 posts
1 project
#12412 Application rendering
5 months, 1 week ago

Personaly I use an update flag (or bool if you prefer). As soon as something happens that should update, you just set the flag, then let all the render fuctions do their magic, and clear the flag.

I would not think about rendering only part of the screen until its actually needed, like for example for a fading blinking cursor.

The biggest obstacle to great software is lack of motivation. Motivate each other!
ratchetfreak
322 posts
#12414 Application rendering
5 months, 1 week ago

One way of looking at deciding when and what to redraw is as a cache invalidation problem.

What's on screen is a cached version of the program state.

Sometimes the OS discards part of your window and requests a redraw by sending an event into the queue, you can also request such an event to be sent. The OS will combine multiple requests for a redraw into a single event for the combined area.

When part of the screen needs to change the widget library will request a redraw for the part of the screen that needs to change in response to the call from the user.

The blinking cursor is a special case where they use something called xor mode where you overdraw an image and it transforms the pixels you draw over. If you draw the exact same thing again you end up with the original pixels back.