Thread: Glut Camera/stray error: need tutorial/advice

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

    Question Glut Camera/stray error: need tutorial/advice

    Hello, I am new to C++ and Glut (I know some C), and I have made an attempt to add a camera to a basic Glut program. However, when I compile, I get these following errors:

    C:\Users\drewtoby\Desktop\cube\main.cpp|25|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|25|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|31|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|31|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|37|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|37|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|47|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|47|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|57|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|57|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|63|error: stray '\221' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp|63|error: stray '\222' in program|
    C:\Users\drewtoby\Desktop\cube\main.cpp||In function 'void keyboard(unsigned char, int, int)':|
    C:\Users\drewtoby\Desktop\cube\main.cpp|25|error: 'q' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|27|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|31|error: 'z' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|33|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|37|error: 'w' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|40|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|41|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|42|error: 'xpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|42|error: 'sin' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|43|error: 'zpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|43|error: 'cos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|44|error: 'ypos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|47|error: 's' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|50|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|51|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|52|error: 'xpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|52|error: 'sin' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|53|error: 'zpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|53|error: 'cos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|54|error: 'ypos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|57|error: 'd' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|59|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|63|error: 'a' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|65|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp||In function 'int main(int, char**)':|
    C:\Users\drewtoby\Desktop\cube\main.cpp|82|error: 'display' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|84|error: 'variables' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|84|error: expected ';' before 'to'|
    C:\Users\drewtoby\Desktop\cube\main.cpp|85|error: 'reshape' was not declared in this scope|
    ||=== Build finished: 40 errors, 1 warnings ===|

    with this code:

    Code:
    #include <GL/glut.h>
    #include <iostream>
    
    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;
    }

    Could you let me know what I am doing wrong, and/or reccomend a glut camera tutorial? Thanks!!!!!

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

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Look closely at the following code note the single quotation marks. These are not the normal single quote mark ' notice how yours are not straight up and down. You will need to replace all of your single quotes with the proper single quote, both the start and end single quote seem wrong.
    Code:
    if (key==‘d’)
    Jim

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    37
    Okay, I will try that. Thanks!!! Anything else?

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    37
    I Made the adjustments, now only 24 errors

    Errors:

    C:\Users\drewtoby\Desktop\cube\main.cpp||In function 'void keyboard(unsigned char, int, int)':|
    C:\Users\drewtoby\Desktop\cube\main.cpp|30|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|30|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|32|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|36|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|36|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|38|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|42|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|42|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|45|error: invalid operands of types 'const char [5]' and 'int' to binary 'operator/'|
    C:\Users\drewtoby\Desktop\cube\main.cpp|46|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|47|error: 'xpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|48|error: 'zpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|49|error: 'ypos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|52|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|52|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|55|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|56|error: 'xrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|57|error: 'xpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|58|error: 'zpos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|59|error: 'ypos' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|62|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|62|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|64|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|68|warning : comparison with string literal results in unspecified behaviour|
    C:\Users\drewtoby\Desktop\cube\main.cpp|68|error: ISO C++ forbids comparison between pointer and integer|
    C:\Users\drewtoby\Desktop\cube\main.cpp|70|error: 'yrot' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp||In function 'int main(int, char**)':|
    C:\Users\drewtoby\Desktop\cube\main.cpp|87|error: 'display' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|89|error: 'variables' was not declared in this scope|
    C:\Users\drewtoby\Desktop\cube\main.cpp|89|error: expected ';' before 'to'|
    C:\Users\drewtoby\Desktop\cube\main.cpp|90|error: 'reshape' was not declared in this scope|
    ||=== Build finished: 24 errors, 7 warnings ===|

    Code:

    Code:
    #include <GL/glut.h>
    #include <iostream>
    #include <math.h>
    #include <stdlib.h>
    using namespace std;
    
    
    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;
    }

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You seem to have replaced the problem single quotes with double quotes. Double quotes denote a C-string not a character. They need to be single quotes.

    Jim

  7. #7
    Registered User xentaka's Avatar
    Join Date
    May 2011
    Posts
    60
    The single quote is on the same key as the double quote if your using standard keyboard... so " pressing shift and ' without... you want without.

  8. #8
    Registered User
    Join Date
    Apr 2011
    Posts
    37
    Thanks again everyone! Used C when it should have been C++... lol

    Only a handful of errors now, I'll go fix em!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 03-12-2011, 04:25 PM
  2. Stray Error while compiling
    By Mankthetank19 in forum C Programming
    Replies: 6
    Last Post: 02-03-2011, 03:24 PM
  3. What does: 'error: stray ‘o357’ in program' mean?
    By Phanixis in forum Linux Programming
    Replies: 8
    Last Post: 12-04-2010, 01:48 AM
  4. C compiling / error: stray ‘\’ in program
    By Elya in forum C Programming
    Replies: 5
    Last Post: 07-02-2009, 08:20 AM
  5. OpenGL: glut.h error
    By reaperman in forum C++ Programming
    Replies: 2
    Last Post: 10-29-2008, 12:09 PM