glEvalCoord when used with glFeedback is not giving output as expected

五迷三道 提交于 2019-11-29 12:45:58

I think your size is 28 because your projection/modelview pair is clipping out some points.

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

Try this:

#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;
}

I added a slightly larger projection matrix.

With that I get a size of 124:

  • 31 points * 3 floats per point = 93
  • 31 points * 1 GL_POINT_TOKEN per point = 31

31 + 91 = 124

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!