0

the function glEvalCoord2f() takes two coordinates as arguments and gives back a point in 3d space,I want to get the point with 3d coordinate,how to do it ?here is my code:

#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
#include <vector>

int  PI = 3.145;
int y = 0;


GLfloat ctrlpoints[4][4][3] = {
    {{-3.5, 1.0, -4.5},  {-0.5, 1.0,-4.5 }, {0.5, 1.0, -4.5 },   {3.5, 1.0,-4.5}},
    {{-3.5, 1.0, -0.5},  {-0.5, -2.0 - y,-0.5 }, {0.5, -2.0 - y, -0.5 }, {3.5, 1.0,-0.5}},
    {{-3.5, 1.0,  0.5},  {-0.5, 1.0, 0.5 }, {0.5, 1.0,  0.5 },   {3.5, 1.0, 0.5}},
    {{-3.5, 1.0,  4.5},  {-0.5, 1.0, 4.5 }, {0.5, 1.0,  4.5 },   {3.5, 1.0, 4.5}}
};
void initMap(void)
{
    glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &ctrlpoints[0][0][0]);
    glEnable(GL_MAP2_VERTEX_3);
    glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
}

void myMouse(int button, int state, int px, int py)
{
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {`your text`
        ctrlpoints[1][1][1] -= 1.0f;
        ctrlpoints[1][2][1] -= 1.0f;
    }
    initMap();
    glutPostRedisplay();
}

void init(void)
{
    //glClearColor(1.0, 1.0, 1.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_FLAT);
    initMap();
}

void display(void)
{

    int i, j;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(0.0, 1.0, 1.0);
    glPushMatrix();
    glRotatef(45.0, 1.0, 1.0, 1.0);



    for (j = 0; j <= 50; j++) {
        glBegin(GL_LINE_STRIP);
        for (i = 0; i <= 50; i++)
        {
            glEvalCoord2f((GLfloat)i / 50.0, (GLfloat)j / 50.0);//how to do it ?
        }
        glEnd();
        //glBegin(GL_LINE_STRIP);
        //for (i = 0; i <= 50; i++)
        //{
        //    glEvalCoord2f((GLfloat)j / 50.0, (GLfloat)i / 50.0);
        //}
        //glEnd();
    }
    glPopMatrix();
    glPushMatrix();
    glColor3f(1, 1, 0);
    glPopMatrix();
    glFlush();
}


void reshape(int w, int h)
{
    glViewport(0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
        glOrtho(-5.0, 5.0, -5.0*(GLfloat)h / (GLfloat)w, 5.0*(GLfloat)h / (GLfloat)w, -5.0, 5.0);
    else
        glOrtho(-5.0*(GLfloat)w / (GLfloat)h, 5.0*(GLfloat)w / (GLfloat)h, -5.0, 5.0, -5.0, 5.0);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
        glutInitWindowSize(500, 500);
        glutInitWindowPosition(100, 100);
        glutCreateWindow(argv[0]);
        init();
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutMouseFunc(myMouse);
        glutMainLoop();
        return 0;
}

i try to google it ,but no one has the same problem. i am a freshman in OpenGL, it seems unreasonable that glEvalCoord2f() return void.I also try to use feedback like this

glFeedbackBuffer(3 * numPoints, GL_3D, feedbackBuffer);
(void)glRenderMode(GL_FEEDBACK);

but it return coordinate values in a two-dimensional screen which is useless

0 Answers0