Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to properly use glPrimitiveRestartIndex().
Forum Updated to NodeBB v4.3 + New Features

How to properly use glPrimitiveRestartIndex().

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 811 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lavonne
    wrote on last edited by
    #1

    Of the following two code snippets the first draws 6 individual quads, while the second draws jumbled triangles as result of failing to restart primitives at 0xffff marker. How should I adjust the code as to properly enable GL_PRIMITIVE_RESTART_INDEX.
    QOpenGLFunctions::glPrimitiveRestartIndex() fails to activate or restart index incorrectly marked.

    Here is code snippet, and thank you in advance if you can help :)

    /// . . . setup shaders and matrices
    /// object 'scene' is initialized QOpengGLFunctions object

    scene->glViewport(0, 0, w, h);
    scene->glClearColor(0.0, 0.3, 0.0, 1.0);
    scene->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    ///
    
    /**
    /// BOX - individual draw commands :(
    if (mode == Scene::Render_By_Camera)   bindTextureIndex(Box_Tex);
    bindBufferIndex(Box_Vbo);
    static GLushort box_indices[6][4] =
        { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 }, { 12, 13, 14, 15 }, { 16, 17, 18, 19 }, { 20, 21, 22, 23 } };
    /// draw 6 sides of box fine
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[0]); /// NegX
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[1]); /// PosZ
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[2]); /// PosX
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[3]); /// PosX
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[4]); /// NegZ
    scene->glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, box_indices[5]); /// PosY
    **/
    /// BOX - Single Draw Command :)
        /// enable primitive restart, as QOpenGLFunctions does not directly support it
    static QOpenGLContext * context = QOpenGLContext::currentContext();
    QOpenGLFunctions_3_1 * functions = context->versionFunctions<QOpenGLFunctions_3_1> (); /// first version supporting glPrimitiveRestartIndex()
    if (!functions->initializeOpenGLFunctions())   qWarning() << "QOpenGLFunctions_3_1 not initialized!";
        /// setup array
    static GLushort box_ids[29] =
        { 0, 1, 2, 3, 0xFFFF, 4, 5, 6, 7, 0xFFFF, 8, 9, 10, 11, 0xFFFF, 12, 13, 14, 15, 0xFFFF, 16, 17, 18, 19, 0xFFFF, 20, 21, 22, 23 };
        /// draws scrambled vertex soup as GL_PRIMITIVE_RESTART does NOT SEEM TO EFFECT RESULTS
    if (mode == Scene::Render_By_Camera)   bindTextureIndex(Box_Tex);
    bindBufferIndex(Box_Vbo);
    functions->glPrimitiveRestartIndex(0xFFFF);
    scene->glEnable(GL_PRIMITIVE_RESTART_INDEX);
    scene->glDrawElements(GL_TRIANGLE_FAN, 29, GL_UNSIGNED_SHORT, box_ids);
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved