2017-07-27 58 views
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(); 
} 
} 

回答

5

您可以設置點的大小與glPointSize,所以應該知道價值。如果因爲某些原因想要查詢它,可以使用glGetGL_POINT_SIZE枚舉來完成。

+0

我在找的是像素的實際數量,而不是點的大小。我需要「調整」相當於他們身高一半的點數。理想情況下,我不會硬編碼值 - 我想獲得值,除以2,並將其添加到Y位置。 –

+0

@NickR:'glPointSize'已經以像素爲單位。它如何轉換爲視口座標取決於你的變換矩陣。 – ybungalobill

相關問題