Is it possible to draw and clear grease pencil real-time during/over blender game engine gameplay?
Since the game engine does not support drawing with grease pencil while the game engine is running, I made a script to draw on the camera in the game engine.
To use the script, enter it into the text editor and name it grease_pencil.py. You could call it anything, but it must end in
.py to work as a module.
Add a Python controller to an Always sensor, with true level triggering enabled, on any object. Change the python controller's Execution Method to Module and set its source to grease_pencil.draw or whatever you named it only without the .py and followed by .draw (draw is the name of the function we are calling).
Press P, in the game engine, and click and drag to draw.
The complete script.
import bge color = (.9, 0, 0) lines =  def position(): scene = bge.logic.getCurrentScene() camera = scene.active_camera x, y = bge.logic.mouse.position vec = camera.worldPosition - camera.getScreenVect(x, y) vec = vec * camera.worldOrientation * camera.world_to_camera return vec def mouse_just_down(): return bge.logic.mouse.events[bge.events.LEFTMOUSE] == bge.logic.KX_INPUT_JUST_ACTIVATED def mouse_down(): return bge.logic.mouse.events[bge.events.LEFTMOUSE] == bge.logic.KX_INPUT_ACTIVE def mouse_moving(): return bge.logic.mouse.events[bge.events.MOUSEX] == bge.logic.KX_INPUT_ACTIVE or \ bge.logic.mouse.events[bge.events.MOUSEY] == bge.logic.KX_INPUT_ACTIVE def draw(): if mouse_just_down(): lines.append([position()]) if mouse_down() and mouse_moving(): lines[-1].append(position()) for line in lines: prev = None for vec in line: if prev: bge.render.drawLine(prev, vec, color) prev = vec