hello I am new to opengl/glut and I think I am still using version 1.1 with visual studio 2013 C++
the problem I am having is that I cannot make the arm rotate back and forth with IdleFunc, I have tried glutTimerFunc but that is not really practice for what I intend to do.
In the reverse () function I need an alternative to the “else” statement
#include "stdafx.h"
#include "GL\glut.h"
#include <iostream>
GLdouble angle_1 = 0, angle_2 = 0;
static GLdouble sentinel = 0;
void reverse()
{
if (angle_1 < 26 )// ||angle_2>-25)
{
angle_1 +=.01;
angle_2-=.01;
}
else
{
angle_1 = .0;
angle_2 = .0;
}
glutPostRedisplay();
}
void keyFunc(unsigned char key, int i, int u)
{
switch (key)
{
case'l':
glutIdleFunc(reverse);
sentinel = 1;
break;
case'r':
glutIdleFunc(NULL);
break;
}
}
void legs()
{
glPushMatrix();
glScaled(3, 2, 1);
glutWireCube(1);
//////////////////////////////////////////first joint
glPushMatrix();
glRotated(angle_1, 1, 0, 0);
//glTranslated(0, 0, angle_1);
glTranslated(1, 0, 0);
glScaled(.5, 2, 1);
glutWireCube(1);
////////////////leg
glPushMatrix();
glTranslated(0, -1, 0);
glScaled(.5, 2, 1);
glutWireCube(1);
glPopMatrix();
glPopMatrix();
//////////////////////////////////////////first joint
glPushMatrix();
glRotated(angle_2, 1, 0, 0);
glTranslated(-1, 0, 0);
glScaled(.5, 2, 1);
glutWireCube(1);
////////////////leg
glPushMatrix();
glTranslated(0, -1, 0);
glScaled(.5, 2, 1);
glutWireCube(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
void general()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 0.5, 0, 0);
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65, w / h, 1, 150);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(10, 10, 20, 0, 0, 0, 0, 1, 0);
}
void display()
{
general();
glPushMatrix();
glRotated(95, 0, 1, 0);
legs();
glPopMatrix();
glutSwapBuffers();
}
int _tmain(int argc, _TCHAR* argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutCreateWindow("wind");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyFunc);
//glutMouseFunc(mouse_Click);
glutMainLoop();
return 0;
}
if anyone could give me an idea on how to correct the code it will be really appreciated here is the copy of the code