Link to home
Start Free TrialLog in
Avatar of ExpExchHelp
ExpExchHelpFlag for United States of America

asked on

OpenGL (Timer Function)

I'm working on an OpenGL program that spins a "square".  

Below is the code thus far.   Instead of the "void spinDisplay" function, I now want to use a "timer" function (included below the spinDisplay).    When simply commenting out the spinDisplay, I get a compile error.    

What am I missing?   Do I need to keep portions of the spinDisplay or is my timer_func incorrect (or placed incorrectly within the program)?

Thanks,
EEH
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
 
#define DEGREES_TO_RADIANS 3.14159/180.0
 
static GLfloat spin = 0.0;
GLfloat x, y;
 
void square()
{
 	glBegin(GL_QUADS);
       	glVertex2f(x, y);
       	glVertex2f(-y, x);
       	glVertex2f(-x, -y);
       	glVertex2f(y,-x);
    glEnd();
}
 
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    square();
    glutSwapBuffers ();
}
 
 
void spinDisplay ()          // ORIGINAL FUNCTION
{
    spin = spin + 2.5;
    if (spin > 360.0) spin = spin - 360.0;
    x = 25.0 * cos(DEGREES_TO_RADIANS * spin);
    y = 25.0 * sin(DEGREES_TO_RADIANS * spin);
    glutPostRedisplay();
}
 
 
void timer_func(int n)           // NEW FUNCTION
{
	// Update the object positions, etc.
	glutPostRedisplay();
         //glutTimerFunc(n, timer_func, n); 
	glutTimerFunc(5, timer_func, 5);
}
 
 
void myinit ()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(1.0, 0.0, 1.0);
    glShadeModel(GL_FLAT);
}
 
void mouse(int btn, int state, int x, int y)
{
   	if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    	glutIdleFunc(spinDisplay);
    if (btn == GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
    	glutIdleFunc(NULL);
}
	
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
        50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
    else
    glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
        50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}
 
/*  main loop
 *  open window with initial window size, title bar,
 *  RGBA display mode, and handle input events
 */
int main(int argc, char** argv)
{
 
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    glutIdleFunc (spinDisplay);
    glutMouseFunc (mouse);
 
    glutMainLoop();
}

Open in new window

Avatar of mitsujin
mitsujin
Flag of Australia image

What is the error message u getting?

You can call spinDisplay from within timer_func. (replace line 41 with spinDisplay()).

Enclose timer_func within a void function (e.g. void run())  and pass that to glutIdleFunc instead (line 90).

// in timer_func
void timer_func(int n)           // NEW FUNCTION
{
        // Update the object positions, etc.
        spinDisplay();
 
         //glutTimerFunc(n, timer_func, n); 
        glutTimerFunc(n, timer_func, n);
}
 
void run() {
   timer_func(60);
}
 
// and in main
glutIdleFunc(run);

Open in new window

Avatar of ExpExchHelp

ASKER

mitsujin:

I'll check it out tonight... pls be on standby for additional feedback/questions.

EEH
mitsujin:

so far I didn't get any error message.   It just didn't work.  

I tried to make the changes but now I get a compile error.   Below is the modified code (as is).   Do you have another recommendations as to how the program should be changed (all code please)?

Thank you,
EEH
/*
 *  double.c
 *  This program demonstrates double buffering for
 *  flicker-free animation.  The left and middle mouse
 *  buttons start and stop the spinning motion of the square.
 */
 
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
 
#define DEGREES_TO_RADIANS 3.14159/180.0
 
static GLfloat spin = 0.0;
GLfloat x, y;
 
void square()
{
 	glBegin(GL_QUADS);
       	glVertex2f(x, y);
       	glVertex2f(-y, x);
       	glVertex2f(-x, -y);
       	glVertex2f(y,-x);
    glEnd();
}
 
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    square();
    glutSwapBuffers ();
}
 
 
 
 
 
 
 
// in timer_func
void timer_func(int n)           // NEW FUNCTION
{
        // Update the object positions, etc.
        spinDisplay();
 
         //glutTimerFunc(n, timer_func, n); 
        glutTimerFunc(n, timer_func, n);
}
 
