【问题标题】:Get OpenGL point size in pixels on Windows?在 Windows 上获取 OpenGL 点大小(以像素为单位)?
【发布时间】:2018-01-03 08:44:03
【问题描述】:

我在 WinAPI 中使用 OpenGL 来创建 2D 线图。我的点以点大小 8 绘制,我想调整绘制点的高度(以及连接它们的线),以便该点的 bottom 位于正确的 y 位置(即,这样 0 处的点就不会被 x 轴分割)。

我有一个硬编码的调整,但我宁愿让它与绘制的点大小一起缩放,这样当它在不同大小的窗口中绘制时,它的工作原理是一样的。

这是我绘制点和连接它们的线的方法:

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();
}
}

【问题讨论】:

    标签: c++ c++11 winapi opengl


    【解决方案1】:

    您使用glPointSize 设置磅值,因此您 应该知道该值。如果你以后因为某种原因想查询它,可以使用glGet和GL_POINT_SIZE枚举来完成。

    【讨论】:

    • 我正在寻找的是实际的像素数,而不是点的大小。我需要将这些点“调整”相当于它们高度的一半。理想情况下,我不会对值进行硬编码——我想获取该值,将其除以 2,然后将其添加到 Y 位置。
    • @NickR: glPointSize 已经是像素。它如何转换为视口坐标取决于您的转换矩阵。
    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多