openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Thick Lines and Varying Point Sizes for Programmable Renderer

Open NickHardeman opened this issue 2 weeks ago • 7 comments

This PR attempts to mimic some of the original line and point drawing functionality allowed by earlier versions of GL for the Programmable GL Renderer pipeline while introducing some simple additional functionality.

Lines

This PR aims to enable varying line width for the following:

  • ofMesh with mode GL_LINES, GL_LINE_STRIP or GL_LINE_LOOP
  • ofPolyline
  • ofPath ( which draws the poly lines and sets the width from the stroke width on the path )
  • ofDrawLine(x,y)

Currently supported attributes:

  • Color per line point
  • Textures (y coord is 0 -> tex height )
  • Global color

The approach for the thick lines involves adding additional points per vertex to a vbo mesh that feeds additional VAO attributes to a shader.

  • Allows for referencing next and previous vertex references
  • Does not require a geometry shader ( not available in all instances or platforms )
  • Renders 4 vertices per source vertex for mitered lines (GL_LINE_STRIP, GL_LINE_LOOP) and 2 vertices for GL_LINES
  • Can set screen space width (pixel width) regardless of distance to camera or world width ( size attenuation )

This PR currently does not intend to do the following

  • Add end caps, round or otherwise
  • Address self intersection

Example Code:

path.setStrokeWidth(mLineWidth);
path.draw();
ofSetLineWidth(mLineWidth);
mesh.setMode(OF_PRIMITIVE_LINES);
mesh.draw();

Points

Points can vary in size based of a newly introduced function ofSetPointSize(pointSize); Supports

  • Per point color
  • Textures ( single texture for all points )
  • Smoothing via a shader

Example code:

ofSetPointSize(pointSize);
ofEnablePointSprites();
texture.bind();
mesh.drawVertices();
texture.unbind();

Core functionality to the GL Programmable Renderer has been changed and thus requires extensive testing.

TODO:

  • [x] Optimizations
  • [ ] Thorough testing
  • [x] Cleaning up and comments
  • [x] Update examples/gl/pointsAsTexturesExample
  • [x] Create lines example ( in examples/graphics since Cairo also supports line width, not sure if it should be in examples/gl).

Fixes #8011

Screenshot 2024-06-13 at 10 53 04 PM

Screenshot 2024-06-15 at 9 16 29 PM

NickHardeman avatar Jun 14 '24 04:06 NickHardeman