Learn R Programming

RGL - 3D visualization device system for R using OpenGL

INTRODUCTION

The RGL package is a visualization device system for R, using OpenGL or WebGL as the rendering backend. An OpenGL rgl device at its core is a real-time 3D engine written in C++. It provides an interactive viewpoint navigation facility (mouse + wheel support) and an R programming interface. WebGL, on the other hand, is rendered in a web browser; rgl produces the input file, and the browser shows the images.

WEBSITE

A pkgdown website is here:

https://dmurdoch.github.io/rgl/

The unreleased development version website is here:

https://dmurdoch.github.io/rgl/dev/

See this vignette for details on producing your own pkgdown website that includes rgl graphics.

The currently active development site is here:

https://github.com/dmurdoch/rgl

INSTALLATION

Most users will want to install the latest CRAN release. For Windows, macOS and some Linux platforms, installation can be easy, as CRAN distributes binary versions:

# Install latest release from CRAN
install.packages("rgl")

To install the latest development version from Github, you’ll need to do a source install. Those aren’t easy! Try

# Install development version from Github
remotes::install_github("dmurdoch/rgl")

If that fails, read the instructions below.

Currently installs are tested on older R versions back to R 3.5.x, but this version of rgl may work back as far as R 3.3.0.

LICENSE

The software is released under the GNU Public License. See COPYING for details.

FEATURES

  • portable R package using OpenGL (if available) on macOS, Win32 and X11
  • can produce 3D graphics in web pages using WebGL
  • R programming interface
  • interactive viewpoint navigation
  • automatic data focus
  • geometry primitives: points, lines, triangles, quads, texts, point sprites
  • high-level geometry: surface, spheres
  • up to 8 light sources
  • alpha-blending (transparency)
  • side-dependent fill-mode rendering (dots, wired and filled)
  • texture-mapping with mipmapping and environment mapping support
  • environmental effects: fogging, background sphere
  • bounding box with axis ticks marks
  • undo operation: shapes and light-sources are managed on type stacks, where the top-most objects can be popped, or any item specified by an identifier can be removed

PLATFORMS

macOS Windows 7/10 Unix-derivatives

BUILD TOOLS

R recommended tools (gcc toolchain) On Windows, Rtools40 (or earlier versions for pre-R-4.0.0)

REQUIREMENTS

For OpenGL display:

Windowing System (unix/x11 or Windows)
OpenGL Library
OpenGL Utility Library (GLU)

For WebGL display:

A browser with WebGL enabled. See https://get.webgl.org.

Installing OpenGL support

Debian and variants including Ubuntu:

aptitude install libgl1-mesa-dev libglu1-mesa-dev

Fedora:

yum install mesa-libGL-devel mesa-libGLU-devel libpng-devel

macOS:

Install XQuartz.
rgl should work with XQuartz 2.7.11 or newer, but it will probably need rebuilding if the XQuartz version changes. XQuartz normally needs re-installation whenever the macOS version changes.

Windows:

Windows normally includes OpenGL support, but to get the appropriate include files etc., you will need the appropriate version of Rtools matched to your R version.

Options

The libpng library version 1.2.9 or newer is needed for pixmap import/export support.

The freetype library is needed for resizable anti-aliased fonts.

BUILDING/INSTALLING

Binary builds of rgl are available for some platforms on CRAN.

For source builds, install the prerequisites as described above, download the tarball and at the command line run

R CMD INSTALL rgl_1.3.15.tar.gz

(with the appropriate version of the tarball). The build uses an autoconf configure script; to see the options, expand the tarball and run ./configure --help.

Alternatively, in R run

install.packages("rgl")

to install from CRAN, or

remotes::install_github("dmurdoch/rgl")

to install the development version from Github.

BUILDING ON MACOS

To build on MacOS using one of the ARM64 chips (currently M1, M2 or M3), follow the instructions on https://mac.r-project.org/tools/ to install the tools and libraries into /opt/R/arm64. It is important that /opt/R/arm64/bin appear in your PATH before /usr/local/bin if the latter directory has been used for x86_64 installs. If you don’t do this, or have some other error in setting things up, you’ll get a warning during rgl installation saying that some configure test failed, and rgl will be installed without OpenGL support.

Some versions of RStudio (including 2024.04.2+764) have a bug that modifies your PATH on startup and again after every package installation, putting /usr/local/bin at the head of the PATH. If you are building rgl in such a system you need to remove files from /usr/local/bin if there’s a file with the same name in /opt/R/arm64/bin. Hopefully this bug will be fixed soon!

