# webgl-context

> gets a WebGLRenderingContext

Latest version **2.2.0** (published 2015-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install webgl-context
pnpm add webgl-context
yarn add webgl-context
bun add webgl-context
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2015-06-11 |
| First published | 2014-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | webgl, glsl, context, glcontext, gl, webglrenderingcontext, webglcontext |

## Links

- npm: https://www.npmjs.com/package/webgl-context
- Repository: https://github.com/mattdesl/webgl-context
- Issues: https://github.com/mattdesl/webgl-context/issues
- npm.io page: https://npm.io/package/webgl-context

## Dependencies (1)

- [get-canvas-context](https://npm.io/package/get-canvas-context.md) ^1.0.1

## Recent versions

- 2.2.0 (latest) — 2015-06-11
- 2.1.2 — 2015-04-01
- 2.1.1 — 2015-01-16
- 2.1.0 — 2015-01-14
- 2.0.0 — 2015-01-04
- 1.2.1 — 2014-06-12
- 1.2.0 — 2014-06-12
- 1.1.0 — 2014-06-11
- 1.0.0 — 2014-06-11

## README

# webgl-context

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Grabs a WebGLRenderingContext, returning null if it doesn't exist. Similar to [2d-context](https://nodei.co/npm/2d-context/).

```js
//get a webgl context, will be null if not found
var gl = require('webgl-context')()

if (gl) {
    document.body.appendChild(gl.canvas)
    //do something...
}
```

Or, with options:

```js
//or with optional settings...
var gl = require('webgl-context')({
    canvas: canvas, //the canvas DOM element to use
    width: 400, //resizes the canvas..
    height: 200, 
    antialias: true //can specify custom attributes here
})
```

## Usage

[![NPM](https://nodei.co/npm/webgl-context.png)](https://nodei.co/npm/webgl-context/)

#### `ctx = require('webgl-context')([opt])`

Gets a new canvas context with optional parameters:

- `canvas` a canvas element to use, otherwise creates a new element
- `width` a width to set, otherwise no change
- `height` a height to set, otherwise no change
- other attributes are passed to the getContext call, like `alpha` and `antialias`

You can then get a reference of the canvas element with `ctx.canvas`. 

## See Also

- [get-canvas-context](https://www.npmjs.com/package/get-canvas-context)
- [2d-context](https://www.npmjs.com/package/2d-context)

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/webgl-context/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/webgl-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
