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 4 of 4

Thread: Can't compile example from text book. 3 errors.

  1. #1
    Newbie Newbie
    Join Date
    Mar 2013
    Posts
    3

    Can't compile example from text book. 3 errors.

    Hi,
    my code below is similar to an example on a previous page in the text book which compiles.
    For 1 error reason, this text book example has a lot of mistakes that won't compile and I need some help to fix it.
    1 error:
    main.cpp: In function ‘void polyline(GLint, GLint, GLint, GLint)’:
    main.cpp:50:9: error: ‘ptCtr’ was not declared in this scope


    Code:
    Code cpp:
    #include <GL/glut.h>
     
    GLsizei winWidth = 400, winHeight = 300;        // Initial display-window size.
    GLint endPtCtr = 0;                             // Initialise line endpoint counter.
     
    class scrPt
    {
    public:
        GLint x, y;
    };
     
    void init (void)
    {
        glClearColor (0.0, 0.0, 1.0, 1.0)           // Set display-window colour to blue.
     
        glMatrixMode (GL_PROJECTION);
        gluOrtho2D (0.0, 200.0, 0.0, 150.0);
    }
     
    void displayFcn (void)
    {
        glClear (GL_COLOR_BUFFER_BIT);
    }
     
    void winReshapeFcn (GLint newWidth, GLint newHeight)
    {
        /* Reset viewport and projection parameters. */
        glViewport (0, 0, newWidth, newHeight);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ( );
        gluOrtho2D (0.0, GLdouble (newWidth), 0.0, GLdouble (newHeight));
     
        /* Reset display-window size parameters. */
        winWidth = newWidth;
        winHeight = newHeight;
    }
     
    void drawLineSegment (scrPt endPt1, scrPt endPt2)
    {
        glBegin (GL_LINES);
            glVertex2i (endPt1.x, endPt1.y);
            glVertex2i (endPt2.x, endPt2.y);
        glEnd( );
    }
     
    void polyline (GLint button, GLint action, GLint xMouse, GLint yMouse)
    {
        static scrPt endPt1, endPt2;
     
        if (ptCtr == 0)
        {
            if (button == GLUT_LEFT_BUTTON && action == GLUT_DOWN)
            {
                endPt1.x = xMouse;
                endPt1.y = winHeight - yMouse;
                ptCtr = 1;
            }
            else
                if (button == GLUT_RIGHT_BUTTON)    // Quit the program.
                    exit (0);
        }
        else
            if (button == GLUT_LEFT_BUTTON && action == GLUT_DOWN)
            {
                endPt2.x = xMouse;
                endPt2.y = winHeight - yMouse;
                drawLineSegment (endPt1, endPt2);
     
                endPt1 = endPt2;
            }
            else
                if (button = GLUT_RIGHT_BUTTON)     // Quit the program.
                    exit (0);
     
        glFlush ( );
    }
     
    void main (int argc, char** argv)
    {
        glutInit (&argc, argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
        glutInitWindowPosition (100, 100);
        glutInitWindowSize (winWidth, winHeight);
        glutCreateWindow ("Draw Interactive Polyline");
     
        init ( );
        glutDisplayFunc (displayFcn);
        glutReshapeFunc (winReshapeFcn);
        glutMouseFunc (polyline);
     
        glutMainLoop ( );
    }
    Last edited by Dark Photon; Yesterday at 07:49 AM.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    590
    A quick look it seems ptCtr should be endPtCtr - but the compiler is correct it is not defined.

    Please enclose code is side "square-bracket code square-bracket" "square-bracket /code square-bracket" when posting

    EDIT: I would be very doubtful about using a book with that many errors
    Last edited by tonyo_au; Yesterday at 01:53 AM.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,847
    Quote Originally Posted by tonyo_au View Post
    Please enclose code is side "square-bracket code square-bracket" "square-bracket /code square-bracket" when posting
    The [noparse] tag is very useful for telling folks about VBulletin markup - discovered that a few months ago. For instance:

    Please enclose code inside [code]...[/code] blocks when posting (or use [highlight=cpp]...[/highlight] or [highlight=glsl]...[/highlight] if you want colorization as well).
    Last edited by Dark Photon; Yesterday at 07:53 AM.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    590
    Thanks for that

Posting Permissions

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