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:


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


#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);
    ‎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;
}

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.)

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.


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


#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;
}

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.

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!!!

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.