这是indexloc提供的服务,不要输入任何密码
Skip to content

ImDrawList coding party - deadline Nov 30, 2020! #3606

@ocornut

Description

@ocornut

ImDrawList coding party!

  • create small visual effects
  • 1024 bytes of source code
  • 320x180 output
  • only use dear imgui's crappy low-level shape drawing api

Two days ago I thought:
"It'd be fun to organize a contest for writing special effects using the ImDrawList api, with a constraint on source code size. May be fun to see what people can come up with using shape/vector-based api (quite different from a pixel-shading function). Would you participate?"

It's by no mean a great api but it has served many well, to draw custom widgets etc, let's get it some extra love..

Here's a testbed imdrawlist_party.cpp which you can paste in your application or any dear imgui example:
https://gist.github.com/ocornut/51367cc7dfd2c41d607bb0acfa6caf66

Rules:

  • Your source file fx.inl must be <= 1024 bytes.
  • Effect should be reasonably portable (not relying on specific render backend callback)
  • OK to use preprocessor define or other tricks as long as they are reasonably portable.
  • Included are: math.h, imgui.h, imgui_internal.h with ImVec2 maths operators
  • The effect should not use ImGui:: functions, only use ImDrawList facilities.
  • Canvas ratio is expected to be 16/9, canvas size expected to be 320 by 180.
  • For simplicity we assume you can encode a color as 0xAAGGBBRR instead of using the IM_COL32() macro, therefore IMGUI_USE_BGRA_PACKED_COLOR config option is not supported!

Prizes:

  • This is mostly for fun so please feel free to make multiple submissions or tweak them as you feel. No pressure. Mostly, I'm supposed to work and ship tables this or next week so hey why I am doing this?!
  • We could possibly include some of them in imgui_demo if they strike a good balance of cool and educational. If we end up doing that we'll rework code to be neat and proper for a demo (aka not densely packed into 1024 characters).

Function signature:

void FX(ImDrawList* d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec4 mouse, float t);
     d : draw list
     a : upper-left corner
     b : lower-right corner
    sz : size (== b - a)
 mouse : x,y = mouse position (normalized so 0,0 over 'a'; 1,1 is over 'b', not clamped)
         z,w = left/right button held. <-1.0f not pressed, 0.0f just pressed, >0.0f time held.
    t  : time

If not using a given parameter, you can omit its name in your function to save a few characters.

To record gif files you can use ShareX https://getsharex.com or ScreenToGif https://www.screentogif.com/

Let's get started! You can post on this thread, on discord or on twitter!

Known issues

  • ImDrawList polygon stroking with thick lines looks broken on acute angle, good luck!!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions