Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectangle not overlaying on line correctly #114

Closed
arihantparsoya opened this issue Jun 4, 2019 · 3 comments
Closed

Rectangle not overlaying on line correctly #114

arihantparsoya opened this issue Jun 4, 2019 · 3 comments
Assignees
Labels

Comments

@arihantparsoya
Copy link
Member

Drawing a rectangle over a line does not fully obscure the line

To Reproduce

from p5 import *

def setup():
	size(640, 360)
	no_loop()

def draw():
	background(0)
	stroke(255)
	line((0, 0), (200, 200))
	fill(255, 0, 0)
	rect((60, 50), 50, 50)

if __name__ == '__main__':
	run()

Output
Screenshot 2019-06-04 at 3 04 41 PM

I believe the problem is in the renderer. The renderer first renders all the polygons before lines. Reference: https://github.com/p5py/p5/blob/master/p5/sketch/renderer.py#L276

System information:

  • p5 release (version number or latest commit):
  • Python version: 3.7
  • Operating system: MacOS Mojave
@arihantparsoya arihantparsoya self-assigned this Jun 4, 2019
@abhikpal
Copy link
Member

abhikpal commented Jun 4, 2019

This looks like #67.

@jeremydouglass
Copy link
Contributor

jeremydouglass commented Aug 16, 2019

A guess (not an OpenGL expert) is that you need to get rid of globals poly_draw_queue, line_draw_queue, point_draw_queue and replace them with a single draw_queue.

So, in add_to_draw, append like this this:

    draw_queue.append(('poly', vertices, idx, fill))
    draw_queue.append(('point', vertices, idx, stroke))
    draw_queue.append(('line', vertices, idx, stroke))

...and then flush_geometry needs to iterate over that existing labeled queue -- rather than building it manually with zip() out of three small queues.

p5/p5/sketch/renderer.py

Lines 393 to 395 in 000b562

global poly_draw_queue
global line_draw_queue
global point_draw_queue

@arihantparsoya
Copy link
Member Author

When we use a common draw_queue, OpenGL is called multiple times whenever the opengl primitives (triangles, lines, triangles) change. This makes the overall efficiency of code slower. Hence, this structure was adopted.

In the current development branch, we have implemented a common draw_queue with some performance optimisation. It will be merged into the main code soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants