Login  Register

Re: How to duplicate a cube and control each one independently?

Posted by V. Scott Gordon on Aug 13, 2017; 2:46am
URL: https://forum.jogamp.org/How-to-duplicate-a-cube-and-control-each-one-independently-tp4038114p4038117.html

This is my first post... apologies in advance if I stumble....

You are using a deprecated approach; better would be to use shaders, as follows:

Read in the obj file once into a VBO, then draw it as many times as you like by calling glDrawArrays() for each occurance, with different MV ("model-view") matrices that you pass through the shader pipeline as uniform variables.  You can hide one of them by simply skipping the corresponding call to glDrawArrays().

If there is some simple relationship between how the different copies move relative to each other, there is an even more efficient approach: instancing.  You read in the obj file once into a VBO, then draw it using glDrawArraysInstanced(), specifying the number of instances you want drawn of the object.  In the vertex shader, you can then use the built-in variable gl_InstanceID to manipulate the model matrix differently for each instance.  Hiding one of them is slightly trickier, but there are many possible tricks for doing it.

Complete examples of both methods are given in chapter 4 of this book (sorry for the shameless plug):
http://jogamp.org/wiki/index.php/Jogl_Tutorial#Gordon_and_Clevenger_textbook

(Julien - feel free to correct anything I may have mis-stated)