BUILDING WITHOUT OPENGL

As of version 0.104.1, it is possible to build the package without OpenGL support on Unix-alikes (including macOS) with the configure option –disable-opengl For example,

R CMD INSTALL --configure-args="--disable-opengl" rgl_1.3.15.tar.gz 

On Windows, OpenGL support cannot currently be disabled.

DOCUMENTATION and DEMOS:

library(rgl)
browseVignettes("rgl")
demo(rgl)

CREDITS

Daniel Adler dadler@uni-goettingen.de
Duncan Murdoch murdoch@stats.uwo.ca
Oleg Nenadic onenadi@uni-goettingen.de
Simon Urbanek simon.urbanek@math.uni-augsburg.de
Ming Chen mchen34@uwo.ca
Albrecht Gebhardt albrecht.gebhardt@uni-klu.ac.at
Ben Bolker bolker@zoo.ufl.edu
Gabor Csardi csardi@rmki.kfki.hu
Adam Strzelecki ono@java.pl
Alexander Senger senger@physik.hu-berlin.de
The R Core Team for some code from R.
Dirk Eddelbuettel edd@debian.org
The authors of Shiny for their private RNG code.
The authors of knitr for their graphics inclusion code. Jeroen Ooms for Rtools40 and FreeType help.
Yohann Demont for Shiny code, suggestions, and testing.
Joshua Ulrich for a lot of help with the Github migration. Xavier Fernandez i Marin for help debugging the build.
George Helffrich for draping code.
Ivan Krylov for window_group code in X11.
Michael Sumner for as.mesh3d.default enhancement.
Tomas Kalibera for winutf8 and other help.
David Hugh-Jones for documentation improvements.
Trevor Davis for a snapshot3d patch.
Mike Stein for pointer-handling code.
Jonathon Love for the uname patch.
The Mapbox team for the triangulation code.

Copy Link

Version

Install

install.packages('rgl')

Monthly Downloads

62,808

Version

1.3.16

License

GPL

Issues

Pull Requests

Stars

Forks

Maintainer

Duncan Murdoch

Last Published

January 6th, 2025

Functions in rgl (1.3.16)

all.equal.mesh3d

Compare mesh3d objects in a meaningful way.
ageControl

Set attributes of vertices based on their age
arc3d

Draw arcs
GramSchmidt

The Gram-Schmidt algorithm
Buffer

R6 Class for binary buffers in glTF files.
abclines3d

Lines intersecting the bounding box
arrow3d

Draw an arrow
as.tmesh3d

Convert object to a triangular mesh
as.mesh3d.ashape3d

Convert alpha-shape surface of a cloud of points to RGL mesh object
as.mesh3d.rglId

Convert object in plot to RGL mesh object
as.rglscene

Convert an object to an rglscene object.
as.triangles3d

Convert an object to triangles
as.mesh3d

Convert object to mesh object
asRow

Convenience functions for RGL HTML layouts
.check3d

Check for an open RGL window.
addNormals

Add normal vectors to objects so they render more smoothly
aspect3d

Set the aspect ratios of the current plot
cylinder3d

Create cylindrical or "tube" plots
decorate3d

Add decorations to a 3D plot
checkDeldir

Check for a compatible version of deldir
rgl.attrib

Get information about shapes
axes3d

Draw boxes, axes and other text outside the data
ellipse3d

Make an ellipsoid
bgplot3d

Use base graphics for RGL background
callbacks

User callbacks on mouse events
drape3d

Drape lines over a scene.
elementId2Prefix

Use widget with old-style controls
hover3d

Display hover info in plot.
import

Imported from magrittr
contourLines3d

Draw contours on a surface
bbox3d

Set up bounding box decoration
clipMesh3d

Clip mesh or RGL object to general region
bg3d

Set up background
expect_known_scene

Helper for testthat testing.
identify3d

Identify points in plot
clipplaneControl

Sets attributes of a clipping plane
figWidth

Get R Markdown figure dimensions in pixels
getBoundary3d

Extract the boundary of a mesh
in_pkgdown_example

Are we running in a pkgdown example?
merge.mesh3d

Merge RGL mesh objects
par3dinterpControl

Control RGL widget like par3dinterp()
mesh3d

Construct 3D mesh objects
mfrow3d

Set up multiple figure layouts
cube3d

Sample 3D mesh objects
mergeVertices

Merge duplicate vertices in mesh object
pch3d

