jeudi 27 juillet 2017

OpenGL: How to get point size in pixels? (WinAPI)

I am using OpenGL in WinAPI to create a 2D line graph. My points are plotted in point size 8, and I want to adjust the height of the plotted points (and the line connecting them) so that the bottom of the point is at the proper y-position (i.e., so that a point at 0 isn't split by the x-axis).

I had an adjustment hard-coded, but I would rather have it scale with the plotted point size, so that when it's plotted in a different size window, it works the same.

Here is my method for plotting the points and the line connecting them:

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

Thanks!

Aucun commentaire:

Enregistrer un commentaire