I have this code:
#include <iostream>
#include <vector>
using std::vector;
#ifdef __APPLE__
#include <GLUT/GLUT.h>
#else
#include <GL/GLUT.h>
#endif
#define heightWindow 500
#define widthWindow 500
struct point {
double x;
double y;
};
vector<struct point> arr(heightWindow);
void renderScene();
int main(int argc, char **argv)
{
int k = 0;
for (struct point& i : arr) {
i.x = k;
i.y = k;
k++;
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(widthWindow, heightWindow);
glutCreateWindow("2D NBody Problem");
glutDisplayFunc(renderScene);
glPointSize(3.0);
glutMainLoop();
return 1;
}
void renderScene() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
for (struct point& i : arr) {
glVertex2f(i.x, i.y);
}
glEnd();
glFinish();
glutSwapBuffers();
}
The way I have set up my code, it should print a diagonal set of points from the upper left to the bottom right. But when I run this, only one point is shown, at the center of the window.
Is there anything that I can do about this?