PDA

View Full Version : Multple Thread using OpenGL



pchopra
12-19-2011, 12:26 AM
Hi friends..
i am new to opengl. i am having problem in using the opengl application in a multi thread programme.
here is sample of my programme:

void * PlotTringle(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread \n");
int argc;
char** argv;
int w=1362;
int h=688;
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (2000, 2000);
glutCreateWindow (argv[0]);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel (GL_FLAT);
glClearColor (0.0, 0.0, 0.0, 0.0);
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
drawLeftTriangle();
drawRightTriangle();
glFlush();
glutMainLoop();
return 0;
}

void * GetData(void *threadid)
{
long tid;
tid = (long)threadid;
printf("GetData \n");
/* code to get data */
}

int main(int argc, char** argv)
{

pthread_t thread1, thread2;
int rc1;
long t1;
printf("In main: creating thread %ld\n", t1);
rc1 = pthread_create(&amp;thread1, NULL, PlotTringle, (void *)t1);
if (rc1){
printf("ERROR; return code from pthread_create() is %d\n", rc1);
return(-1);
}

int rc2;
long t2;
printf("In main: creating thread %ld\n", t2);
rc2 = pthread_create(&amp;thread2, NULL, GetData, (void *)t2);
if (rc2)
{
printf("ERROR; return code from pthread_create() is %d\n", rc2);
return(-1);
}
return 0;
}

V-man
12-19-2011, 05:17 AM
Did you read the Forum Posting Guidelines?