Sign in to follow this  
cebugdev

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.

Capture.PNG.e0beae7488bce4a839cf96ce8d33b986.PNG

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

Capture2.PNG.735ef25c81808e71e7753d4c6c187e50.PNG

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 this post


Link to post
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! 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this