【发布时间】:2018-09-16 03:21:43
【问题描述】:
我想在鼠标点击的位置绘制随机大小的方块。但是我的代码改变了已经绘制的矩形的大小。我想问一下如何更改我的代码以不更改之前绘制的矩形的大小。 这是我的代码。
GLfloat myVertices[10][2];
GLint count = 0;
std::default_random_engine(dre);
std::uniform_int_distribution<> uid(10, 100);
void Mouse(int button, int state, GLint x, GLint y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
myVertices[count][0] = x;
myVertices[count][1] = (600 - y);
count++;
}
}
GLvoid drawScene()
{
GLint index;
if (count > 0)
{
for (index = 0; index < count; index++)
{
glRectf(myVertices[index][0], myVertices[index][1], myVertices[index][0] + uid(dre), myVertices[index][1] + uid(dre));
}
}
glFlush();
}
【问题讨论】: