其他分享
首页 > 其他分享> > c – glEvalCoord与glFeedback一起使用时没有按预期提供输出

c – glEvalCoord与glFeedback一起使用时没有按预期提供输出

作者:互联网

我试图从glEvalCoord读取值,但没有得到我应该得到的确切值.我的代码是

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

现在,我不确定但不应该为曲线的x,y和z坐标给出30 * 3的值?但我只得到7 * 3的价值.而输出的大小是28.

解决方法:

我认为你的尺寸是28,因为你的投影/模型视图对剪掉了一些点.

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

我添加了一个略大的投影矩阵.

有了这个我得到124的大小:

> 31分*每点3个浮点数= 93
> 31分* 1每点GL_POINT_TOKEN = 31

31 91 = 124

标签:c,opengl,evaluator
来源: https://codeday.me/bug/20191002/1842841.html