Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Learn to draw and deform a grid

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2012
    Posts
    4

    Learn to draw and deform a grid

    Helllo,I have a piece of code and i m trying to understand it.The code is to draw a grid and deform it according to a particular function.i.e the sincModify().I am getting the error too less parameters which is because there are no parameters in sincModify in the main().Can anyone help me out by telling what is to be done because i didnt get the whole program


    //////////////code//////


    #include<GL/glut.h>
    #include<math.h>
    #define Q_UNUSED

    static void sincModify(double pt[3],const double bounds[4])
    {
    double r=sqrt(pt[0]*pt[0]+pt[1]*pt[1]);
    const double pi=3.1415;
    pt[2]=-sin(pi*r)/pi*r;
    Q_UNUSED(bounds);
    }
    double* computePointCoordinates(int PointIndex,int xPoint,int yPoint,double xSpace,double ySpace)
    {
    static double pt[3];
    double width=xSpace*(xPoint-1);
    double height=ySpace*(yPoint-1);
    double minX=-width/2;
    double minY=-height/2;
    pt[0]=minX+xSpace*(PointIndex%xPoint);
    pt[1]=minY+ySpace*(PointIndex/yPoint);
    pt[2]=0;
    return pt;
    }
    void computePointCoordinates(int PointIndex,int xPoint,int yPoint,double xSpace,double ySpace,double pt[3])
    {
    double *tmp=computePointCoordinates(PointIndex,xPoint,yPo int,xSpace,ySpace);
    pt[0]=tmp[0];
    pt[1]=tmp[1];
    pt[2]=tmp[2];
    }
    void renderGrid(int xPoint,int yPoint,double xSpace,double ySpace,void* deformFunction(double pt[3],const double bounds[4]))
    {
    double bounds[4];
    int nrQuads=(xPoint-1)*(yPoint-1);
    if(deformFunction)
    {
    double width=xSpace*(xPoint-1);
    double height=ySpace*(yPoint-1);
    bounds[0]=-width/2;
    bounds[1]=-height/2;
    bounds[2]=width;
    bounds[3]=height;
    }
    glBegin(GL_TRIANGLES);
    for(int i=0;i<nrQuads;i++)
    {
    int k=i+i/(xPoint-1);
    int a=k;
    int b=k+1;
    int c=k+1+xPoint;
    int d=k+xPoint;
    double apt[3],bpt[3],cpt[3],dpt[3];
    computePointCoordinates(a,xPoint,yPoint,xSpace,ySp ace,apt);
    computePointCoordinates(b,xPoint,yPoint,xSpace,ySp ace,bpt);
    computePointCoordinates(c,xPoint,yPoint,xSpace,ySp ace,cpt);
    computePointCoordinates(d,xPoint,yPoint,xSpace,ySp ace,dpt);
    if(deformFunction)
    {

    deformFunction(apt,bounds);
    deformFunction(bpt,bounds);
    deformFunction(cpt,bounds);
    deformFunction(dpt,bounds);
    }
    glVertex3dv(apt);
    glVertex3dv(cpt);
    glVertex3dv(dpt);

    glVertex3dv(apt);
    glVertex3dv(bpt);
    glVertex3dv(cpt);

    }
    glEnd();

    }
    void renderScene()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(0.0,0.0,0.0);
    renderGrid(50,50,0.06,0.06,sincModify());
    glutSwapBuffers();
    }
    void myInit()
    {
    glClearColor(1.0,1.0,1.0,1.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2.00,-2.00,-2.00,-2.00,-2.00,-2.00);
    glMatrixMode(GL_MODELVIEW);
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glPointSize(8);

    }
    int main(int argc,char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowPosition(0,0);
    glutInitWindowSize(600,600);
    glutCreateWindow("Grid Tutorial");
    glutDisplayFunc(renderScene);
    myInit();
    glutMainLoop();

    }

  2. #2
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    11
    The grid is not moving, but I managed to compile it. I trie with gcc, then there where way more errors than you declared. However, I consider you use g++ so the error comes from thoses lines :
    static void sincModify(double pt[3],const double bounds[4])
    void renderGrid(int xPoint,int yPoint,double xSpace,double ySpace,void* deformFunction(double pt[3],const double bounds[4]))
    renderGrid(50,50,0.06,0.06,sincModify());

    I think they should look like this :
    void sincModify(double pt[3],const double bounds[4]) //static really usefull ?
    void renderGrid(int xPoint,int yPoint,double xSpace,double ySpace,void deformFunction(double pt[3],const double bounds[4])) //void* give a different signature
    renderGrid(50,50,0.06,0.06,&sincModify); //send pointer to function

    It compile, but as I said the grid is not moving, up to you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •