Results 1 to 4 of 4

Thread: how to send vertices array using buffer

  1. #1
    Newbie Newbie
    Join Date
    Apr 2015
    Posts
    1

    how to send vertices array using buffer

    i want to print vertices arrays using buffer, but i can't. please help me!!

    my Open GL version is 4.2

    in userinit part

    bool userInit()
    {

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glEnable( GL_CULL_FACE );
    glEnable( GL_DEPTH_TEST );

    vec4 vertices[6];

    vertices[0] = vec4(0.833f, -0.25f, 0, 1);
    vertices[1] = vec4(0.0f, 0.5f, 0, 1);
    vertices[2] = vec4(-0.833f, -0.25f, 0, 1);
    vertices[3] = vec4(0.833f, -0.25f, 0, 1);
    vertices[4] = vec4(0.0f, -0.8f, 0, 1);
    vertices[5] = vec4(-0.833f, -0.25f, 0, 1);

    glGenBuffers( 1, &vertexBuffer );
    glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );

    return true;
    }


    in render part

    void render()
    {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glUseProgram( pratice );

    GLuint vertexPositionLoc = glGetAttribLocation( pratice, "position" );
    glEnableVertexAttribArray( vertexPos );
    glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
    glVertexAttribPointer( vertexPos, 4, GL_FLOAT, GL_FALSE, 0, 0 );

    glDrawArrays(GL_TRIANGLES, 0, 6);

    glutSwapBuffers();

    }

    this source code prints only one triangle.

    why!?!?!?! what's wrong in this program??

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    Quote Originally Posted by shinx200 View Post
    i want to print vertices arrays using buffer, but i can't. please help me!!

    my Open GL version is 4.2
    in render part

    void render()
    {
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glUseProgram( pratice );

    GLuint vertexPositionLoc = glGetAttribLocation( pratice, "position" );
    glEnableVertexAttribArray( vertexPos );
    glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
    glVertexAttribPointer( vertexPos, 4, GL_FLOAT, GL_FALSE, 0, 0 );

    glDrawArrays(GL_TRIANGLES, 0, 6);

    glutSwapBuffers();

    }

    this source code prints only one triangle.

    why!?!?!?! what's wrong in this program??
    To show only one triangle is correct.
    if you add this statement again,
    glDrawArrays(GL_TRIANGLES, 3, 6);
    you could get the second triangle,

    beside, the pratice may be practice.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    296
    glDrawArrays(GL_TRIANGLES, 0, 6);
    and the correct written should be
    glDrawArrays(GL_TRIANGLES, 0, 3);
    thus you can show up to four triangles. despite you can get 15 triangles.

  4. #4
    Member Contributor
    Join Date
    Oct 2014
    Posts
    55
    Quote Originally Posted by shinx200 View Post
    glEnable( GL_CULL_FACE );

    vertices[0] = vec4(0.833f, -0.25f, 0, 1);
    vertices[1] = vec4(0.0f, 0.5f, 0, 1);
    vertices[2] = vec4(-0.833f, -0.25f, 0, 1);
    vertices[3] = vec4(0.833f, -0.25f, 0, 1);
    vertices[4] = vec4(0.0f, -0.8f, 0, 1);
    vertices[5] = vec4(-0.833f, -0.25f, 0, 1);
    You're using backface-culling but your two triangles are in different winding order. The coordinates of the first triangle are in counterclockwise ordering, the 3 following coordinates of the second triangle are in clockwise order.

    That means one of your triangles get culled away.

    Always take care to specify your coordinates in a consistent manner.

Similar Threads

  1. How to pass Array to Shader like Vertices?
    By RaenirSalazar in forum OpenGL: GLSL
    Replies: 3
    Last Post: 07-22-2014, 11:19 AM
  2. not able to send array using uniform buffer object
    By juanito in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-25-2014, 11:18 AM
  3. Discarding vertices possible using element array buffer?
    By samvdj in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-18-2013, 03:29 PM
  4. Replies: 1
    Last Post: 11-20-2013, 04:49 AM
  5. Send a texture buffer to a shader
    By Vylsain in forum OpenGL: GLSL
    Replies: 4
    Last Post: 11-16-2012, 01:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean