Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: loop drawing cubes

  1. #1
    Newbie Newbie
    Join Date
    Aug 2012
    Posts
    1

    loop drawing cubes

    Hi,
    I've an example with one cube. I want the cube is drawn again and again. He should be somewhere in the scene and not on the place before.
    Can anyone help me please?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    894
    Simply generate a random positions that make sense, put them into an array and while iterating over the cubes, simply fetch the position for the current cube and translate it using that position. If you're using shaders you can simply pass that position to the shader or use instancing where you will pass the complete array, or slices of arrays, to the shader. If you're using the fixed-function pipeline (i.e. GL 2.1- features) you need to employ the matrix stack and for each cube push the model-view, translate, draw the cube, and pop the matrix.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •