i'm trying draw quad background (2d) using opengl 3.x+. quads deprecated, goal use 2 triangles make rectangle fills screen. it's working, i'm not 100% clear on here.
setup
gluint positionbufferobject; glfloat vertexpositions[] = { -1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, }; glgenbuffers(1, &positionbufferobject); glbindbuffer(gl_array_buffer, positionbufferobject); glbufferdata(gl_array_buffer, sizeof(vertexpositions), vertexpositions, gl_static_draw);
- i understand
vertexpositions
, it's array of vertices. glgenbuffers()
saying, want 1 buffer , assign id&positionbufferobject
?glbufferdata()
uploadsvertexpositions
gpu's memory; how know upload since didn't give id?
- i understand
draw
glenablevertexattribarray(0); glvertexattribpointer(0, 4, gl_float, gl_false, 0, 0); gldrawarrays(gl_triangle_strip, 0, 5); gldisablevertexattribarray(0);
glenablevertexattribarray()
says i'm going drawing array 0?gldrawarrays()
- if want draw 2 vertex arrays? how know ones render? knows above command?- not sure
glvertexattribpointer()
does? gldrawarrays()
clear.
clean up, think right?
glbindbuffer(gl_array_buffer, 0); gldeletebuffers(1, &positionbufferobject);
i setup/cleanup once.
bonus points:
- is effective way render this? read i'm suppose submitting , rendering in "batches" [?] since 3.x+ doesn't immediate mode more. there 1 array, batches won't performance in case, if had "a large number" of vertxarrays draw, same process?
- in setup storing array id positionbufferobject, have hardcoded in rendering loop. seems confusing after dozen or arrays, why isn't practice use variable instead of hardcode it?
glgenbuffers(1, &positionbufferobject);
says "make vertex buffer object, , positionbufferobject
id."
glbindbuffer(gl_array_buffer, positionbufferobject);
says "positionbufferobject
current gl_array_buffer
."
glbufferdata(gl_array_buffer, sizeof(vertexpositions), vertexpositions, gl_static_draw);
says "upload vertexpositions
id bound gl_array_buffer
(which positionbufferobject
)."
glenablevertexattribarray(0);
says "vertex attribute array 0 available use."
glvertexattribpointer(0, 4, gl_float, gl_false, 0, 0);
says "vertex attribute array 0 interpreted consisting of groups of 4 floats."
gldrawarrays(gl_triangle_strip, 0, 5);
says "draw triangle strip 5 indices every enabled array."
gldisablevertexattribarray(0);
says "we're done time being vertex attribute array 0."
Comments
Post a Comment