I've been watching "Warcraft 3", and suddenly realized that I have no idea how to draw a circle on a surface.

Here is an example:

In "Warcraft 3", circles are painted on the ground, even over terrain of varying height.

I guess this is projection? I also have very little idea of how to draw a shadow. I only somewhat know OpenGL.

It is also interesting how this circle seems to not perfectly repeat the shape of that cliff. My guess is that it's drawn using a height map, which is stored somewhere separately, and not as the cliff, itself. It looks like it actually goes underwater, but it may be just a compression artifact.

  • \$\begingroup\$ There are countless ways to do this. The best answer to this questions depends on what graphics engine you are using. \$\endgroup\$ – Philipp May 31 '17 at 11:46
  • \$\begingroup\$ The keyword you are probably looking for is "decals", there are quite a few questions about decals here already - maybe you find some of them helpful? \$\endgroup\$ – wondra May 31 '17 at 11:49
  • \$\begingroup\$ Don't use any engine yet. Maybe I'll use raw opengl, I'm not sure. \$\endgroup\$ – Viktor Smirnov May 31 '17 at 11:49
  • \$\begingroup\$ It seems clear you would like answers in context of OpenGL. Given that, I have narrowed the scope; this came up in the review queue for closure as too broad, and without a specific context (like "OpenGL"), I have to agree. \$\endgroup\$ – Gnemlock May 31 '17 at 12:49
  • \$\begingroup\$ Note that if you later decide to use a different system, where an OpenGL answer is not applicable, your certainly welcome to come back and ask "how would I use this / convert this to this other system"; though not before having to initially learn that new system, as you mention in your question. \$\endgroup\$ – Gnemlock May 31 '17 at 12:53

The best way to do this efficiently (without dynamic meshes) would probably be done using the fragment shader.

You pass the circle centers to the terrain's fragment shader, you get the fragment's position from the vertex shader, and using the

dist = length(fragment.xz - center.xz)

You get the distance from the circle's center. If it equals the radius of the circle, then you make the fragment green for example.

  • \$\begingroup\$ If there are a lot of these circles to draw, then rendering them separately as screenspace decals may be more efficient — limiting the cost of each ring to only the portion of the screen it covers. \$\endgroup\$ – DMGregory May 31 '17 at 12:08
  • \$\begingroup\$ Hm, warcraft 3 was done with opengl 1.3, before any shaders existed. According to this sharkyforums.com/… and this en.wikipedia.org/wiki/OpenGL_Shading_Language \$\endgroup\$ – Viktor Smirnov May 31 '17 at 12:27
  • 1
    \$\begingroup\$ @ViktorSmirnov, note that we can help you identify a way to produce the same effect; but we can not tell you how a specific game does it. Unless we actually worked on said game, such answers would only be speculation. Questions asking "how did they do it", as opposed to "how do I do it like they did" are often closed for that distinct difference. \$\endgroup\$ – Gnemlock May 31 '17 at 12:51
  • \$\begingroup\$ I want to target low-spec computers, and because of that I'd like to avoid shaders where possible. What do you think, should I create a circle texture and draw that? \$\endgroup\$ – Viktor Smirnov May 31 '17 at 13:14
  • \$\begingroup\$ Even low-spec computers today support shaders. You'd be hard pressed to find someone playing computer or mobile games on a machine with no shader support, so I wouldn't worry about the tech limiting your audience. \$\endgroup\$ – DMGregory May 31 '17 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.