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

Thread: smooth rotating cube

  1. #1
    Newbie Newbie
    Join Date
    Apr 2017
    Posts
    6

    smooth rotating cube

    My system:
    linux debian7 32bit

    Using OpenGL tutorial and reference manual,
    Example rotating cube ex6.1 works ok.
    However I'm stuck at ex6.3 smooth the cube.
    It's trying to double buffer and smooth the cube.
    I get the following errors after compile.
    Thanks for helping:

    Code :
    terminal compile:
    gcc ex6a.c -lGL -lGLU -lglut -o ex6a
     
    ex6a.c: In function ‘display’:
    ex6a.c:26:5: error: stray ‘\342’ in program
    ex6a.c:26:5: error: stray ‘\200’ in program
    ex6a.c:26:5: error: stray ‘\216’ in program

    Code cpp:
    #include <GL/glut.h>
     
    GLfloat angle= 0.0;
     
    void spin (void)
    {
        angle+= 1.0;
        glutPostRedisplay();
    }
     
    void display(void)
    {
        glClear (GL_COLOR_BUFFER_BIT);
        glLoadIdentity ();
        gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
        glRotatef(angle, 1, 0, 0);
        glRotatef(angle, 0, 1, 0);
        glRotatef(angle, 0, 0, 1);
        glutWireCube(2.0);
        &#8206;glutSwapBuffers(void);  // added line pg35
        // glFlush(); remove line
    }
     
    void reshape (int w, int h)
    {
        glViewport (0, 0, (GLsizei)w, (GLsizei)h);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluPerspective (60, (GLfloat) w / (GLfloat) h, 1.0, 100.0);
        glMatrixMode (GL_MODELVIEW);
    }
     
    int main(int argc, char **argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE); // added line pg35
        glutInitWindowSize (500, 500);
        glutInitWindowPosition (100, 100);
        glutCreateWindow ("ex6a: smooth cube");
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutIdleFunc(spin);
        glutMainLoop();
        return 0;
    }
    Last edited by Dark Photon; 04-30-2017 at 02:51 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,227
    If you look at the code you copy/pasted above, it appears that there may be some high-bit characters just before glutSwapBuffers(void).

    You could delete that line and the previous line and retype them. But better yet, prove this to yourself by dumping the character codes in the file with one of: "od -xc ex6a.c" or "hexdump ex6a.c". Then use a text editor which will show you the high-bit characters and let you delete them (emacs, vi, etc.)

  3. #3
    Newbie Newbie
    Join Date
    Apr 2017
    Posts
    6
    After manually entering 2 lines of code,
    I get a new set of compiler errors.

    I only have gedit. I tried to make vi work, but after many days and dozens of web sites I failed.

    Code :
    gcc ex6a.c -lGL -lGLU -lglut -o ex6a
    ex6a.c: In function ‘display’:
    ex6a.c:26:21: error: expected expression before ‘void’
    ex6a.c:26:21: error: too many arguments to function ‘glutSwapBuffers’
    In file included from /usr/include/GL/glut.h:17:0,
                     from ex6a.c:7:
    /usr/include/GL/freeglut_std.h:424:26: note: declared here

    Code :
    #include <GL/glut.h>
     
    GLfloat angle= 0.0;
     
    void spin (void)
    {
        angle+= 1.0;
        glutPostRedisplay();
    }
     
    void display(void)
    {
        glClear (GL_COLOR_BUFFER_BIT);
        glLoadIdentity ();
        gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
        glRotatef(angle, 1, 0, 0);
        glRotatef(angle, 0, 1, 0);
        glRotatef(angle, 0, 0, 1);
        glutWireCube(2.0);         // manually typed
        glutSwapBuffers(void);     // manually typed
        // glFlush(); remove line
    }
     
    void reshape (int w, int h)
    {
        glViewport (0, 0, (GLsizei)w, (GLsizei)h);
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluPerspective (60, (GLfloat) w / (GLfloat) h, 1.0, 100.0);
        glMatrixMode (GL_MODELVIEW);
    }
     
    int main(int argc, char **argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE); // added line pg35
        glutInitWindowSize (500, 500);
        glutInitWindowPosition (100, 100);
        glutCreateWindow ("ex6a: smooth cube");
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutIdleFunc(spin);
        glutMainLoop();
        return 0;
    }

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,594
    Quote Originally Posted by tvus_ogl View Post
    Code :
        glutSwapBuffers(void);     // manually typed
    You need to learn to program in C before you try to write programs in C.

    You can't expect to be able to just copy-paste code without actually learning the language.

  5. #5
    Newbie Newbie
    Join Date
    Apr 2017
    Posts
    6
    GClements a.k.a. Captain Obvious
    -no links suggesting .pdf help, learning C
    -code from an OpenGL Tutorial pdf, suggesting copy/paste
    -shows no experience to be proud of
    -not enough experience to help OpenGL

    Dark Photon (Senior Member) Is an asset to OpenGL forums.
    He displays actual knowledge of C in troubleShooting.
    I was actually learning insight about this problem.
    This exact problem has many webSites talking about it, without a fix.
    I thought I would get closer to the source for an answer.

    My experience is from, the late 70's with assembly and fortran.
    It was taught using CodeRun (bought out by Ms or Sun I forget)
    CodeRuns addage was: Programming is not rocket science,
    It's for everyone.
    With CodeRun I rose quickly in the industrial field, now retired.

    Today I have a need to learn C. C drives everything.
    Internet/Google not much of value is out there.
    I did find some spec docs, I value greatly.
    GClements is typical of the garbage, in front of ppl wanting C.
    Only wanting to increase posting # instead of helping. So sad.

    If OpenGL forums is not interested in OpenGL Tutorial pdf problems,
    Then either am I. In time I will learn to fix this.
    And I'm on the learning path now. Thank You.

    All Hale, Dark Photon HALE!!! HALE!!! HALE!!!

  6. #6
    Newbie Newbie
    Join Date
    Apr 2017
    Posts
    6
    after your help with glutSwapBuffers
    I then had additional problems with glutInitDisplayMode
    Using correct C glut procedures, it was easily fixed.
    The code works fine now.
    thanks your help is appreciated.

Posting Permissions

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