void run() {
   timer_func(60);
}
 
 
 
 
 
 
void spinDisplay ()          // ORIGINAL FUNCTION
{
    spin = spin + 2.5;
    if (spin > 360.0) spin = spin - 360.0;
    x = 25.0 * cos(DEGREES_TO_RADIANS * spin);
    y = 25.0 * sin(DEGREES_TO_RADIANS * spin);
    glutPostRedisplay();
}
 
void myinit ()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(1.0, 0.0, 1.0);
    glShadeModel(GL_FLAT);
}
 
void mouse(int btn, int state, int x, int y)
{
   	if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    	glutIdleFunc(spinDisplay);
    if (btn == GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
    	glutIdleFunc(NULL);
}
	
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
        50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
    else
    glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
        50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}
 
/*  main loop
 *  open window with initial window size, title bar,
 *  RGBA display mode, and handle input events
 */
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    glutIdleFunc (spinDisplay);
    glutMouseFunc (mouse);
 
    glutMainLoop();
 
	glutIdleFunc(run);                // New code
 
}

Open in new window

The problem is that you are implementing spinDisplay after run. If you are going to call a function make sure its implemented before the function you are adding it in.
You can also solve fix it by just declaring the function as follows:

void spinDisplay();

I've compiled your code with these changes, and it works. I did ran into some slight issues with setting up glut libraries though.

Also you

if you want to improve the timing function or learn more about opengl, I recommend
http://nehe.gamedev.net/



#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
 
#define DEGREES_TO_RADIANS 3.14159/180.0
 
void spinDisplay();
 
static GLfloat spin = 0.0;
GLfloat x, y;
 
void square()
{
        glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(-y, x);
        glVertex2f(-x, -y);
        glVertex2f(y,-x);
    glEnd();
}
 
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    square();
    glutSwapBuffers ();
}
 
 
 
 
 
 
 
// in timer_func
void timer_func(int n)           // NEW FUNCTION
{
        // Update the object positions, etc.
        spinDisplay();
 
         //glutTimerFunc(n, timer_func, n);
        glutTimerFunc(n, timer_func, n);
}
 
void run() {
   timer_func(60);
}
 
 
 
 
 
 
void spinDisplay ()          // ORIGINAL FUNCTION
{
    spin = spin + 2.5;
    if (spin > 360.0) spin = spin - 360.0;
    x = 25.0 * cos(DEGREES_TO_RADIANS * spin);
    y = 25.0 * sin(DEGREES_TO_RADIANS * spin);
    glutPostRedisplay();
}
 
void myinit ()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(1.0, 0.0, 1.0);
    glShadeModel(GL_FLAT);
}
 
void mouse(int btn, int state, int x, int y)
{
        if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
        glutIdleFunc(spinDisplay);
    if (btn == GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
        glutIdleFunc(NULL);
}
 
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
        50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
    else
    glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
        50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}
 
/*  main loop
 *  open window with initial window size, title bar,
 *  RGBA display mode, and handle input events
 */
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    glutIdleFunc (run);
    glutMouseFunc (mouse);
 
    glutMainLoop();
 
        glutIdleFunc(run);                // New code
 
}

Open in new window

Wow, I'm getting 143 compile errors:

I use Visual C++ Express Edition.   No luck so far.

