Reputation: 269
I'm needing some help with some c++/OpenGL coding. What I'm doing is a polygon approximation algorithm.
My code first pulls in a set of points from a .txt file, stores them all in an array and then displays that array. It then takes those points and performs the algorithm on them, and creates a new array of points. What I can't figure out how to do, is how to get that second set of points displayed on the same window as the first. Do I have to create a new display function and call that one? Or maybe modify the basic display function that I have now to accept an array? Here's the code for my display function:
void display(void){
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
glBegin(GL_POINTS);
for(int i=0; i<2000; i++)
glVertex2i(pixel[i].x,pixel[i].y);
glEnd();
glFlush();
}
Upvotes: 0
Views: 125
Reputation: 2239
You just need to draw the processed array. Considering that you just want to render the resulting points, like in your code sample, you could use:
void display(void){
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
glBegin(GL_POINTS);
for(int i=0; i<2000; i++)
glVertex2i(pixel[i].x,pixel[i].y);
// here goes the rendering of the new set of points.
glColor3f(1,0,0); // change the color so we can see better the new points.
for(int i=0; i<2000; i++)
glVertex2i(result[i].x,result[i].y);
glEnd();
glFlush();
}
The variable result
is your array with the results of the processing.
You can not modify the display
function since it is called by the OpenGL and it does not know about your arrays. But nothing goes against you splitting your code into many functions called by your display
function.
Hope it helps.
Upvotes: 1