I am using glut library with opengl and draw circle with it. Circle is draw successfully on frame but what i want compile these circle vertices in a thread. For example i put in circle loop, Every vertex draw after 2seconds is completed than on run time it appear that vertex on frame which seconds are passed. I am using sleep() function but doesn't work with it.
Code:
#include <iostream>
#include <cstdlib>
#include <GL/glut.h>
#include<windows.h>
#include <cmath>
#define M_PI 3.14159265358979323846
using namespace std;
void init(void) {
glClearColor(0.0f,0.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case '\x1B':
exit(EXIT_SUCCESS);
break;
}
}
void drawCircle(float pointX, float pointY, float Radius, int segment)
{
glBegin(GL_LINE_LOOP);
for (int i = 0; i < segment; i++)
{
float thetha= i * (2.0f * (float)M_PI / segment);
float x = Radius * cos(thetha);
float y = Radius * sin(thetha);
Sleep(2000);
glVertex2f(x + pointX, y + pointY);
}
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
drawCircle(0.0f, 0.0f, 0.80f, 360);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(590, 590);
glutInitWindowPosition(50,50);
glutCreateWindow("Frame");
init();
glutKeyboardFunc(&keyboard);
glutDisplayFunc(&display);
glutMainLoop();
return EXIT_SUCCESS;
}