0
我在WinAPI中使用OpenGL创建2D线图。我的点绘制在点的大小为8,我想调整绘制点的高度(以及连接它们的线),使点的位置在适当的y位置(即,使点在0处不被x轴分割)。在Windows上以像素为单位获取OpenGL点大小?
我有一个硬编码的调整,但我宁愿让它与绘制的点大小进行比例缩放,以便当它绘制在不同大小的窗口中时,它的工作原理是一样的。
这里是我的绘制点和连接它们的线法:
void plotScores() {
if (samples > 1) { //if this is at least the second score, connect the scores with a line
glLineWidth(12.0);
GLdouble lineXPos = 0, lineYPos = 0;
glColor3d(0.3, 0.3, 0.3);
glBegin(GL_LINE_STRIP);
for (int i = 0; i < scores.size(); i++) {
lineXPos = (i * 0.05) - 0.88;
lineYPos = ((scores[i] - 0.5) * 1.6); //need to adjust this for line y-position...
glVertex2d(lineXPos, lineYPos);
}
glEnd();
}
for (int i = 0; i < scores.size(); i++) {
GLdouble pointXPos = (i * 0.05) - 0.88;
GLdouble pointYPos = ((scores[i] - 0.5) * 1.6); //...and this for point y-position
if (scores[i] >= threshold) {
glColor3d(0.0, 1.0, 0.2);
}
else {
glColor3d(1.0, 0.2, 0.0);
}
glBegin(GL_POINTS);
glVertex2d(pointXPos, pointYPos);
glEnd();
}
}
我在找的是像素的实际数量,而不是点的大小。我需要“调整”相当于他们身高一半的点数。理想情况下,我不会硬编码值 - 我想获得值,除以2,并将其添加到Y位置。 –
@NickR:'glPointSize'已经以像素为单位。它如何转换为视口坐标取决于你的变换矩阵。 – ybungalobill