//plotter.cpp, 5/25/1998 //modified from //graph.cpp //Oguz Yetkin, 5/20/1998 // //opengl graphics kludge for physics neural network project #ifdef WIN #include #include #include #include #include "plotter.h" static Plotter* pl; void Launch(void* Me){ int dummyargc=1; char** dummyargv=new char*[1]; dummyargv[0]=new char[20]; strcpy(dummyargv[0], "application"); printf("\nMe: %x pl: %x",Me, pl); assert(Me==pl); ((Plotter*)Me)->MyMain(dummyargc, dummyargv); ///will invoke glutMainLoop() which never returns //********!!!! all subsequent communication //********!!!! with outside work happens via display_mutex //********!!!! controlled variables //point of no return } void Display(){ int count; static int firstrun=1; if(firstrun){ glClear(GL_COLOR_BUFFER_BIT); /*clear the window*/ firstrun=0; } //acquire the mutex //cout<<"\ndisplay waiting for run mutex!"<run_mutex, INFINITE); //cout<<"\ndisplay acquired run mutex!"<display_mutex, INFINITE); //WaitForSingleObject(pl->display_mutex, INFINITE); //cout<<"\ndisplay now has display mutex!"<displayed){ //long random(); /*standard random number gen */ /* point2 p={75.0,50.0}; */ /* random point */ //we only want to do this once! It's commented out! //glClear(GL_COLOR_BUFFER_BIT); /*clear the window*/ // plot point if(!pl->displayed){ glBegin(GL_POINTS); //glBegin(GL_POLYGON); glVertex2f(pl->x_location, pl->y_location); glEnd(); pl->displayed=1; printf("\ndisplayed: %f %f",pl->x_location, pl->y_location); glFlush(); //glutPostRedisplay(); } ReleaseMutex(pl->run_mutex); ReleaseMutex(pl->display_mutex); Sleep(0);//give up thread time! }//end while } //encapsulate former main into Plotter class, //add public variables //int displayed, //float x_location, y_location, //HANDLE display_mutex // void myinit(void); //void display(void); Plotter::Plotter(int _maxx, int _maxy){ maxx=_maxx; maxy=_maxy; maxz=500; //for now displayed=1; //initially we have nothing to display //clear mutex //display_mutex=CreateMutex(NULL, FALSE, NULL); //clear //displayed_mutex=CreateMutex(NULL, TRUE, NULL); //set display_mutex=CreateMutex(NULL, FALSE, NULL); //cleared run_mutex=CreateMutex(NULL, TRUE, NULL); //set ::pl=this; //this is the kludgiest thing I've ever done, I hope it works thread_num=_beginthread(Launch, 0, (void*)this); //cout<<"\n***THREAD LAUNCHED"<