Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js to webGL to OpenGL

I want to take a three.js code and possibly convert it to a webGL or preferably OpenGL code so that I can use it in a stand-alone program that I'm developing in Python. Is there any straightforward way of doing that ?

like image 671
MostafaMV Avatar asked Oct 24 '13 22:10

MostafaMV


People also ask

Does Three js use OpenGL?

Three. js uses the WebGL engine in the browser for rendering scenes. The API is based on OpenGL (GL stands for graphics library), a desktop graphics API.

Does Three js use WebGL?

js. Three. js is a cross-browser JavaScript library and application programming interface (API) used to create and display animated 3D computer graphics in a web browser using WebGL.

What's the relationship between WebGL and three js?

WebGL: is the Javascript API that allows you to create 3D graphics in the browser. Three. js: A framework build on top of WebGL which makes it easier to create 3D graphics in the browser, it uses a canvas + WebGL to display the 3D scene.

Should I learn WebGL before three js?

If you use Three. js, you don't need to know how to program in WebGL, you just need to understand the WebGL concepts. That means, that you just need to be able to read someone else's WebGL code and understand what you read. That is a lot easier than being expected to write a WebGL program yourself from scratch.


1 Answers

As far as I know there isn't any easy way.

Though if you know OpenGL, where "knowing" is when you can do pretty much any task, from rendering a huge amount of vertices to performing texturing, lighting and shadow mapping, etc.

Then you could simply go to any Three.js og WebGL application.

Here is a Three.js application as an example.

  • http://mrdoob.github.io/three.js/examples/#webgl_geometry_cube

Then you can just view-source of the Three.js/WebGL script. Where you automatically can make sense of most of it. Like.

var geometry = new THREE.CubeGeometry(100, 200, 300);

We can easily assume the above code would create a 3D Cube where (100, 200, 300) = (width, height, length). Now we know that we need to create a new VAO and/or VBO which we would calculate the vertices, and as we can see in the example the cube is textured, so we know that we need to store both vertices and texture coordinates within the buffer.

Basically you could read through everything like that. Here are some more examples.

renderer.setSize(window.innerWidth, window.innerHeight);

That would of course set the size of the display.

Also Three.js is just a JavaScript library build on top of WebGL.

like image 75
vallentin Avatar answered Oct 11 '22 17:10

vallentin