Results 1 to 4 of 4

Thread: Vertex array object with lines

  1. #1
    Member Contributor
    Join Date
    Jun 2015
    Posts
    60

    Vertex array object with lines

    I am trying to draw a set of crosshairs. I am following the learnopengl.com example. Do I need to have a shader if I only want to draw lines and not other geometric objects? The example shows a triangle. He instances a shader so it will fill the triangle correctly. Do I need to have a shader if i am only drawing lines? I am drawing other lines without a shader, but they are dynamic and I am using glBegin/glEnd with glVertex3f calls to do it.

    Here is my initialization code:

    Code :
    GLuint CH1_VBO[Output_Count], CH1_VAO[Output_Count];
    GLfloat CH1_Vertices[] = { -0.235,  0.000, 0.950,
                               -0.176,  0.000, 0.950,
                               -0.118,  0.000, 0.950,
                               -0.059,  0.000, 0.950,
                                0.059,  0.000, 0.950,
                                0.118,  0.000, 0.950,
                                0.176,  0.000, 0.950,
                                0.235,  0.000, 0.950,
                               -0.029,  0.412, 0.950,
                                0.029,  0.412, 0.950,
                               -0.059,  0.206, 0.950,
                                0.059,  0.206, 0.950,
                               -0.059, -0.206, 0.950,
                                0.059, -0.206, 0.950,
                               -0.029, -0.412, 0.950,
                                0.029, -0.412, 0.950 };
     
        glGenVertexArrays( 1, &CH1_VAO[Output] );
        glGenBuffers( 1, &CH1_VBO[Output] );
     
        glBindVertexArray( CH1_VAO[Output] );
          glBindBuffer( GL_ARRAY_BUFFER, CH1_VBO[Output] );
          glBufferData(GL_ARRAY_BUFFER, sizeof(CH1_Vertices), CH1_Vertices, GL_STATIC_DRAW);
        glBindVertexArray( 0 );

    once inside the main loop for each output display, I call:

    Code :
                glBindVertexArray( CH1_VAO[Output] );
                glDrawArrays( GL_LINES, 0, 16 );
                glBindVertexArray( 0 );

    absolutely nothing happens. I know the output is being rendered, because I have text being rendered to each output channel.

    What am I missing?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,110
    Quote Originally Posted by advorak View Post
    Do I need to have a shader if I only want to draw lines and not other geometric objects? The example shows a triangle. He instances a shader so it will fill the triangle correctly. Do I need to have a shader if i am only drawing lines?
    Whether or not you need a shader has nothing to do with whether you're drawing lines or triangles.

    You need to use a shader if you don't want to use the fixed-function pipeline .If you're using an OpenGL 3+ core profile context, the fixed-function pipeline isn't available so you have to use shaders for any rendering.

    In the compatibility profile, you can mix old and new features more or less freely. E.g. you can use VBOs and VAOs to specify vertex attributes for the fixed-function pipeline, or you can use glBegin/glEnd to specify vertex attributes for a shader program.

    Quote Originally Posted by advorak View Post
    Here is my initialization code:

    Code :
        glBindVertexArray( CH1_VAO[Output] );
          glBindBuffer( GL_ARRAY_BUFFER, CH1_VBO[Output] );
          glBufferData(GL_ARRAY_BUFFER, sizeof(CH1_Vertices), CH1_Vertices, GL_STATIC_DRAW);
        glBindVertexArray( 0 );

    absolutely nothing happens. I know the output is being rendered, because I have text being rendered to each output channel.

    What am I missing?
    Nowhere in the posted code do you call glVertexAttribPointer() (or glVertexPointer()) to associate the array with a vertex attribute. When you subsequently call glDrawArrays(), the VAO is still in its default state.

  3. #3
    Member Contributor
    Join Date
    Jun 2015
    Posts
    60
    You had me until you started talking about OpenGL 3+ core profile context -vs- compatibility profile. Could you expound on this a little?

    I have the fixed-function pipeline available to me as I have drawn other very dynamic lines, but it appears i can not mix the modes as in your "compatibility profile."

    I understood you to say I need a shader even if i am only drawing lines. As I need a shader for other objects on the screen, I will implement it now.

    Thank you for your help.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,110
    Quote Originally Posted by advorak View Post
    You had me until you started talking about OpenGL 3+ core profile context -vs- compatibility profile. Could you expound on this a little?
    OpenGL 3+ has two profiles: core and compatibility. In the core profile, legacy features such as glBegin/glEnd() and the fixed-function pipeline aren't available. The compatibility profile has all of the legacy features as well as the newer ones.

    The main reasons for using the core profile are simplicity (you don't need to understand how legacy features interact with newer features, as the legacy features don't exist), and the fact that some platforms (notably Mac) only provide a compatibility profile for older OpenGL versions (the Mac only offers a compatibility profile for OpenGL 2.1, so if you want to use newer features you're limited to the core profile).

    Quote Originally Posted by advorak View Post
    I understood you to say I need a shader even if i am only drawing lines.Thank you for your help.
    No. If legacy features such as glBegin/glEnd work, then you don't need a shader. However, if you aren't using a shader, you need to use the fixed-function attributes, i.e. glVertexPointer() etc rather than glVertexAttribPointer(). Bindings for fixed-function attributes are stored in VAOs alongside those for user-defined attributes.

    In any case, you appear to have missed my main point:
    Quote Originally Posted by GClements View Post
    Nowhere in the posted code do you call glVertexAttribPointer() (or glVertexPointer()) to associate the array with a vertex attribute. When you subsequently call glDrawArrays(), the VAO is still in its default state.
    That's the fundamental reason why you aren't getting anything; you've created and filled a buffer but haven't told OpenGL to use it to obtain the vertex positions (as well as calling glVertexPointer(), you also need to enable GL_VERTEX_ARRAY).

Similar Threads

  1. Vertex array object
    By gwartney in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-24-2016, 03:51 AM
  2. Vertex Array Object and vertex buffer object
    By Xxacero in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-23-2015, 05:13 AM
  3. Vertex Array Object vs. Vertex Buffer Object
    By michaelglaz in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-26-2014, 02:52 PM
  4. Vertex array object
    By Pswin in forum OpenGL: Advanced Coding
    Replies: 36
    Last Post: 08-26-2009, 10:02 AM
  5. Vertex Array Object
    By fgiannon in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 12-12-2003, 02:27 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