• 9
• 9
• 10
• 9
• 10

# OpenGL Linestrip adds extra line at 0,0 (2D space)

## Recommended Posts

im trying to test GL_Line strip by drawing line strips between points and it always starts at 0,0 even i start to draw at the middle of the screen.

i simplified my test data to just draw two points but still the same.

the result is the line is drawn from 0,0 to any points in my vertices.

Im using orthographic projection and pases 2D vectors to my shaders to draw it on 3D, but that is not the concern.

here is my non simplified testing: im trying to draw linestrips using mouse, but it always starts at 0,0

Here is the code (the simplified version/first image)

	float vertices[] = {

SCR_WIDTH/2,SCR_HEIGHT/2,
SCR_WIDTH,SCR_HEIGHT,
};

unsigned int VBO = 0;
unsigned int VAO = 0;
glGenBuffers(1, &VBO);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(float),
vertices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glDrawArrays(GL_LINE_STRIP, 0, 4);


Im using OpenGL 3.1 right now on desktop as i am writing a code that will be ported to OpenGL ES 2.0 after i write it in desktop, (android studio is slow so i do my opengl coding in Visual Studio)

Edited by cebugdev

##### Share on other sites
3 hours ago, cebugdev said:

glDrawArrays(GL_LINE_STRIP, 0, 4)

Why 4 if you only draw 2 vertices ?

##### Share on other sites
39 minutes ago, _Silence_ said:

Why 4 if you only draw 2 vertices ?

oh god youre correct, silly me, i originally thought that the last parameter is for the number of data.

Thanks man!