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

Thread: Drawing Quads multiple times per frame

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    4

    Drawing Quads multiple times per frame

    Hello,

    Using modern OpenGL (4.2) what is the best way for me to draw a quad multiple times with different positions and textures?

    I currently have a render class which, when initialized creates a program, shaders a VBO etc. Then a Render functions which creates an mvp based on input and binds the textures and uniforms and such then draws with glDrawArrays.

    Is there a way to render the same set of vertices like this or do I need to create a VBO and everything else for every single object.

    The reason I want to do this is I am making a 2D game and all the objects are exactly the same when it comes to vertices.

    David

  2. #2
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    you can use this one object over and over again.
    the only thing that you need to change is the 'mvp' as this one positions the Quad.

    (pseudocode)
    set first mvp
    draw VBO

    set second mvp position
    draw VBO

    set third mvp position
    draw VBO
    (/pseudocode)

    cu
    uwi

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    4
    Thanks, I have got it to work.

    Can I ask another question though. If using draw array's instanced can I pass a dynamic array of matrices to the shader or does it need to be determined at compile time? If it can how can I do so?

    Thanks so much

  4. #4
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    i am not shure if i got you right here , but:
    you may be able to pass a array of matrixs to the shader, BUT the shader only processes one of you quads every time.
    so the array won´t help.
    you should always send one array of vertex and its matrix ( and color, etc ) though the rendering pipeline.
    than change the matrix and send the next one ...
    what you are trying to do here is somthing a geometry shader may do ...

    cu
    uwi

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    4
    Oh well ok. I have heard that passing an array of matrix uniforms into a vertex array and then assigning each one to an instanced based on its instanceID. Can this not be done without a geometry shader

  6. #6
    Intern Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    97
    hi,

    yes it can be done ... the question is just, if this is the propper way for your code.
    it somehow taking the long and hard road instead of taking the freeway :-)

    cu
    uwi
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    Free Programming Helpline: www.programming-hotline.com
    ---------------------------------------------------------
    A Friday Night Programmer: www.uwiworld.net

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Instancing is good if it helps you avoid a large number of GL calls. If you are just rendering 100 quads with different textures, it doesn't sound like a performance win. Even 12 year old GPU can handle that.

    In your case, you can make use of GL_TEXTURE_2D_ARRAY and have a flag to sample from the layer that you desire.
    ------------------------------
    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
  •