EEH
1>------ Build started: Project: HW_4_spin, Configuration: Debug Win32 ------
1>Compiling...
1>HW_4_spin.cpp
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : error C2146: syntax error : missing ';' before identifier 'glAccum'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C2146: syntax error : missing ';' before identifier 'glAlphaFunc'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1153) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C2146: syntax error : missing ';' before identifier 'GLboolean'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C2146: syntax error : missing ';' before identifier 'glAreTexturesResident'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C2371: 'APIENTRY' : redefinition; different basic types
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1154) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C2146: syntax error : missing ';' before identifier 'glArrayElement'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1155) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C2146: syntax error : missing ';' before identifier 'glBegin'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1156) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C2146: syntax error : missing ';' before identifier 'glBindTexture'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1157) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C2146: syntax error : missing ';' before identifier 'glBitmap'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1158) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C2146: syntax error : missing ';' before identifier 'glBlendFunc'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1159) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C2146: syntax error : missing ';' before identifier 'glCallList'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1160) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C2146: syntax error : missing ';' before identifier 'glCallLists'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1161) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C2146: syntax error : missing ';' before identifier 'glClear'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1162) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C2146: syntax error : missing ';' before identifier 'glClearAccum'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1163) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C2146: syntax error : missing ';' before identifier 'glClearColor'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1164) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C2146: syntax error : missing ';' before identifier 'glClearDepth'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1165) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C2146: syntax error : missing ';' before identifier 'glClearIndex'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1166) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C2146: syntax error : missing ';' before identifier 'glClearStencil'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1167) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C2146: syntax error : missing ';' before identifier 'glClipPlane'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1168) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C2146: syntax error : missing ';' before identifier 'glColor3b'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1169) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C2146: syntax error : missing ';' before identifier 'glColor3bv'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1170) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C2146: syntax error : missing ';' before identifier 'glColor3d'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C2086: 'int APIENTRY' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'APIENTRY'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1171) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : error C2086: 'int WINGDIAPI' : redefinition
1>        c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1152) : see declaration of 'WINGDIAPI'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : error C2146: syntax error : missing ';' before identifier 'glColor3dv'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : error C2182: 'APIENTRY' : illegal use of type 'void'
1>c:\program files\microsoft platform sdk for windows server 2003 r2\include\gl\gl.h(1172) : fatal error C1003: error count exceeds 100; stopping compilation
1>Build log was saved at "file://c:\Documents and Settings\Tom\My Documents\Master of Engineering -- VMASC\48 -- MSIM 641\06 Homework\Homework 4\HW_4_spin\Debug\BuildLog.htm"
1>HW_4_spin - 143 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Open in new window

ok, that means you do not have the libraries added to your linker settings.

just add these extra lines at the beginning of your program.

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")

you also need to go and download the glut libraries. Here is the link

http://www.cs.stevens.edu/~kamberov/teach/F2004/437/newGLNotes.html

its got some good instructions as to how to add it to your project.

your code should now look like the attached.


#pragma comment(lib, "opengl32.lib") 
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
 
 
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
 
#define DEGREES_TO_RADIANS 3.14159/180.0
 
void spinDisplay();
 
static GLfloat spin = 0.0;
GLfloat x, y;
 
void square()
{
        glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(-y, x);
        glVertex2f(-x, -y);
        glVertex2f(y,-x);
    glEnd();
}
 
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    square();
    glutSwapBuffers ();
}
 
 
 
 
 
 
 
// in timer_func
void timer_func(int n)           // NEW FUNCTION
{
        // Update the object positions, etc.
        spinDisplay();
 
         //glutTimerFunc(n, timer_func, n);
        glutTimerFunc(n, timer_func, n);
}
 
void run() {
   timer_func(60);
}
 
 
 
 
 
 
void spinDisplay ()          // ORIGINAL FUNCTION
{
    spin = spin + 2.5;
    if (spin > 360.0) spin = spin - 360.0;
    x = 25.0 * cos(DEGREES_TO_RADIANS * spin);
    y = 25.0 * sin(DEGREES_TO_RADIANS * spin);
    glutPostRedisplay();
}
 
void myinit ()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(1.0, 0.0, 1.0);
    glShadeModel(GL_FLAT);
}
 
void mouse(int btn, int state, int x, int y)
{
        if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
        glutIdleFunc(spinDisplay);
    if (btn == GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
        glutIdleFunc(NULL);
}
 
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
        50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
    else
    glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
        50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}
 
/*  main loop
 *  open window with initial window size, title bar,
 *  RGBA display mode, and handle input events
 */
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    glutIdleFunc (run);
    glutMouseFunc (mouse);
 
    glutMainLoop();
 
    glutIdleFunc(run);                // New code
 
}

Open in new window

ok, if you have all the libraries, just remove

#include
#include

and it will compile.
I need to use the libraries:
#include <GL/gl.h>
#include <GL/glu.h>

It appears that we're working w/ different IDEs, right?

Any more suggestions as to how it can be fixed w/o totally changing my existing code?

EEH
if you look at the error output, it is actually finding these files (gl.h and glu.h). The problem is that visual c++ is complaining that windows.h hasn't been included yet.

Now since you are using the glut library, it does all the necessary includes for you. So you only need to do #include .

I've tried this with a different IDE (code::blocks) and it compiles properly. However in visual c++ it gives me the same compile errors you sent before. Hence to fix it i just used #include


Have you installed the glut libraries? place the glut.h file in the same location as where the other opengl header files are.

Also place the glut32.dll file in c:\windows\system32

and place glut32.lib in the visual c++ lib directory.






