Glut two errors upon being compiled: "not declared terms"

This is a discussion on Glut two errors upon being compiled: "not declared terms" within the C++ Programming forums, part of the General Programming Boards category; Okay, I have two errors which I cannot figure out (they should be easy, I am knew to C++). They ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    37

    Smile Glut two errors upon being compiled: "not declared terms"

    Okay, I have two errors which I cannot figure out (they should be easy, I am knew to C++). They are:

    C:\Users\drewtoby\Desktop\tby\main.cpp|88|error: 'display' was not declared in this scope|

    AND

    C:\Users\drewtoby\Desktop\tby\main.cpp|91|error: 'Reshape' was not declared in this scope|

    for this code:

    Code:
    #include <GL/glut.h>
    #include <iostream>
    #include <math.h>
    #include <stdlib.h>
    using namespace std;
    
    float xpos = 0, ypos = 0, zpos = 0, xrot = 2, yrot = 2, angle=2.0;
    
    void enable (void) {
        glEnable (GL_DEPTH_TEST); //enable the depth testing
        glEnable (GL_LIGHTING); //enable the lighting
        glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
        glShadeModel (GL_SMOOTH); //set the shader to smooth shader
        }
    
    
    void renderScene(void) {
       glClear(GL_COLOR_BUFFER_BIT);
       glBegin(GL_TRIANGLES);
       glColor3f(1,0,0);//Change the object color to red
          glVertex3f(-2.0,-0.1,0.0);
          glVertex3f(0.4,0.0,0.0);
          glVertex3f(0.0,0.0,0.0);
       glEnd();
       glFlush();
    }
    
    
    void keyboard (unsigned char key, int x, int y) {
    
        if (key=='q')
        {
        xrot += 1;
        if (xrot >360) xrot -= 360;
        }
    
        if (key=='z')
        {
        xrot -= 1;
        if (xrot < -360) xrot += 360;
        }
    
        if (key=='w')
        {
        float xrotrad, yrotrad;
        yrotrad = (yrot / 180 * 3.141592654f);
        xrotrad = (xrot / 180 * 3.141592654f);
        xpos += float(sin(yrotrad)) ;
        zpos -= float(cos(yrotrad)) ;
        ypos -= float(sin(xrotrad)) ;
        }
    
        if (key=='s')
        {
        float xrotrad, yrotrad;
        yrotrad = (yrot / 180 * 3.141592654f);
        xrotrad = (xrot / 180 * 3.141592654f);
        xpos -= float(sin(yrotrad));
        zpos += float(cos(yrotrad)) ;
        ypos += float(sin(xrotrad));
        }
    
        if (key=='d')
        {
        yrot += 1;
        if (yrot >360) yrot -= 360;
        }
    
        if (key=='a')
        {
        yrot -= 1;
        if (yrot < -360)yrot += 360;
        }
        if (key==27)
        {
        exit(0);
        }
    }
    
    
    int main(int argc, char **argv) {
       glutInit(&argc, argv);
       glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
       glutInitWindowPosition(100,100);
       glutInitWindowSize(800,800);
       glutCreateWindow("MynDrawn: An Open Source Alternative to Minecraft");
       glutDisplayFunc(renderScene);
    glutIdleFunc (display); //update any variables in display,
    //display can be changed to anyhing, as long as you move the
    //variables to be updated, in this case, angle++;
    glutReshapeFunc (Reshape); //reshape the window accordingly
    glutKeyboardFunc (keyboard); //check the keyboard
    glutMainLoop (); //call the main loop
    return 0;
    }
    Do I need to include another Glut file, or is it something else? Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You need something called "display".

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Specifically, you need to create two functions of your own called display() and Reshape(). That's what you're telling glut with these lines:
    Code:
    glutIdleFunc (display); //update any variables in display,
    glutReshapeFunc (Reshape); //reshape the window accordingly
    You're saying, "glut, I want you to call these two functions of mine when certain events happen." In this case you want display() to be called whenever the program is idle, so that it spends its time redrawing the screen when nothing else is happening; and you want Reshape() to be called when the user resizes the window.

    Note that you can just comment out these lines and when e.g. glut sees the window being resized it won't do anything at all. If you don't use glutIdleFunc the code will probably work reasonably well too, since you register a glutDisplayFunc. The difference between display and idle functions is that glut calls the display func only when it knows the screen needs to be repainted. This will happen if you drag another window on top of your program's window, or minimize and then re-open the window. Whereas the idle func is called repeatedly, over and over again, which makes it more suitable for animation.

    If you want an idle function too -- well, googling for "glutIdelFunc" I found that display() should have the signature
    Code:
    void display(void) {
        // ... put your code here
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    37
    Okay, thanks!!!! I'll find/build/mod those files!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "variable or field declared void"
    By Treborh in forum C++ Programming
    Replies: 13
    Last Post: 02-06-2010, 02:33 PM
  2. Replies: 17
    Last Post: 12-15-2006, 10:02 AM
  3. Replies: 3
    Last Post: 08-31-2005, 12:41 PM
  4. Replies: 1
    Last Post: 06-21-2005, 08:10 AM
  5. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21