# gl-texture-cube

> Wraps WebGL's cube texture object.

Latest version **1.0.1** (published 2016-01-03) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install gl-texture-cube
pnpm add gl-texture-cube
yarn add gl-texture-cube
bun add gl-texture-cube
```

## 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 | 1.0.1 |
| Published | 2016-01-03 |
| First published | 2016-01-01 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Rye Terrell |
| Maintainers | wwwtyro |
| Keywords | stackgl, cube, texture, cubemap |

## Links

- npm: https://www.npmjs.com/package/gl-texture-cube
- Repository: https://github.com/wwwtyro/gl-texture-cube
- Homepage: https://github.com/wwwtyro/gl-texture-cube#readme
- Issues: https://github.com/wwwtyro/gl-texture-cube/issues
- npm.io page: https://npm.io/package/gl-texture-cube

## Recent versions

- 1.0.1 (latest) — 2016-01-03
- 1.0.0 — 2016-01-01

## README

# gl-texture-cube

Wraps WebGL's cube texture object.

*Note: This API is experimental and will probably change to reach parity with
[gl-texture2d](https://github.com/stackgl/gl-texture2d).*

## Install

```sh
npm install gl-texture-cube
```

## Example

### Javascript

```js
var Box3D = require('geo-3d-box')
var TextureCube = require('gl-texture-cube')

var boxData = Box3D({size: 2})

var box = Geometry(gl)
  .attr('aPosition', boxData.positions)
  .faces(boxData.cells)

var textures = generateCubemapTextures()

var cubemap = TextureCube(gl, textures)

program.uniforms.uTexture = cubemap.bind(0)
program.uniforms.uModel = model
program.uniforms.uView = view
program.uniforms.uProjection = projection

box.draw()
```

### Vertex Shader

```glsl
attribute vec3 aPosition;

uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;

varying vec3 vNorm;

void main() {
    gl_Position = uProjection * uView * uModel * vec4(aPosition, 1.0);
    vNorm = aPosition;
}
```

### Fragment Shader

```glsl
uniform samplerCube uTexture;

varying vec3 vNorm;

void main() {
    gl_FragColor = textureCube(uTexture, vNorm);
}
```


## API

```js
var createTextureCube = require('gl-texture-cube')
```

### Constructor

#### `var cubemap = createTextureCube(gl, domElements[, format=gl.RGBA, type=gl.UNSIGNED_BYTE])`

Creates a texture from `domElements`, structured as:

```js
{
  pos: {
    x: domElement,
    y: domElement,
    z: domElement,
  },
  neg: {
    x: domElement,
    y: domElement,
    z: domElement
  }
}
```

...where each `domElement` can be one of:

* An ImageData object
* An HTMLCanvas object
* An HTMLImage object
* An HTMLVideo object

Takes a WebGL context `gl`. Optionally takes a WebGL data format `format`
and storage type `type`.

### Methods

#### `cubemap.bind([textureUnit])`

Binds the texture. If the optional `textureUnit` is not defined then
the active texture is not changed.

#### `cubemap.dispose()`

Destroys the texture and releases its resources.

#### `cubemap.generateMipmap()`

Generates mipmaps for the texture.

### Properties

#### `cubemap.wrap`

Gets/sets the wrap behavior for the texture in both dimensions.
Defaults to `[gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE]`. Example:

```js
cubemap.wrap = [gl.REPEAT, gl.REPEAT]
```
#### `cubemap.magFilter` & `cubemap.minFilter`

Gets/sets the magnification and minification filter. Defaults
to `gl.NEAREST`.

## Credits
Based on [gl-texture2d](https://github.com/stackgl/gl-texture2d).

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