c++ - OpenGl project with drawPrimitive() -


i trying change c++ project, drawing lines when click on view port. functionality fine, trying change when click on "up" or "down" keys color next lines change. if click on keys color changes lines including old ones (already drawn).

please give me idea of do. here of code:

void drawprimitive() { vertex *temp;  //  set primitive color glcolor3fv(primitivecolor);  //  set point size in case drawing point if (type == point)     glpointsize(pointsize);  //  display results depending on mode glbegin(mode);     for(temp = head; temp != null; temp = temp->np)     {         if (smoothshading)             glcolor3f(temp->r, temp->g, temp->b);          glvertex2f(temp->x, temp->y);     } glend(); }   void mouse(int button, int state, int x, int y) { if(button == glut_left_button && state == glut_down) {     float pointx, pointy;      pointx = (float)x/window_width * world_width;     pointy = (float)(window_height - y)/window_height * world_height;      //  add vertex list of vertices...     addvertex(&head, &tail, pointx, pointy, 0.0f, primitivecolor[0], primitivecolor[1], primitivecolor[2]);      //  automatically calls display function     glutpostredisplay(); } else if(button == glut_middle_button && state == glut_down) {     deletevertex(&head, &tail);     glutpostredisplay(); } }   void special(int key, int x, int y) { switch (key) {     //  change primitive color     case glut_key_up :         changeprimitivecolor(1);         break;     case glut_key_down :         changeprimitivecolor(-1);         break; }  glutpostredisplay(); }   void changeprimitivecolor(int step) { primitivecolorid += step;  if (primitivecolorid < 0)     primitivecolorid = color_count - 1;  if (primitivecolorid >= color_count)     primitivecolorid = 0;  setcolor(primitivecolor, primitivecolorid); } 

your code sort of unclear; primitivecolor global variable?

assuming you're calling drawprimitive() lines each redraw, same primitivecolor used lines. change color when press or down, redisplay function called, , lines redrawn using same color.

what might want have list containing both primitives , respective colors. when iterate through list, can set color each line.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -