Mohammad Areeb Siddiqui
Mohammad Areeb Siddiqui

Reputation: 10179

Why canvas.getContext("2d")? Why not only canvas.getContext()?

If a canvas is always 2d then why in the world are we specifying the 2d parameter in getContext() function. Why isn't it only getContext(), why is it with a fixed parameter? :O

Upvotes: 1

Views: 352

Answers (2)

Sterling Archer
Sterling Archer

Reputation: 22395

It's not "always 2D". You can use WebGL to make 3D graphics, or other parameters accepted by getContext

Microsoft has a detailed explanation on the parameters here.

Upvotes: 1

Anubhav
Anubhav

Reputation: 7208

There are 2 parameters which getContext() can take. One is the standard 2d context which renders 2d elements. The other uses webGL technology which is still in its infancy. Hence mostly you will find the 2d context of canvas everywhere (as of now).

Just as 3ds max or photoshop is a 2d window on your computer screen but you can render 3d stuff through them. Similarly, canvas is a 2d element in your browser through which you can change the context and render appropriate output.

Upvotes: 2

Related Questions