Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing a single line in glsl
    primarykey
    data
    text
    <p>I am trying to draw a single line as a part of learning OpenGL 4.x and above. Here are the shaders that I am using.</p> <p>Vertex Shader</p> <pre><code> "#version 430 core \n" " \n" "void main(void) \n" "{ \n" " const vec4 vertices[2] = vec4[2](vec4(0.25,-0.25,0.5,1.0),vec4(-0.25,-0.25,0.5,1.0)); \n" " gl_Position = vertices[gl_VertexID]; n" "} \n" </code></pre> <p>and Fragment Shader</p> <pre><code> "#version 430 core \n" " \n" "out vec4 color; \n" " \n" "void main(void) \n" "{ \n" " color = vec4(0.0, 0.8, 0.0, 1.0); \n" "} \n" </code></pre> <p>And here is what I do in my <code>display()</code> function.</p> <pre><code>void display() { static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f }; glClearBufferfv(GL_COLOR, 0, red); glUseProgram(program); glLineWidth(8.0f); glDrawArrays(GL_LINES, 0, 2); glFlush(); } </code></pre> <p>However, nothing gets drawn in the window except red color. I have read <a href="https://stackoverflow.com/questions/5458185/drawing-lines-with-glsl">this</a>,<a href="https://stackoverflow.com/questions/11594247/opengl-lines-with-shaders">this</a> and <a href="https://stackoverflow.com/questions/11594804/opengl-shader-two-object-and-one-line-to-connect-them">this</a> questions. Two of them refer me to use Vertex Buffers and the third one tells me to draw a triangle with two vertices in the same position. </p> <p>My question is, why does <code>glDrawArrays(GL_LINES, 0, 2)</code> in my code fail to draw a single line? Or is it essential that I use Vertex Array Buffers when I need to draw a single line?</p> <p>UPDATE:</p> <p>Here is the code from the <code>main()</code> function.</p> <pre><code>startShaders(); while (!glfwWindowShouldClose(window)) { RenderFunction(); glfwSwapBuffers(window); glfwPollEvents(); } shutdown(); cout &lt;&lt; "INFO: OpenGL Version: " &lt;&lt; glGetString(GL_VERSION) &lt;&lt; endl; glfwTerminate(); exit(EXIT_SUCCESS); </code></pre> <p>And here is my <code>RenderFunction()</code> that calls <code>Display()</code> function.</p> <pre><code>void RenderFunction() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); display(); } </code></pre> <p>UPDATE 2: Here is the pic of console window displaying <code>stderr</code> output. <img src="https://i.stack.imgur.com/hXj4z.jpg" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload