Semestre 02, 2026
El ciclo principal que ejecuta cualquier aplicación gráfica o videojuego.
Logra la ilusión de movimiento e interactividad en tiempo real.
Sin el render loop, las aplicaciones gráficas serían estáticas. Con el loop:
En cada iteración del loop se realizan 3 pasos principales:
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Antes del loop se crea la ventana y se cargan los recursos: texturas, modelos y shaders.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
El ciclo se repite frame tras frame hasta que el usuario cierra la ventana.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Se procesan las entradas de teclado, mouse y controladores de esta iteración.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Se actualiza el estado: posiciones de los objetos, físicas y animaciones.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Se dibuja la nueva escena en el framebuffer con el estado ya actualizado.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Se intercambia el framebuffer actual con el próximo para mostrar el frame sin parpadeos.
init_window(width, height)
while not window_should_close():
process_input()
update_scene()
render_frame()
swap_buffers()
limit_framerate()
Se limita el framerate con vsync o retrasos manuales para mantenerlo estable.
El render loop escucha eventos de entrada:
Cambia entre el framebuffer actual y el próximo. Evita parpadeos (flickering).
Mantiene un framerate estable con vsync o retrasos manuales.
Cada frame dispone de un tiempo fijo, que comparten input, update y render.
$$t_{frame} = \frac{1000\ \text{ms}}{\text{FPS}}$$Si el trabajo de un frame excede su presupuesto, los FPS bajan y aparece el stutter.
Escalar el movimiento por delta time: el tiempo transcurrido desde el frame anterior.
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
Antes del loop guardamos el tiempo inicial como referencia.
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
Al inicio de cada frame tomamos el tiempo actual.
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
Delta time es cuánto tiempo pasó desde el frame anterior.
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
Guardamos el tiempo actual para calcular el dt del siguiente frame.
last_time = now()
while not window_should_close():
current_time = now()
dt = current_time - last_time
last_time = current_time
x += velocidad * dt
render_frame()
Al escalar por dt, la velocidad es constante en tiempo real sin importar los FPS.
limit_framerate evita que el loop consuma el 100% de CPU y GPU sin control.
Sincroniza el swap con el refresco del monitor (p. ej. 60 Hz). Elimina el tearing, pero limita los FPS al refresco.
Duerme (sleep) el tiempo sobrante del presupuesto de frame. Da control fino del ritmo, pero no elimina el tearing por sí solo.
El render loop es lo que envuelve el raycaster o raytracer.