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 6 of 6

Thread: Moving vertices in Programmable Pipeline

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2010
    Posts
    17

    Moving vertices in Programmable Pipeline

    Hey guys,
    So I have a simple OpenGL program up and running that draws a square using the programmable pipeline. How do I actually tell the vertices to change their location? Do I edit the vertices in the VBO? If so, how exactly would I do this?

    Thanks,
    Kreed

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,401
    Quote Originally Posted by Kreed View Post
    ...draws a square using the programmable pipeline. How do I actually tell the vertices to change their location? Do I edit the vertices in the VBO? If so, how exactly would I do this?
    It would help to know what the cause of the location change was to advise you best.

    Some of your choices include: modify the input OBJECT-SPACE vertex position attributes in the VBO, or analytically modify the vertex positions in a shader. The latter might be accomplished by changing your MODELVIEW transform (MODELING and/or VIEWING transform) and/or your PROJECTION transform, or performing some kind of analytical OBJECT-SPACE movement, animation, or instancing on your object vertices in the shaders such as particle system behavior, geometry instancing, extrusion, decaling, morphing, skinning, etc.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2010
    Posts
    17
    So, I did a little research, and I guess I should be using a translation Matrix. The issue I have is that I don't want to move a set amount, I want to be able to hand OpenGL it's new coordinates. So instead of telling it to move 10 units on the X axis, I want to tell it to move a specific point. Essentially, I am getting the final location from my physics engine. I suppose I could compute the necessary units to move by doing something like (finalPosition = oldPosition - newPosition), but it seems like there would be a simpler way than to do that.
    Last edited by Kreed; 08-23-2012 at 03:01 PM.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    If all the vertices are to be translated by a fixed amount a translation matrix is a good option. If each vertex is to change a different amount, modifying or re-creating the VBO will be better. If the vertex has a lot of other information you can save bus time by having a separate buffer that has the offsets.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2010
    Posts
    17
    Basically, I have a aphysics engine (Box2D) that does my physics calculations. Any time an object moves in Box2D, I want to translate the corresponding square in OpenGL. I realize that a translation is the way to go, but for a translation you essentially move an object a certain distance in a certain direction IE using a vector. Is there an efficient way to force a new location?

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,256
    Doesn't your physics engine give you a matrix so that you can pass it along to GL? That's what other physics engines do such as Newton Dynamics and ODE. I though it was a pretty common thing for all physics engines.

    Anyway, if you want to update vertices in your VBO, here are some tips
    http://www.opengl.org/wiki/VBO_-_more#Dynamic_VBO
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_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
  •