Skip to content

Init

cjcliffe edited this page Jan 2, 2013 · 5 revisions

CubicVR.init function

CubicVR.init provides a simple way to get your WebGL context and CubicVR.js internals initialized in a single call. If CubicVR.init() returns a falsey value it can be assumed that WebGL was unable to be initialized. For even simpler initialization including WebGL support check with pass/fail functions see CubicVR.start.

Note that core_vs and core_fs are typically left undefined as they will be automatically bundled with CubicVR.js when consolidated or minified. While in expanded form the paths to the core shaders will be determined automatically based on the inclusion of CubicVR.js.

If a canvas is not provided a full-browser one will be created for you with resize support. To add any object that has a .resize(x,y) method to the resize call just use CubicVR.[[addResizeable]](object). Most relevant objects such as Scene, Layout, Camera, PostProcessingChain and more already support being added to the global-resize list.

CubicVR.init( canvas, core_vs, core_fs )

Parameters:

  • canvas (optional) : This can be the ID of an existing canvas in the format "#idname" or optionally if left undefined or null will create it's own full-browser canvas.
  • core_vs (optional) : This can be the path to the core vertex shader, if left undefined or null the default path will be determined automatically.
  • core_fs (optional) : This can be the path to the core fragment shader, if left undefined or null the default path will be determined automatically.

Typical usage:

<html><head>
    <script src="../../CubicVR.js" type="text/javascript"></script>
    <script type='text/javascript'>
            function webGLStart() {
                // by default generate a full screen canvas with automatic resize
                var gl = CubicVR.init();
                var canvas = CubicVR.getCanvas();

                if (!gl) {
                    alert("Sorry, no WebGL support.");
                    return;
                };

                // do WebGL setup and render stuff here...

            }
        </script>
    </head>

    <body onLoad="webGLStart();"></body>

</html>

Returns:

A valid WebGL context if successful, falsey value if not.

Related Methods:

CubicVR.setFixedSize( x, y )

This function controls the size of the automatic canvas created. If you wish the canvas to be set to alternate dimensions you can specify them using this function.

Parameters:

  • x : The x-dimensions of the canvas to create.
  • y : The y-dimensions of the canvas to create.

Returns:

none

CubicVR.setFixedAspect( aspect )

This function controls the aspect of the automatic canvas created. If you wish the canvas to be forced to a specific aspect ratio you can specify it using this function.

Parameters:

  • aspect : A floating-point aspect ratio to match, eg. (1280/720)

Returns:

none

CubicVR.getCanvas( )

Retrieve the internally created or assigned canvas that CubicVR has been initialized with.

Returns:

The CANVAS element to which CubicVR.js is currently bound.

CubicVR.setCanvasSizeFactor( scale )

Set the size factor or 'percentage' of the browser the internally created canvas should occupy. By default it will appear auto-centered in the browser and will resize itself appropriately and pass relevant sizes to any resize events.

Parameters:

  • scale : Scale of the canvas relative to the browser between 0 and 1 floating-point, default 1.

Returns:

none

CubicVR.setQuality( quality )

Configure the default rendering quality. By default CubicVR.js will use "high" rendering quality -- this means all lighting and texture features are enabled in the engine and shaders. To hint CubicVR.js to run at a lower quality you can use this method.

Each setting includes an internal registry of available features that are flagged on and off, if you wish to create and use a custom feature set for your application examine the available configurations in CubicVR.js source. Custom Shaders that intend to run in various quality levels should also be tested to ensure they aren't using features or values that are unavailable at that level.

Note that enabling a lower quality will actually assist by skipping the loading of various textures intended for parallax, normal, reflection, etc. So be aware of this if you're expecting them to be there at a lower quality setting.

Parameters:

  • quality : Either "low", "medium" or "high". Default: "high".
    • "low": Use only vertex based lighting, no advanced shader features such as parallax, normal maps or shadows. Fast for older or mobile devices.
    • "medium": Use fragment based lighting but no advanced shader features or shadows.
    • "high": Use all available features.

Returns:

none

CubicVR.setDefaultFilter( filter_mode )

Set the default texture filter mode. This will over-ride any automatic selections of MIPMAP and LINEAR states during texture loads.

Parameters:

  • filter_mode : One of the available texture filtering enums. Default: "linear_mip".
    • "linear_mip": Linear filtering during magnification and mip-map during minification. POT-only.
    • "linear": Linear filtering during magnification or minification. Works with non-POT.
    • "nearest_mip": Nearest filtering during magnification and nearest mip-map during minification. POT-only.
    • "nearest": Nearest filtering during magnification and minification. Works with non-POT.

Returns:

none

CubicVR.setSoftShadows( val )

Enable or disable the use of Soft-Shadows. This can only be done once before any rendering without having to clear all the shader caches (or else it will have undefined mixed soft/regular rendering).

Parameters:

  • val : true to enable soft-shadows, false to disable.

Returns:

none

Something went wrong with that request. Please try again.