Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Open GL ES2.0 - glDrawelements()
QtWS25 Last Chance

Open GL ES2.0 - glDrawelements()

Scheduled Pinned Locked Moved Game Development
2 Posts 2 Posters 3.8k Views
  • 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.
  • A Offline
    A Offline
    akhil
    wrote on last edited by
    #1

    I am not able to use glDrawElements() command properly. I have checked with my buffers( both vertex and index) with my vertex and index data. Both come out to be same. And what i feel is that the main problem lies in drawing the object. I am giving my code below. Can anyone point the mistake.

    @void GLWindow::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the background and depth-buffer for this frame

    GLuint vertexAttr = m_sampleProgram.attributeLocation("vertex");
    GLuint normalAttr = m_sampleProgram.attributeLocation("normal");
    GLuint texAttr = m_sampleProgram.attributeLocation("texCoord");
    GLuint matrixAttr = m_sampleProgram.uniformLocation("matrix");
    GLuint projAttr = m_sampleProgram.uniformLocation("proj");
    
    m_sampleProgram.bind();
    vertexBuffer.bind();
    indexBuffer.bind();
    
    m_sampleProgram.enableAttributeArray(vertexAttr);
    m_sampleProgram.setAttributeBuffer(vertexAttr, GL_FLOAT, 0 * sizeof(GLfloat), 3, 5 * sizeof(GLfloat));
    m_sampleProgram.enableAttributeArray(texAttr);
    m_sampleProgram.setAttributeBuffer(texAttr,    GL_FLOAT, 3 * sizeof(GLfloat), 2, 6 * sizeof(GLfloat));
    m_sampleProgram.enableAttributeArray(normalAttr);
    m_sampleProgram.setAttributeBuffer(normalAttr, GL_FLOAT, 5 * sizeof(GLfloat), 3, 5 * sizeof(GLfloat));
    
    QMatrix4x4 projection;
    projection.perspective(45.0f, (float)width()/(float)height(), 0.01f, 1000.0f );    // Use perspective projection
    
    
    m_sampleProgram.setUniformValue( projAttr, projection );                        // Set projection to the shader
    
    // Orientation for the <object> we are about to render
    QMatrix4x4 orientation;
    orientation.setToIdentity();
    orientation.translate(0.0f, 0.0f, -10.0f );                                      // 5 units away from camera
    static float ang = 0.0f;
    ang+=0.1f;
    orientation.rotate(ang, 1.0f, 0.0f, 0.0f );
    orientation.rotate(ang*0.7f, 0.0f, 1.0f, 0.0f );
    orientation.rotate(ang*1.4f, 0.0f, 0.0f, 1.0f );
    m_sampleProgram.setUniformValue( matrixAttr, orientation );                     // Set orientation to the shader
    
    glEnable(GL_DEPTH_TEST);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glDrawElements(GL_TRIANGLES, faceCount, GL_UNSIGNED_SHORT, 0);          // draw the 3d <object>
    
    m_sampleProgram.disableAttributeArray(vertexAttr);                              // Disable the program
    m_sampleProgram.disableAttributeArray(texAttr);
    m_sampleProgram.disableAttributeArray(normalAttr);
    
    vertexBuffer.release();
    indexBuffer.release();
    
    m_sampleProgram.release();
    swapBuffers();                                                                  // Swap buffers manually since automatic swapping was disabled in a constructor.
    

    };

    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      minimoog77
      wrote on last edited by
      #2

      @m_sampleProgram.enableAttributeArray(vertexAttr);
      m_sampleProgram.setAttributeBuffer(vertexAttr, GL_FLOAT, 0 * sizeof(GLfloat), 3, 5 * sizeof(GLfloat));
      m_sampleProgram.enableAttributeArray(texAttr);
      m_sampleProgram.setAttributeBuffer(texAttr, GL_FLOAT, 3 * sizeof(GLfloat), 2, 6 * sizeof(GLfloat));
      m_sampleProgram.enableAttributeArray(normalAttr);
      m_sampleProgram.setAttributeBuffer(normalAttr, GL_FLOAT, 5 * sizeof(GLfloat), 3, 5 * sizeof(GLfloat));@

      Looks like vertex strides are wrong.

      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