2013-10-19 76 views
0

我想從glEvalCoord中讀取值,但沒有得到我應該得到的確切值。我的代碼是glEvalCoord與glFeedback一起使用時沒有按預期輸出

GLfloat ctrlpoints[4][3] = { 
    { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, 
    { 2.0, -4.0, 0.0}, { 4.0, 4.0, 0.0}}; 

void display() 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glEnable(GL_LIGHTING); 
    glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); 
    glEnable(GL_MAP1_VERTEX_3); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    GLint size; 
    GLfloat feedBuffer[1024]; 

    glFeedbackBuffer (1024, GL_3D, feedBuffer); 
    glRenderMode (GL_FEEDBACK); 
    glBegin (GL_POINTS); 
    for (int i=0; i<=30; ++i) 
    { 
     GLfloat t = GLfloat(i)/30; 
     glEvalCoord1f(t); 
    } 
    glEnd(); 
    size = glRenderMode (GL_RENDER); 
    cerr<<size<<endl; 
} 

現在,我不知道,但它不應該給我30個* 3值爲每個曲線的x,y和z座標?但我只獲得7 * 3的值。尺寸輸出爲28.

回答

1

我認爲您的size28,因爲您的投影/模型視圖對正在裁剪出一些點。

"In feedback mode, each primitive that would be rasterized ... generates a block of values that's copied into the feedback array."

嘗試這種情況:

#include <GL/glut.h> 
#include <iostream> 

using namespace std; 

void display() 
{ 
    glClear(GL_COLOR_BUFFER_BIT); 

    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    double w = glutGet(GLUT_WINDOW_WIDTH); 
    double h = glutGet(GLUT_WINDOW_HEIGHT); 
    double ar = w/h; 
    glOrtho(-5 * ar, 5 * ar, -5, 5, -1, 1); 

    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 

    GLfloat ctrlpoints[4][3] = 
    { 
     { -4.0, -4.0, 0.0 }, { -2.0, 4.0, 0.0 }, 
     { 2.0, -4.0, 0.0 }, { 4.0, 4.0, 0.0 } 
    }; 

    glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]); 
    glEnable(GL_MAP1_VERTEX_3); 

    GLfloat feedBuffer[1024]; 
    glFeedbackBuffer (1024, GL_3D, feedBuffer); 
    glRenderMode (GL_FEEDBACK); 

    glPointSize(5); 
    glColor3ub(255, 255, 255); 
    glBegin (GL_POINTS); 
    for (int i=0; i<=30; ++i) 
    { 
     GLfloat t = GLfloat(i)/30; 
     glEvalCoord1f(t); 
    } 
    glEnd(); 

    GLint size = glRenderMode (GL_RENDER); 
    cerr << size << endl; 

    glutSwapBuffers(); 
} 

int main(int argc, char **argv) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); 
    glutInitWindowSize(640, 480); 
    glutCreateWindow("GLUT"); 
    glutDisplayFunc(display); 
    glutMainLoop(); 
    return 0; 
} 

我添加了一個略大投影矩陣。

隨着我得到一個124size:每點

  • 31分* 3個浮子= 93
  • 31分* 1 GL_POINT_TOKEN每點= 31

31 + 91 = 124

+0

好吧,明白了。謝謝 – pcoder

相關問題