code-d icon indicating copy to clipboard operation
code-d copied to clipboard

The usage of OpenGL is not accurate(Template OpenGL-SDL)

Open tim37021 opened this issue 8 years ago • 0 comments

https://github.com/Pure-D/code-d/blob/master/templates/EmptyOpenGL_SDL/source/app.d#L170

You are using vertex array object(VAO) here. It stores all the necessary information for drawing. There's no need to re-enable attribute arrays and respecify their format.

You can move the following code to loadscene

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
			3, // size
			GL_FLOAT, // type
			false, // normalized?
			0, // stride
			null  // array buffer offset
			);
	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
	glVertexAttribPointer(1, // attribute 1
			3, // size
			GL_FLOAT, // type
			false, // normalized?
			0, // stride
			null  // array buffer offset
			);

when rendering, simply...:

glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);

tim37021 avatar Nov 22 '17 14:11 tim37021