我是过剩的新手,我无法解决这个问题。我在鼠标点击时画了一个点,但总是只有最后一个点是可见的。我怎样才能使旧点不会消失,并且每次点击只需再添加一个?(不将所有点保存为变量或什么,只是让它们在绘制新点时不会从窗口中消失)非常感谢。
#include <iostream>
#include <math.h>
#include "gl/glut.h"
#include <windows.h>
using namespace std;
typedef struct {
float x;
float y;
} Point;
typedef struct {
int r;
int g;
int b;
} Color;
Point novy;
Color nova;
void Display(void){
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(8);
glBegin(GL_POINTS);
glColor3f(nova.r,nova.g,nova.b);
glVertex2f(novy.x,novy.y);
glEnd();
glFlush();
}
void onMouse(int button, int state, int x, int y){
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
novy.x = x / (double) 300 * (1 - (-1)) + (-1);
novy.y = (1 - y / (double) 300) * (1 - (-1)) + (-1);
glutPostRedisplay();
}
}
int main(void){
cout << "suradnice \n";
cin >> novy.x;
cin >> novy.y;
cout << "rgb farba \n";
cin >> nova.r;
cin >> nova.g;
cin >> nova.b;
glutCreateWindow("This is the window title");
glutDisplayFunc(Display);
glutMouseFunc(onMouse);
glutMainLoop();
return 0;
}