[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Canvas resize.



WebGL follows the same rules as other GLs; that is, you have to manage the viewport size yourself. What you need to do is add a Resize event listener to the canvas element, and then call the viewport method on the context: glContext.viewport(x, y, width, height). The x&y are relative to the canvas bottom left corner, so if you want to maintain a render viewport the same size as the canvas, something like this would work:

canvas.addEventListener("resize", function() {
glContext.viewport(0, 0, canvas.width, canvas.height);
});

So no, you don't have to destroy the context and recreate it. (I'm not aware of a way to destroy the context actually...as further getContext() calls return the original context)

On Aug 1, 2010 5:51pm, Steve Baker <steve@sjbaker.org> wrote:
> So I have an HTML5 - and I used canvas.getContext (yaddayadda)
>
> to get the GL rendering context...but I don't understand how canvas and
>
> context a relating to one-another.
>
>
>
> If something resizes the canvas using:
>
>
>
>     canvas.width=whatever;
>
>     canvas.height=whatever;
>
>
>
> ...the GL context doesn't resize with it - instead, it stays the same
>
> number of pixels and is rendered into the bottom-left corner of an
>
> up-sized canvas or cropped if it's a down-sized canvas.
>
>
>
> I guess I'm supposed to destroy the GL context, reload textures and
>
> shaders and create a new one?   But that's a time-consuming thing.
>
>
>
> I'd kinda hoped that the old GL context could be stretched or squashed
>
> to fit the canvas until I could recreate and replace it so that the user
>
> experience would be that the image might go a bit blurry or aliassy for
>
> a few seconds after a resize.  Is there a way to do that - or am I just
>
> going about this all wrong?
>
>
>
>  -- Steve
>
>
>
> -----------------------------------------------------------
>
> You are currently subscribed to public_webgl@khronos.org.
>
> To unsubscribe, send an email to majordomo@khronos.org with
>
> the following command in the body of your email:
>
>
>