c++ - Vertex Buffer Objects Open GL -


i new open gl , trying build non deprecated code. can't grasp vbo. got far, can please explain i'm supposed doing. also, have opengl programming guide, if can point out pages read helpful well.

#include <gl/glew.h> #include <gl/freeglut.h>   gluint id[2]; glfloat positiondata[][2] ={{50,50},{100,50},{50,100}, {100,50}, {100, 100}, {50, 100}}; glfloat colors[][3] = {{0.1, 0.2, 0.3},{0.1, 0.2, 0.3},{0.1, 0.2, 0.3},{0.1, 0.2, 0.3},{0.1, 0.2, 0.3}};  void init(){     glewinit();     glclearcolor(1.0, 1.0, 1.0, 0.0); }  void display(){     glclear(gl_color_buffer_bit);     glshademodel(gl_flat);     glgenbuffers(2, id);     glbindbuffer(gl_array_buffer, id[0]);     glbufferdata(gl_array_buffer, sizeof(positiondata), positiondata, gl_static_draw);     glenableclientstate(gl_vertex_array);     glvertexattribpointer(0, 3, gl_float, gl_false, 0, 0);     glenablevertexattribarray(0);     glbindbuffer(gl_array_buffer, id[1]);     glbufferdata(gl_array_buffer, sizeof(colors), colors, gl_static_draw);     glenableclientstate(gl_color_array);     glvertexattribpointer(1, 3, gl_float, gl_false, 0, 0);     glenablevertexattribarray(1);      gldrawarrays(gl_triangles, 0, 12);      gldisablevertexattribarray(0);     gldisablevertexattribarray(1);     gldeletebuffers(2, id);     glflush(); }  void reshape(int w, int h){     glviewport(0,0, (glsizei) w, (glsizei) h);     glmatrixmode(gl_projection);     glloadidentity();     gluortho2d(0.0f, (gldouble) w, 0.0f, (gldouble) h); }  int main(int argc, char *argv[]){     glutinit(&argc, argv);     glutinitdisplaymode(glut_single | glut_rgb);     glutinitwindowsize(500, 500);     glutinitwindowposition(100, 100);     glutcreatewindow("i don't vbos");     init();     glutdisplayfunc(display);     glutreshapefunc(reshape);     glutmainloop();     return 0; } 

i did quick on code, 1 thing stood out: you're missing point of vbos. in each draw call you're creating vbo objects, upload data, try draw them (it won't work, because shaders giving vertex attributes sense misssing) , delete them.

the whole point of vbo upload geometry data gl object once , refer it's abstract object id handle , index arrays, 1 place in buffer object.

but there's else screwed in code, setting projection matrix in reshape callback. 1 thing, in opengl-3 core don't have built-in matrices anymore. it's shader uniforms. , set matrices on demand in rendering handler.

i think should write definitive opengl-3 core tutorial, demonstrating proper idioms.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -