Hello.
i just downloaded the pThread library and i just wanted to try out some graphics.
So, i typed this down:
#include <posix/pthread.h>
#include <posix/sched.h>
#include <windows.h>
#include <stdio.h>
#include <gl/glut.h>
void Display(void);
void mouse(int b, int s, int x, int y);
pthread_t ntid, ntid1;
// for the command line arguments
char **args;
int count;
void* fn_1(void *arg)
{
printf("fun1
");
/* Initialisations */
glutInit(&count, args);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutCreateWindow("Sample");
glutDisplayFunc(Display);
glutMouseFunc(mouse);
glutMainLoop();
return ((void *)0);
}
void Display(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1, 1, -1, 1, -1, 1);
}
void mouse(int b, int s, int x, int y)
{
// just plot a point
glColor3f(0.0, 0.0, 0.0);
if (b == GLUT_LEFT_BUTTON && s == GLUT_DOWN) {
glBegin(GL_POINTS);
glVertex2i(1, 1);
glEnd();
glFlush();
}
}
void* fn_2(void *arg)
{
int x = 10;
Sleep(2000); // make thread 1 execute first(hence delay)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/* draw the cube here */
while (1) {
// this is for clearing
glColor3f(1.0, 1.0, 1.0);
glutSolidCube(1);
glRotatef(x += 10, 1, 1, 1);
glColor3f(0.0, 0.0, 0.0);
glutSolidCube(1);
glColor3f(1.0, 1.0, 1.0);
glutWireCube(1);
glFlush();
Sleep(100);
}
}
int main(int argc, char **argv)
{
count = argc;
args = argv;
/* Create the 2 threads */
int err1 = pthread_create(&ntid, NULL, fn_1, NULL);
int err2 = pthread_create(&ntid1, NULL, fn_2, NULL);
/*-wait for threads to exit-*/
void *val, *val1;
pthread_join(ntid, &val);
pthread_join(ntid1, &val1);
/*---------------------------*/
return 0;
}
But im just getting a blank window.
Can anyone please tell me where im going wrong?
Thanks.