Yes, I've installed all libraries properly.   I know this as other programs worked just fine.

Going back to the original message, is there a simple syntax error or a missing line that needs to be inserted in order to get timer function working properly?

EEH
The code attached works in visual c++.

 From the original message, the change i did was to simply declare spinDIsplay above timerFunc. The syntax error you were getting was that you couldn't use spinDIsplay inside timerFunc because it was implemented below this function.

To fix this, you either implement the function above timerFunc or

add void spinDisplay(); in your original working code. Just place it after

#define DEGREES_TO_RADIANS 3.14159/180.0

You can then call spinDIsplay in the timer function as the code attached shows.

Alternatively you can put all your functions in a header file and include it in this file.  

#pragma comment(lib, "opengl32.lib") 
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
 
 
#include <stdlib.h>
#include <math.h>
 
#include <GL/glut.h>
 
#define DEGREES_TO_RADIANS 3.14159/180.0
 
void spinDisplay();
 
static GLfloat spin = 0.0;
GLfloat x, y;
 
void square()
{
        glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(-y, x);
        glVertex2f(-x, -y);
        glVertex2f(y,-x);
    glEnd();
}
 
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    square();
    glutSwapBuffers ();
}
 
 
 
 
 
 
 
// in timer_func
void timer_func(int n)           // NEW FUNCTION
{
        // Update the object positions, etc.
        spinDisplay();
 
         //glutTimerFunc(n, timer_func, n);
        glutTimerFunc(n, timer_func, n);
}
 
void run() {
   timer_func(60);
}
 
 
 
 
 
 
void spinDisplay ()          // ORIGINAL FUNCTION
{
    spin = spin + 2.5;
    if (spin > 360.0) spin = spin - 360.0;
    x = 25.0 * cos(DEGREES_TO_RADIANS * spin);
    y = 25.0 * sin(DEGREES_TO_RADIANS * spin);
    glutPostRedisplay();
}
 
void myinit ()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glColor3f(1.0, 0.0, 1.0);
    glShadeModel(GL_FLAT);
}
 
void mouse(int btn, int state, int x, int y)
{
        if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
        glutIdleFunc(spinDisplay);
    if (btn == GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
        glutIdleFunc(NULL);
}
 
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
        50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
    else
    glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
        50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
}
 
/*  main loop
 *  open window with initial window size, title bar,
 *  RGBA display mode, and handle input events
 */
int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    glutIdleFunc (run);
    glutMouseFunc (mouse);
 
    glutMainLoop();
 
    glutIdleFunc(run);                // New code
 
}

Open in new window

Ok... the code builds fine now.

Final question:  How can I slow down the "spinning"?

EEH
Instead of

glutIdleFunc (run);

just call timer_func;

The problem with using glutIdleFunc is that it keeps calling timer_func so the square will spin faster and faster. Just call timer_func on its own with the desired time in milliseconds.



int main(int argc, char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("double buffered");
    myinit ();
    glutDisplayFunc(display);
    glutReshapeFunc (myReshape);
    //glutIdleFunc (run);
    timer_func(60);      // new code
    glutMouseFunc (mouse);
 
    glutMainLoop();
 
    glutIdleFunc(run);                
 
}

Open in new window

I'm still a beginner in programming in C.

Based on the existing code, how do I call it on its own?

EEH
Before I was calling it using glutIdleFunc. We had glutIdleFunc(run);

and the run function was calling the timer_func. Now we just want to call timer_func only. so...

To call it on its own - Instead of glutIdleFunc(run); Or glutIdleFunc (spinDisplay);

do this

timer_func(60);

This will stop your square from spinning too fast. You can also delete the run function as its not needed now.  

Follow the code for main in the last post as a guide also.

Ok, this thread is growing very long.   Thank you for being so patient w/ me.

Ok, I need to go through all the messages again.   My goal though is to make sure the square rotates 10 degress per second.

Based on the original code, you pls help me revise the code (full c/cpp file) into a final message... incl all the changes you recommended.    I'm kinda lost as to what pieces are new, have been removed, etc.

Again, my goal is to make the square rotate 10 degress every second.

Thanks,
EEH
ASKER CERTIFIED SOLUTION
Avatar of mitsujin
mitsujin
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PERFECT!!!

That works great.   Thousand thanks for your continuous help on this (long) thread.   'Truly appreciate it!

EEH
No worries, glad to help.