Advertisement

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

Started by October 11, 2017 03:44 AM
2 comments, last by cebugdev 7 years, 3 months ago

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)

3 hours ago, cebugdev said:

glDrawArrays(GL_LINE_STRIP, 0, 4)

Why 4 if you only draw 2 vertices ?

Advertisement
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! 

This topic is closed to new replies.

Advertisement