Plot symbols similar to base graphics
gltfTypes

Names of glTF types.
material3d

Get or set material properties
grid3d

Add a grid to a 3D plot
extrude3d

Generate extrusion mesh
facing3d

Subset an object to parts facing in a particular direction
matrices

Work with homogeneous coordinates
persp3d

Surface plots
light

Add light source
makeDependency

Process Javascript for HTML dependency
open3d

Work with RGL windows
observer3d

Set the observer location
par3d

Set or query RGL parameters
par3dinterp

Interpolator for par3d parameters
persp3d.function

Plot a function of two variables
persp3d.triSht

Plot an interp or tripack Delaunay triangulation
plotmath3d

Draw text using base graphics math plotting
readSTL

Read and write STL (stereolithography) format files
polygon3d

Draw a polygon in three dimensions
planes3d

Add planes
propertyControl

Controls to use with playwidget()
rgl-deprecated

Deprecated functions in rgl
rgl-duplicated

Duplicated functions in rgl
rgl-defunct

Defunct functions in rgl
persp3d.deldir

Plot a Delaunay triangulation
play3d

Play animation of RGL scene
r3d

Generic 3D interface
rgl.Sweave

Integrating RGL with Sweave
rgl.bringtotop

Assign focus to an RGL window
rgl.attrib.info

Get information about attributes of objects
rgl.fns

Low level functions that should not be called by users.
rgl.init

Initializing RGL
playwidget

Add a widget to play animations
safe.dev.off

Close graphics device in a safe way.
scene

Scene management
plot3d

3D scatterplot
rglToLattice

Convert RGL userMatrix to lattice or base angles
rgl.pixels

Extract pixel information from window
rglMouse

Generate HTML code to select mouse mode
rgl.postscript

Export vector graphics
rglwidget

An htmlwidget to hold an RGL scene
primitives

Add primitive shape
rglShared

Create shared data from an RGL object
rgl-package

3D visualization device system
rgl-internal

Internal RGL functions and data
setupKnitr

Displaying RGL scenes in knitr documents
shade3d

Draw 3D mesh objects
rgl.getAxisCallback

Get user-defined axis labelling callbacks.
rgl.incrementID

Increment ID
rgl.user2window

Convert between RGL user and window coordinates
scene3d

Saves the current scene to a variable, and displays such variables
spheres3d

Add spheres
rglExtrafonts

Register extra fonts
select3d

Select a rectangle in an RGL scene
plot3d.formula

Methods for formulas
plot3d.lm

Method for plotting simple linear fit
selectpoints3d

Select points from a scene
rgl.select

Switch to select mode, and return the mouse position selected
show2d

Draw a 2D plot on a rectangle in a 3D scene
rgl.useNULL

Report default use of null device
snapshot3d

Export screenshot
subdivision3d

Subdivide a mesh
sprites

Add sprites
rglFonts

Specify FreeType fonts
tkrgl

The former tkrgl package
rglIds

RGL id values
sceneChange

Make large change to a scene from Shiny
tkspin3d

Create TCL/TK controller for RGL window
thigmophobe3d

Find the direction away from the closest point in a 3d projection
triangulate

Triangulate a two-dimensional polygon
spin3d

Create a function to spin a scene at a fixed rate
shadow3d

Project shadows of mesh onto object.
tkpar3dsave

Modal dialog for saving par3d settings
setUserCallbacks

Set mouse callbacks in R or Javascript code
vertexControl

Set attributes of vertices
shapelist3d

Create and plot a list of shapes
writeASY

Write Asymptote code for an RGL scene
setUserShaders

Set user-defined shaders for RGL objects, or get shaders.
setAxisCallbacks

User-defined axis labelling callbacks.
turn3d

Create a solid of rotation from a two-dimensional curve
writeOBJ

Read and write Wavefront OBJ format files
viewpoint

Set up viewpoint
setGraphicsDelay

Set a one-time slowdown on opening standard graphics
text3d

Add text to plot
textureSource

Retrieve source code used to produce texture file.
surface3d

Add surface
shiny

Functions for integration of RGL widgets into Shiny app
tagged3d

Find tags on rgl objects.
shinyGetPar3d

Communicate RGL parameters between R and Javascript in Shiny
tkspinControl

Create a spin control in a TCL/TK window
toggleWidget

An HTML widget to toggle display of elements of a scene
subscene3d

Create, select or modify a subscene
subsceneInfo

Get information on subscenes
writePLY

Write Stanford PLY format files