visual c++ - can anyone explain following opengl code? -


can 1 explain how glvertex3fv works when function call

glfloat v[][8][3]={{{-1.5,-1.5,-1.0}, {-1.3,-1.5,-1.0}, {-1.3,-1.3,-1.0}, {-1.5,-1.3,-1.0}, {-1.6,-1.6,1.0}, {-1.4,-1.6,1.0}, {-1.4,-1.4,1.0}, {-1.6,-1.4,1.0}} ,  {{-1.3,-1.5,-1.0}, {-1.1,-1.5,-1.0}, {-1.1,-1.3,-1.0}, {-1.3,-1.3,-1.0}, {-1.4,-1.6,1.0}, {-1.2,-1.6,1.0}, {-1.2,-1.4,1.0}, {-1.4,-1.4,1.0}} ,  {{-1.1,-1.5,-1.0}, {-0.9,-1.5,-1.0}, {-0.9,-1.3,-1.0}, {-1.1,-1.3,-1.0}, {-1.2,-1.6,1.0}, {-1.0,-1.6,1.0}, {-1.0,-1.4,1.0}, {-1.2,-1.4,1.0}} ,  {{-1.5,-1.3,-1.0}, {-1.3,-1.3,-1.0}, {-1.3,-1.1,-1.0}, {-1.5,-1.1,-1.0}, {-1.6,-1.4,1.0}, {-1.4,-1.4,1.0}, {-1.4,-1.2,1.0}, {-1.6,-1.2,1.0}} ,  {{-1.3,-1.3,-1.0}, {-1.1,-1.3,-1.0}, {-1.1,-1.1,-1.0}, {-1.3,-1.1,-1.0}, {-1.4,-1.4,1.0}, {-1.2,-1.4,1.0}, {-1.2,-1.2,1.0}, {-1.4,-1.2,1.0}} ,  {{-1.1,-1.3,-1.0}, {-0.9,-1.3,-1.0}, {-0.9,-1.1,-1.0}, {-1.1,-1.1,-1.0}, {-1.2,-1.4,1.0}, {-1.0,-1.4,1.0}, {-1.0,-1.2,1.0}, {-1.2,-1.2,1.0}} ,  {{-1.5,-1.1,-1.0}, {-1.3,-1.1,-1.0}, {-1.3,-0.9,-1.0}, {-1.5,-0.9,-1.0}, {-1.6,-1.2,1.0}, {-1.4,-1.2,1.0}, {-1.4,-1.0,1.0}, {-1.6,-1.0,1.0}} ,  {{-1.3,-1.1,-1.0}, {-1.1,-1.1,-1.0}, {-1.1,-0.9,-1.0}, {-1.3,-0.9,-1.0}, {-1.4,-1.2,1.0}, {-1.2,-1.2,1.0}, {-1.2,-1.0,1.0}, {-1.4,-1.0,1.0}} ,  {{-1.1,-1.1,-1.0}, {-0.9,-1.1,-1.0}, {-0.9,-0.9,-1.0}, {-1.1,-0.9,-1.0}, {-1.2,-1.2,1.0}, {-1.0,-1.2,1.0}, {-1.0,-1.0,1.0}, {-1.2,-1.0,1.0}}};  glfloat colors[][3]={{0.0,0.0,0.0}, //black  {1.0,0.0,0.0}, //red  {1.0,1.0,0.0}, //yellow  {0.0,1.0,0.0}, //green  {1.0,0.0,1.0}, //magenta  {0.0,1.0,1.0}}; //cyan ....  void polygon(int a,int b,int c,int d,int i)  {  glbegin(gl_polygon);  glcolor3fv(colors[a]);  glvertex3fv(v[i][a]); //wt meaning of line  glcolor3fv(colors[b]);  glvertex3fv(v[i][b]);  glcolor3fv(colors[c]);  glvertex3fv(v[i][c]);  glcolor3fv(colors[d]);  glvertex3fv(v[i][d]);  glflush();  glend(); }  void colorcube() {  polygon(0,3,2,1,i); //wt meaning of  polygon(2,3,7,6,i);  polygon(0,4,7,3,i);  polygon(1,2,6,5,i);  polygon(4,5,6,7,i);  polygon(0,1,5,4,i);  } 

notice: opengl immediate drawing mode. it's been deprecated , discouraged use 20(!) years. in 1996 opengl-1.1 introduced vertex arrays preferred on immediate mode ever since.

glvertex part of old, deprecated opengl immediate drawing mode. between glbegin … glend block arbitrary number of glvertex calls used draw primitives screen; control attributes of drawn attribute setting call preceding glvertex call "selects" glvertex emit.

a vertex whole combinations of attribute specified + position.

first lets @ single points:

glbegin(gl_points); /* every call of glvertex draw point */  /* tip "pen" bucket of bright red */ glcolor3f(1,0,0); /* draw point, whatever color set @ 1,1,1 */ glvertex3f(1,1,1);  /* let's make pen blue */ glcolor3f(0,0,1);  /* wait, want green */ glcolor3f(0,1,0); /* last value set attribute matters.  * point drawn @ 0,1,0 green */ glvertex3f(0,1,0);  /* , on */ /* ... */  glend(); 

the difference drawing gl_points gl_lines or gl_triangles is, have emit pairs or triplets of vertices appear on screen (all withing glbegin, glend block).

now have data attributes contained in larger memory buffer. in case makes more sense point attribute setter functions memory instead of passing parameters. denoted letter 'v' in opengl call name. so

glfloat red_green_blue[3][3] = {    {1,0,0},    {0,1,0},    {0,0,1} };  glcolor3fv(red_green_blue[0]) /* points 'red' part */ 

this equivalent to

glcolor3f(     red_green_blue[0][0],     red_green_blue[0][1],     red_green_blue[0][2] ); 

obviously 'v' form shorter , easier read.

now in code boils down dereferencing locations multidimensional array. wondering 'i' means. suggest follow code pencil on sheet of paper , figure out in way values go opengl.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -