-#include "jttoolkit.h"\r#include <stdio.h>\r#include <stdlib.h>\r#include <string.h>\r#include <iostream.h> \r#include <fstream.h>\r\r\r#define INIT_WINDOW_X 0\r#define INIT_WINDOW_Y 0\r#define INIT_WINDOW_WIDTH 1024\r#define INIT_WINDOW_HEIGHT 768\r\r\r//#include "gl2ps.h"\r#if defined (__DARWIN__)\r#include <ApplicationServices/ApplicationServices.h>\r#endif\r\r#define use_perspective\r#define VERBOSE 0\r//turn this on and off for speed\r\r\r//---- user-global access functions\r\rint ticks(){return _ticks;}\rint width(){return _width;}\rint height(){return _height;}\r\rint mouseX(){return _mouseX;}\rint mouseY(){return _mouseY;}\r\r\rvoid setMouseX(long xx){_mouseX = xx;}\rvoid setMouseY(long yy){_mouseY = yy;}\r\rvoid ignoreMouse(int state){_ignoreMouse = state;}\r\r//--------------\r\rvoid *threadFunc(void*stuff){\r}\r\r//------------------------------------------------------------------------\rvoid initfmod(){\r /* \r if (FSOUND_GetVersion() < FMOD_VERSION){\r printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION);\r exit(1);\r }\r \r if(!FSOUND_Init(48000, 1024, FSOUND_INIT_GLOBALFOCUS)){\r printf("%s\n",FMOD_ErrorString(FSOUND_GetError()));\r }\r */\r}\r//------------------------------------------------------------------------\r\r\r\rfloat friction(){return _friction;}\rvoid setFriction(float f){_friction = f;}\r\rfloat frequencyRange(){return _frequencyRange;}\rvoid setFrequencyRange(float f){_frequencyRange = f;}\r\rvoid drawUnitSquare(){\r glBegin(GL_QUADS);\r glTexCoord2f(0,0);glVertex2f(0,0); \r glTexCoord2f(1,0);glVertex2f(1,0);\r glTexCoord2f(1,1);glVertex2f(1,1);\r glTexCoord2f(0,1);glVertex2f(0,1);\r glEnd();\r}\r\r\rvoid drawUnitSquareSlightlySmaller(){\r glBegin(GL_QUADS);\r glTexCoord2f(0.01,0.01);glVertex2f(0,0); \r glTexCoord2f(0.99,0.01);glVertex2f(1,0);\r glTexCoord2f(0.99,0.99);glVertex2f(1,1);\r glTexCoord2f(0.01,0.99);glVertex2f(0,1);\r glEnd();\r}\r\r\r\r\rvoid toggleFullScreen(){\r fullscreenmode=!fullscreenmode;\r if(fullscreenmode){\r glutFullScreen();\r } else {\r glutReshapeWindow(INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT);\r glutPositionWindow(0,10);\r }\r}\r\rchar* trimLeft(char*buff){\r //count how many to offset backward\r int whiteCount = 0;\r for(int i=0;i<strlen(buff);i++){\r if(buff[i]==' '||buff[i]=='\r'||buff[i]=='\n'||buff[i]=='\t'){\r whiteCount++;\r }else{\r break;\r }\r }\r if(whiteCount>0){\r for(int b=0;b<strlen(buff)-whiteCount;b++){\r buff[b] = buff[b+whiteCount];\r }\r }\r return buff;\r}\r\rvoid fileFromString(unsigned char *fname, char *data, long datasize){\r long i=0;\r FILE *fp = fopen((const char*)fname,"wb");\r for(i=0;i<datasize;i++){\r fputc(data[i],fp);\r }\r fclose(fp);\r}\r\r\r//--------------------------------------------------------------------\r\r\runsigned char* stringFromFile(char *fname){\r long fsize;\r unsigned char *a;\r\r if(fname==NULL){\r if(VERBOSE)printf("err: stringFromFile: filename was null\n",NULL);\r return 0;\r }\r fsize = getFileSize(fname);\r\r if(fsize==0){\r if(VERBOSE)printf("err: stringFromFile: file size was zero\n",NULL);\r return 0;\r }\r a = new unsigned char[fsize+1];\r \r if(a==NULL){\r if(VERBOSE)printf("err: stringFromFile: memory allocation failed\n",NULL);\r return 0;\r }\r \r getFile((char*)fname,a,fsize);\r a[fsize]=0;\r return a;\r}\r\r\r//--------------------------------------------------------------------\r\rlong getFileSize( char *fname){\r FILE *fp;\r long fsize;\r if (fname == NULL){\r if(VERBOSE)printf("err: getFileSize: filename was null\n",NULL);\r return 0;\r }\r fp = fopen((const char*)fname, "rb");\r if (fp == NULL){\r if(VERBOSE)printf("err: getFileSize: file stream failed\n",NULL);\r return 0;\r }\r if(fseek(fp, 0, SEEK_END)!=0){\r if(VERBOSE)printf("err: getFileSize: fseek failed\n",NULL);\r }\r fsize = ftell(fp);\r fclose(fp);\r return fsize;\r}\r\r\r//--------------------------------------------------------------------\r\rvoid getFile( char *filename, unsigned char *buff, int length){\r unsigned char c=0;\r long buffcnt=0;\r long i=0;\r ifstream f;\r //#if defined(__DARWIN__)\r // f.open(filename);\r //#else\r f.open((const char*)filename, ios::binary);\r //#endif\r f.read((char*)buff, length);\r //for(i=0;i<length;i++){\r // printf("{%c}",buff[i]);\r //}\r f.close();\r}\r\r\r//--------------------------------------------------------------------\r\rvoid hideMouse(){\r\r#if defined(__DARWIN__)\r //MAC\r HideCursor();\r#elif defined(linux)\r //LINUX\r //ignore\r#else\r //WINDOWS\r ShowCursor(FALSE);\r#endif\r\r\r}\r\r//--------------------------------------------------------------------\r\rvoid showMouse(){\r#if defined(__DARWIN__)\r //MAC\r ShowCursor();\r#elif defined(linux)\r //ignore\r#else\r //WINDOWS\r ShowCursor(TRUE);\r#endif\r}\r\rvoid display(){}\rvoid display2(){}\r\rvoid _execute_frame(){\r glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);\r glPushMatrix();\r#if defined(use_perspective)\r glTranslatef(-width()/2.0f,height()/2.0,-height()/2.0);\r glScalef(1,-1,1);\r#endif \r if(penta_firstloop){//first time!\r penta_firstloop = false;\r font = new JoshFont("media/usethis.ttf",40,JF_BITMAP,true,true);\r glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r setup();\r }else{\r loop();\r //glFlush();\r //glutPostRedisplay();\r _ticks++;\r }\r glPopMatrix();\r glutSwapBuffers();\r \r}\r\rvoid idle(){\r /*\r if(glutGet(GLUT_ELAPSED_TIME) - lastGlutFrameTime > frameRate){\r _execute_frame();\r lastGlutFrameTime = glutGet(GLUT_ELAPSED_TIME);\r }\r */\r}\r\r\rvoid timerFunc(int v) {\r //if(glutGet(GLUT_ELAPSED_TIME) - lastGlutFrameTime > frameRate){\r _execute_frame();\r //}\r glutTimerFunc(frameRate,timerFunc,0);\r}\r\rvoid preKeyDown(unsigned char k, int special){\r if(special){\r if(k==11){\r toggleFullScreen();\r }\r } else {\r //non special\r if(k==27){\r //exit(0);\r }else if (k==KEY_DELETE || k==KEY_BACKSPACE){\r\r\r } else if (k==6){//ctrl+f on a mac\r toggleFullScreen();\r } else {\r\r }\r }\r\r}\r\rvoid keyboardDown(unsigned char k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r preKeyDown(k,0);\r jttoolkit_keyDown(k,0);\r}\r\rvoid keyboardUp(unsigned char k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r //printf("keyboardUp: %c %i\n",k);\r jttoolkit_keyUp(k,0);\r}\r\r\rvoid specialFunc(int k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r preKeyDown(k,1);\r jttoolkit_keyDown(k,1);\r}\r\rvoid mouseMotionFunc(int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }else{\r ignored_mouseMove(x,y);\r }\r\r}\r\rvoid mousePassiveMotionFunc(int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }else{\r ignored_mouseMove(x,y);\r }\r // printf("%i %i\n",_mouseX,_mouseY);\r}\r\rvoid mouseFunc(int button, int state, int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r \r if(state==GLUT_DOWN){\r jttoolkit_mouseDown();\r } else {\r jttoolkit_mouseUp();\r }\r \r }else{\r \r if(state==GLUT_DOWN){\r ignored_mouseDown(x,y);\r } else {\r ignored_mouseUp(x,y);\r }\r \r }\r}\r\rvoid viewPerspective(float angle){\r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r gluPerspective(angle,(float)width()/(float)height(),0.0001,10000);\r //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f);\r glMatrixMode(GL_MODELVIEW);\r}\r\r\rvoid viewOrtho(){\r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r glOrtho(0,width(),-height(),0,-10000,10000);\r glMatrixMode(GL_MODELVIEW);\r}\r\rvoid reshape(int w,int h){\r // if(glutGetWindow()==MainWindowID){\r if(1){\r \r _width = w;\r _height = h;\r // to keep it propertional & let the window stretch\r // glMatrixMode(GL_PROJECTION);\r // glLoadIdentity();\r glViewport(0,0,w,h);\r // if(w<h){\r // float r = ((float)h/(float)w);\r // glOrtho(-1,1,-r,r,-2,2);\r // }else{\r float r = ((float)w/(float)h);\r // glOrtho(-r,r,-1,1,-2,2);\r // }\r // this->draw();\r \r viewPerspective(90);\r glLoadIdentity();\r \r } else { //then i can assume for now that it was the output console window.\r \r glViewport(0,0,w,h);\r float r = ((float)w/(float)h);\r \r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r \r //#if defined(use_perspective)\r //gluPerspective(90,(float)w/(float)h,0.0001,10000);\r //#else\r glOrtho(0,w,h,0,-10000,10000);\r //#endif\r //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f);\r \r glMatrixMode(GL_MODELVIEW);\r glLoadIdentity();\r }\r // jt_resizeDrawBuffer();\r}\r\rvoid jt_resizeDrawBuffer(){\r // delete [] drawbuffer;\r // drawbuffer = new unsigned char[width()*height()*4];\r}\r\rint main(int argc,char** argv){\r\r\r glutInit(&argc,argv);\r glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGBA);\r glutInitWindowSize (INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT);\r glutInitWindowPosition (INIT_WINDOW_X,INIT_WINDOW_Y);\r\r int gameMode = 0;\r if(argc>1){\r for(int i=0;i<strlen(argv[1]);i++){\r switch(argv[1][i]){\r case 'g':\r gameMode = true;\r }\r }\r }\r\r if(gameMode){\r glutGameModeString("1440x900:16@60");\r glutEnterGameMode();\r }else{\r glutCreateWindow (" ");\r }\r \r jttoolkit_init();\r glutMainLoop();\r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r \r\r //do we ever even get here?\r //FSOUND_Close();\r stop();\r exit(0);\r return 0;\r}\r\rint jttoolkit_init(){\r glutIdleFunc(idle);\r glutDisplayFunc(display);\r glutReshapeFunc(reshape);\r glutMouseFunc(mouseFunc);\r glutMotionFunc(mouseMotionFunc);\r glutPassiveMotionFunc(mousePassiveMotionFunc);\r glutKeyboardFunc (keyboardDown);\r glutKeyboardUpFunc (keyboardUp);\r glutSpecialFunc (specialFunc);\r glutTimerFunc(frameRate,timerFunc,0);\r \r // a whole bunch of switches for the openGL engine\r glEnable(GL_TEXTURE_2D);\r glEnable(GL_BLEND);\r glEnable(GL_DEPTH_TEST);\r //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);\r //glEnable(GL_LINE_SMOOTH);\r //glEnable(GL_POLYGON_SMOOTH);\r glLineWidth(1);\r // glDepthFunc(GL_LESS);//was GL_LEQUAL\r glDepthFunc(GL_LEQUAL);//was GL_LEQUAL\r glClearDepth(1.0f);\r glDisable(GL_DITHER);\r //glShadeModel(GL_SMOOTH);\r glMatrixMode(GL_PROJECTION); // The Projection Matrix\r glLoadIdentity(); // The Projection Matrix\r // Calculate The Aspect Ratio Of The Window\r //gluPerspective(45.0f,(float)wW/(float)wH,0.1f,100.0f);\r //gluLookAt(0,0,1,0,0,0,0,1,0);\r glMatrixMode(GL_MODELVIEW); // The Modelview Matrix\r glLoadIdentity(); // The Modelview Matrix\r //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Perspective Calculations\r //glEnable(GL_FOG);\r //glFogf(GL_FOG_START,-100);\r //glFogf(GL_FOG_END,-200);\r //glFogf(GL_FOG_DENSITY,0.1);\r //float r[] = {0.5,0.5,0.5,0.5};\r //glFogfv(GL_FOG_COLOR,r);\r //--------------------------------------------------------------------------------\r glClearColor(0,0,0,0);\r //also, if that doesn't work, check if the users screen is 640x48, then fullscreen the game.\r //#if defined(__DARWIN__)\r //problem with fullscreen - it disables the glut passive motion func.\r //#else\r //if(fullscreenmode)glutFullScreen();\r //#endif\r\r}\r\rint buildScreenFont(char *fontName, int size){\r return 0;\r}\r\r\rvoid _draw_single_screenFont(int fontID, char*text){\r \r glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);\r \r}\r\rvoid drawScreenFont(int fontID, char*text,int tracking){\r int i;\r int drawScreenFont_buffpt=0;\r int lineCounter=0;\r if (text == NULL)return;\r glPushAttrib(GL_LIST_BIT);\r glRasterPos3f(0,lineCounter,0);\r glListBase(fontID);\r for(i=0;i<strlen(text);i++){\r if(text[i]=='\n'){\r drawScreenFont_buff[drawScreenFont_buffpt]=0;\r _draw_single_screenFont(fontID,drawScreenFont_buff);\r lineCounter+=tracking;\r glRasterPos3f(0,lineCounter,0);\r drawScreenFont_buffpt=0;\r }else{\r drawScreenFont_buff[drawScreenFont_buffpt] = text[i];\r drawScreenFont_buffpt++;\r }\r }\r drawScreenFont_buff[drawScreenFont_buffpt]=0;\r _draw_single_screenFont(fontID,drawScreenFont_buff);\r glPopAttrib();\r}\r\r\rvoid killScreenFont(int fontID){\r glDeleteLists(fontID,256);\r}\r\r\rvoid lights(){\r glEnable(GL_LIGHT0);\r glEnable(GL_LIGHTING);\r glEnable(GL_COLOR_MATERIAL);\r glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r}\r\r\r\rvoid nolights(){\r glDisable(GL_LIGHT0);\r glDisable(GL_LIGHTING);\r glDisable(GL_COLOR_MATERIAL);\r}\r\r\rfloat randomFloat(){\r return ((float)rand())/((float)RAND_MAX);\r}\r\rvoid line(JPoint p1,JPoint p2){\r glBegin(GL_LINES);\r p1.glVertex();\r p2.glVertex();\r glEnd();\r}\r\rvoid bezier(JPoint p1,JPoint p2,JPoint p3,JPoint p4,int steps){\r float *Xs = new float[steps];\r float *Ys = new float[steps];\r float *Zs = new float[steps];\r\r\r interpolateBezier(\r p1.x,p1.y,p1.z,\r p2.x,p2.y,p2.z,\r p3.x,p3.y,p3.z,\r p4.x,p4.y,p4.z,\r steps,Xs,Ys,Zs) ;\r \r glBegin(GL_LINE_STRIP);\r p1.glVertex();\r for(int i=1;i<steps-1;i++){\r glVertex3f(Xs[i],Ys[i],Zs[i]);\r }\r p4.glVertex();\r glEnd();\r \r delete Xs;\r delete Ys;\r delete Zs;\r\r}\r\r\rvoid interpolateBezier(\r float P0X,float P0Y,float P0Z,\r float P1X,float P1Y,float P1Z,\r float P2X,float P2Y,float P2Z,\r float P3X,float P3Y,float P3Z,\r int segs,\r float Xs[] , float Ys[] , float Zs[]) {\r \r float t=0.0f,dt=1.0f/(float)segs; // calculating increment\r float Q0X,Q0Y,Q0Z;\r float Q1X,Q1Y,Q1Z;\r float Q2X,Q2Y,Q2Z;\r float R0X,R0Y,R0Z;\r float R1X,R1Y,R1Z;\r float x;float y;float z;\r float xx=P0X;float yy=P0Y;float zz=P0Z;\r for (int i=1;i<segs;i++) {\r Q0X = P0X + t*(P1X-P0X); Q0Y = P0Y + t*(P1Y-P0Y); Q0Z = P0Z + t*(P1Z-P0Z);\r Q1X = P1X + t*(P2X-P1X); Q1Y = P1Y + t*(P2Y-P1Y); Q1Z = P1Z + t*(P2Z-P1Z);\r Q2X = P2X + t*(P3X-P2X); Q2Y = P2Y + t*(P3Y-P2Y); Q2Z = P2Z + t*(P3Z-P2Z);\r R0X = Q0X + t*(Q1X-Q0X); R0Y = Q0Y + t*(Q1Y-Q0Y); R0Z = Q0Z + t*(Q1Z-Q0Z);\r R1X = Q1X + t*(Q2X-Q1X); R1Y = Q1Y + t*(Q2Y-Q1Y); R1Z = Q1Z + t*(Q2Z-Q1Z);\r x = R0X + t*(R1X-R0X);\r y = R0Y + t*(R1Y-R0Y);\r z = R0Z + t*(R1Z-R0Z);\r //drawLine(xx,yy,zz,x,y,z);\r Xs[i-1]=x;\r Ys[i-1]=y;\r Zs[i-1]=z;\r xx=x;\r yy=y;\r zz=z;\r t+=dt;\r }\r}\r\r\rfloat absf(float a){\r if(a<0)return -a;\r return a;\r}\r\r\rfloat getDist(float x1,float y1,float x2,float y2){\r double x = absf(x1-x2);\r double y = absf(y1-y2);\r x=x*x;\r y=y*y;\r return (float)sqrt(x+y);\r}\r\r\rvoid rect2polar(double x,double y,double returnPair[2]){\r returnPair[0] = getDist(0.0,0.0,x,y);\r returnPair[1] = atan2(y,x);\r}\r\rvoid polar2rect(double r,double theta,double returnPair[2]){\r returnPair[0] = r*cos(theta);\r returnPair[1] = r*sin(theta);\r}\r\r\r\r//tess\r\rvoid JTTessVertex(float x,float y, float z){\r //first look for available memory before allocating more.\r //printf("%f %f %f\n",x,y,z);\r doTessErrorCheck();\r //printf("1 %i\n",tessPtr);\r GLdouble *p = tesscache[tessBase+tessPtr];\r //printf("2\n",0);\r tessPtr++;\r \r p[0] = x;\r p[1] = y;\r p[2] = z;\r p[3] = 0;\r //printf("3\n",0);\r //if(tesscache!=0)tesscache->push((long)p);\r}\r\r\rvoid JTTessEnd(){\r //FLUSH IT!\r \r tobj = gluNewTess();\r _tessBind();\r \r if(tesscache!=0){\r gluTessBeginPolygon(tobj,NULL);\r gluTessBeginContour(tobj);\r \r for(int i=tessBase;i<tessBase+tessPtr;i++){\r GLdouble*t = tesscache[i];\r if((long)t==TESSCACHE_NEWCONTOUR){\r gluTessEndContour(tobj);\r gluTessBeginContour(tobj);\r } else {\r GLdouble *g = (GLdouble*)t;\r gluTessVertex(tobj,g,g);\r }\r }\r \r gluTessEndContour(tobj);\r gluTessEndPolygon(tobj);\r }\r gluDeleteTess(tobj);\r glFlush();\r //JTTessBegin();//reset to new.\r \r}\r\r\r/*\rvoid JTTessInit(int memsize){\r tessfreemem = new Vector();\r tesscache = new GLdouble*[memsize];\r tessmax = memsize;\r for(int i=0;i<memsize;i++){\r tesscache[i] = new GLdouble[12];\r }\r}\r*/\r\r\r\rvoid JTTessNewContour(){\r doTessErrorCheck();\r tesscache[tessBase+tessPtr] = (GLdouble*)TESSCACHE_NEWCONTOUR;\r tessPtr++;\r\r}\r\r\rvoid JTTessBegin(){\r /*\r if(tesscache!=0){\r // for(int i=0;i<tesscache->count ;i++){\r // long t = tesscache->get(i);\r // switch(t){\r // case TESSCACHE_NEWCONTOUR:break;\r // default:\r //printf("%i\n",t);\r //printf("%i\n",((GLdouble*)(t))[0]);\r //delete [] (GLdouble*)t;//i'm leaving this all in memory, but it's dangerous!\r //tessfreemem->push(t);\r //break;\r // }\r //}\r //delete tesscache;\r //tesscache = new Vector();\r \r } else { //it WAS zero.\r //tesscache = new Vector();\r }\r tessBase += tessPtr;//advance forward.\r tessPtr = 0;\r*/\r}\r\r\rvoid doTessErrorCheck(){\r if(tessPtr+tessBase>tessmax){\r printf("error:not enough memory allocated to JTTess",0);\r exit(0);\r }\r}\r\r\r\rvoid _tessBind(){ \r\r //#if defined (__DARWIN__)\r //#define TESSTYPE (GLvoid (*)(...))\r //#else\r //typedef GLvoid ( *GluTessCallbackType)(...);\r //#define TESSTYPE reinterpret_cast<GluTessCallbackType>\r //#endif\r /*\r \r gluTessCallback(tobj, GLU_TESS_VERTEX,\r TESSTYPE(glVertex3dv));\r gluTessCallback(tobj, GLU_TESS_BEGIN,\r TESSTYPE(JTTess_beginCallback));\r gluTessCallback(tobj, GLU_TESS_END,\r TESSTYPE(&JTTess_endCallback));\r gluTessCallback(tobj, GLU_TESS_ERROR,\r TESSTYPE(JTTess_errorCallback));\r gluTessCallback(tobj, GLU_TESS_COMBINE,\r TESSTYPE(JTTess_combineCallback)); \r gluTessProperty(tobj, GLU_TESS_WINDING_RULE,\r GLU_TESS_WINDING_POSITIVE);\r */\r}\r\r\r/* the callback routines registered by gluTessCallback() */\r\r\rvoid JTTESSCALLBACK JTTess_combineCallback(GLdouble coords[3], \r GLdouble *vertex_data[4],\r GLfloat weight[4], GLdouble **dataOut ){\r GLdouble *vertex;\r int i;\r doTessErrorCheck();\r vertex = tesscache[tessBase+tessPtr];//(GLdouble *) malloc(6 * sizeof(GLdouble));\r tessPtr++;\r vertex[0] = coords[0];\r vertex[1] = coords[1];\r vertex[2] = coords[2];\r for (i = 3; i < 7; i++)\r vertex[i] = weight[0] * vertex_data[0][i] \r + weight[1] * vertex_data[1][i]\r + weight[2] * vertex_data[2][i] \r + weight[3] * vertex_data[3][i];\r *dataOut = vertex;\r}\r\r\rvoid JTTESSCALLBACK JTTess_beginCallback(GLenum which){\r glBegin(which);\r}\r\rvoid JTTESSCALLBACK JTTess_endCallback(void)\r{\r glEnd();\r}\r\rvoid JTTESSCALLBACK JTTess_errorCallback(GLenum errorCode)\r{\r const GLubyte *estring;\r\r estring = gluErrorString(errorCode);\r fprintf (stderr, "Tessellation Error: %s\n", estring);\r exit (0);\r}\r\r\r/* new callback routines registered by these calls */\rvoid JTTESSCALLBACK JTTess_vertexCallback(GLvoid *vertex){\r const GLdouble *pointer;\r \r pointer = (GLdouble *) vertex;\r glColor3dv(pointer+3);\r glVertex3dv((const GLdouble*)vertex);\r}\r\r\r\rJoshFont *getFont(){\r return font;\r}\r\rJPoint mouse(){\r return JPoint(mouseX(),mouseY(),0);\r}\r\r/**\r saves the screen to a file. format support provided by image magick.\r supported formats: http://www.imagemagick.org/script/formats.php\r*/\rvoid saveScreen(char *filename){\r using namespace Magick; \r if(rawpixels==NULL){\r rawpixels = new unsigned char[width()*height()*3];\r }\r glReadPixels(0,0,width(),height(), GL_RGB , GL_UNSIGNED_BYTE ,rawpixels);\r \r /*\r //reverse the alpha vals.\r for(int i=0;i<width()*height();i++){\r rawpixels[i*4+3] = 255 - rawpixels[i*4+3];\r }\r */\r \r Image image(width(),height(),"RGB" , CharPixel , rawpixels);\r //image.modifyImage();\r image.flip();\r \r \r image.write(filename);//save\r //delete [] rawpixels;\r}\r\r\r\r/**\r saves the screen to a file. format support provided by image magick.\r supported formats: http://www.imagemagick.org/script/formats.php\r*/\rImage* getPixels(){\r using namespace Magick; \r if(rawpixels==NULL){\r rawpixels = new unsigned char[width()*height()*3];\r }\r glReadPixels(0,0,width(),height(), GL_RGB , GL_UNSIGNED_BYTE ,rawpixels);\r \r /*\r //reverse the alpha vals.\r for(int i=0;i<width()*height();i++){\r rawpixels[i*4+3] = 255 - rawpixels[i*4+3];\r }\r */\r \r Image*image = new Image(width(),height(),"RGB" , CharPixel , rawpixels);\r //image.modifyImage();\r image->flip();\r return image;\r}\r\r\r\r\r\r\r\r/* allocates new storage for an 8-bit image of the specified dimensions\r */\rpng_bytep* make_pixels(int width, int height) {\r int pixel_size = 3;\r //printf("debug debug debug 1\n",0);\r png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\r if (png_ptr == NULL) {\r \r return NULL;\r }\r //printf("debug debug debug 2\n",0);\r png_bytep *row_pointers = (unsigned char **)png_malloc(png_ptr, height*sizeof(png_bytep));\r for (int i = 0; i < height; i++)\r row_pointers[i] = (unsigned char *)png_malloc(png_ptr, width*pixel_size);\r //printf("debug debug debug 3\n",0);\r \r return row_pointers;\r}\r//--------------------------------------------------------------------------------------------\r\rvoid jt_frameRate(unsigned long f){\r frameRate = f;\r}\r\r\rvoid roundedRect(int gl_style,float x1,float y1,float x2,float y2,float radius,int steps){\r float inc = (PI*0.5)/steps;\r glBegin(gl_style);\r //draw a quarter circle here.\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i-PI*0.5) + x2 - radius;\r float y = radius*sin(inc*i-PI*0.5) + y1 + radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i) + x2 - radius;\r float y = radius*sin(inc*i) + y2 - radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i+PI*0.5) + x1 + radius;\r float y = radius*sin(inc*i+PI*0.5) + y2 - radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i+PI) + x1 + radius;\r float y = radius*sin(inc*i+PI) + y1 + radius;\r glVertex2f(x,y);\r }\r\r \r\r glEnd();\r}\r
\ No newline at end of file
+#include "jttoolkit.h"\r#include <stdio.h>\r#include <stdlib.h>\r#include <string.h>\r#include <iostream.h> \r#include <fstream.h>\r\r\r#define INIT_WINDOW_X 0\r#define INIT_WINDOW_Y 0\r#define INIT_WINDOW_WIDTH 1024\r#define INIT_WINDOW_HEIGHT 768\r\r\r//#include "gl2ps.h"\r#if defined (__DARWIN__)\r#include <ApplicationServices/ApplicationServices.h>\r#endif\r\r#define use_perspective\r#define VERBOSE 0\r//turn this on and off for speed\r\r\r//---- user-global access functions\r\rint ticks(){return _ticks;}\rint width(){return _width;}\rint height(){return _height;}\r\rint mouseX(){return _mouseX;}\rint mouseY(){return _mouseY;}\r\r\rvoid setMouseX(long xx){_mouseX = xx;}\rvoid setMouseY(long yy){_mouseY = yy;}\r\rvoid ignoreMouse(int state){_ignoreMouse = state;}\r\r//--------------\r\rvoid *threadFunc(void*stuff){\r}\r\r//------------------------------------------------------------------------\rvoid initfmod(){\r /* \r if (FSOUND_GetVersion() < FMOD_VERSION){\r printf("Error : You are using the wrong DLL version! You should be using FMOD %.02f\n", FMOD_VERSION);\r exit(1);\r }\r \r if(!FSOUND_Init(48000, 1024, FSOUND_INIT_GLOBALFOCUS)){\r printf("%s\n",FMOD_ErrorString(FSOUND_GetError()));\r }\r */\r}\r//------------------------------------------------------------------------\r\r\r\rfloat friction(){return _friction;}\rvoid setFriction(float f){_friction = f;}\r\rfloat frequencyRange(){return _frequencyRange;}\rvoid setFrequencyRange(float f){_frequencyRange = f;}\r\rvoid drawUnitSquare(){\r glBegin(GL_QUADS);\r glTexCoord2f(0,0);glVertex2f(0,0); \r glTexCoord2f(1,0);glVertex2f(1,0);\r glTexCoord2f(1,1);glVertex2f(1,1);\r glTexCoord2f(0,1);glVertex2f(0,1);\r glEnd();\r}\r\r\rvoid drawUnitSquareSlightlySmaller(){\r glBegin(GL_QUADS);\r glTexCoord2f(0.01,0.01);glVertex2f(0,0); \r glTexCoord2f(0.99,0.01);glVertex2f(1,0);\r glTexCoord2f(0.99,0.99);glVertex2f(1,1);\r glTexCoord2f(0.01,0.99);glVertex2f(0,1);\r glEnd();\r}\r\r\r\r\rvoid toggleFullScreen(){\r fullscreenmode=!fullscreenmode;\r if(fullscreenmode){\r glutFullScreen();\r } else {\r glutReshapeWindow(INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT);\r glutPositionWindow(0,10);\r }\r}\r\rchar* trimLeft(char*buff){\r //count how many to offset backward\r int whiteCount = 0;\r for(int i=0;i<strlen(buff);i++){\r if(buff[i]==' '||buff[i]=='\r'||buff[i]=='\n'||buff[i]=='\t'){\r whiteCount++;\r }else{\r break;\r }\r }\r if(whiteCount>0){\r for(int b=0;b<strlen(buff)-whiteCount;b++){\r buff[b] = buff[b+whiteCount];\r }\r }\r return buff;\r}\r\rvoid fileFromString(unsigned char *fname, char *data, long datasize){\r long i=0;\r FILE *fp = fopen((const char*)fname,"wb");\r for(i=0;i<datasize;i++){\r fputc(data[i],fp);\r }\r fclose(fp);\r}\r\r\r//--------------------------------------------------------------------\r\r\runsigned char* stringFromFile(char *fname){\r long fsize;\r unsigned char *a;\r\r if(fname==NULL){\r if(VERBOSE)printf("err: stringFromFile: filename was null\n",NULL);\r return 0;\r }\r fsize = getFileSize(fname);\r\r if(fsize==0){\r if(VERBOSE)printf("err: stringFromFile: file size was zero\n",NULL);\r return 0;\r }\r a = new unsigned char[fsize+1];\r \r if(a==NULL){\r if(VERBOSE)printf("err: stringFromFile: memory allocation failed\n",NULL);\r return 0;\r }\r \r getFile((char*)fname,a,fsize);\r a[fsize]=0;\r return a;\r}\r\r\r//--------------------------------------------------------------------\r\rlong getFileSize( char *fname){\r FILE *fp;\r long fsize;\r if (fname == NULL){\r if(VERBOSE)printf("err: getFileSize: filename was null\n",NULL);\r return 0;\r }\r fp = fopen((const char*)fname, "rb");\r if (fp == NULL){\r if(VERBOSE)printf("err: getFileSize: file stream failed\n",NULL);\r return 0;\r }\r if(fseek(fp, 0, SEEK_END)!=0){\r if(VERBOSE)printf("err: getFileSize: fseek failed\n",NULL);\r }\r fsize = ftell(fp);\r fclose(fp);\r return fsize;\r}\r\r\r//--------------------------------------------------------------------\r\rvoid getFile( char *filename, unsigned char *buff, int length){\r unsigned char c=0;\r long buffcnt=0;\r long i=0;\r ifstream f;\r //#if defined(__DARWIN__)\r // f.open(filename);\r //#else\r f.open((const char*)filename, ios::binary);\r //#endif\r f.read((char*)buff, length);\r //for(i=0;i<length;i++){\r // printf("{%c}",buff[i]);\r //}\r f.close();\r}\r\r\r//--------------------------------------------------------------------\r\rvoid hideMouse(){\r\r#if defined(__DARWIN__)\r //MAC\r HideCursor();\r#elif defined(linux)\r //LINUX\r //ignore\r#else\r //WINDOWS\r ShowCursor(FALSE);\r#endif\r\r\r}\r\r//--------------------------------------------------------------------\r\rvoid showMouse(){\r#if defined(__DARWIN__)\r //MAC\r ShowCursor();\r#elif defined(linux)\r //ignore\r#else\r //WINDOWS\r ShowCursor(TRUE);\r#endif\r}\r\rvoid display(){}\rvoid display2(){}\r\rvoid _execute_frame(){\r glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);\r glPushMatrix();\r#if defined(use_perspective)\r glTranslatef(-width()/2.0f,height()/2.0,-height()/2.0);\r glScalef(1,-1,1);\r#endif \r if(penta_firstloop){//first time!\r penta_firstloop = false;\r font = new JoshFont("media/usethis.ttf",40,JF_BITMAP,true,true);\r glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r setup();\r }else{\r loop();\r //glFlush();\r //glutPostRedisplay();\r _ticks++;\r }\r glPopMatrix();\r glutSwapBuffers();\r \r}\r\rvoid idle(){\r /*\r if(glutGet(GLUT_ELAPSED_TIME) - lastGlutFrameTime > frameRate){\r _execute_frame();\r lastGlutFrameTime = glutGet(GLUT_ELAPSED_TIME);\r }\r */\r}\r\r\rvoid timerFunc(int v) {\r //if(glutGet(GLUT_ELAPSED_TIME) - lastGlutFrameTime > frameRate){\r _execute_frame();\r //}\r glutTimerFunc(frameRate,timerFunc,0);\r}\r\rvoid preKeyDown(unsigned char k, int special){\r if(special){\r if(k==11){\r toggleFullScreen();\r }\r } else {\r //non special\r if(k==27){\r //exit(0);\r }else if (k==KEY_DELETE || k==KEY_BACKSPACE){\r\r\r } else if (k==6){//ctrl+f on a mac\r toggleFullScreen();\r } else {\r\r }\r }\r\r}\r\rvoid keyboardDown(unsigned char k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r preKeyDown(k,0);\r jttoolkit_keyDown(k,0);\r}\r\rvoid keyboardUp(unsigned char k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r //printf("keyboardUp: %c %i\n",k);\r jttoolkit_keyUp(k,0);\r}\r\r\rvoid specialFunc(int k,int x,int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }\r preKeyDown(k,1);\r jttoolkit_keyDown(k,1);\r}\r\rvoid mouseMotionFunc(int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }else{\r ignored_mouseMove(x,y);\r }\r\r}\r\rvoid mousePassiveMotionFunc(int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r }else{\r ignored_mouseMove(x,y);\r }\r // printf("%i %i\n",_mouseX,_mouseY);\r}\r\rvoid mouseFunc(int button, int state, int x, int y){\r if(!_ignoreMouse){\r _mouseX=x;\r _mouseY=y;\r \r if(state==GLUT_DOWN){\r jttoolkit_mouseDown();\r } else {\r jttoolkit_mouseUp();\r }\r \r }else{\r \r if(state==GLUT_DOWN){\r ignored_mouseDown(x,y);\r } else {\r ignored_mouseUp(x,y);\r }\r \r }\r}\r\rvoid viewPerspective(float angle){\r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r gluPerspective(angle,(float)width()/(float)height(),0.0001,10000);\r //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f);\r glMatrixMode(GL_MODELVIEW);\r}\r\r\rvoid viewOrtho(){\r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r glOrtho(0,width(),-height(),0,-10000,10000);\r glMatrixMode(GL_MODELVIEW);\r}\r\rvoid reshape(int w,int h){\r // if(glutGetWindow()==MainWindowID){\r if(1){\r \r _width = w;\r _height = h;\r // to keep it propertional & let the window stretch\r // glMatrixMode(GL_PROJECTION);\r // glLoadIdentity();\r glViewport(0,0,w,h);\r // if(w<h){\r // float r = ((float)h/(float)w);\r // glOrtho(-1,1,-r,r,-2,2);\r // }else{\r float r = ((float)w/(float)h);\r // glOrtho(-r,r,-1,1,-2,2);\r // }\r // this->draw();\r \r viewPerspective(90);\r glLoadIdentity();\r \r } else { //then i can assume for now that it was the output console window.\r \r glViewport(0,0,w,h);\r float r = ((float)w/(float)h);\r \r glMatrixMode(GL_PROJECTION);\r glLoadIdentity();\r \r //#if defined(use_perspective)\r //gluPerspective(90,(float)w/(float)h,0.0001,10000);\r //#else\r glOrtho(0,w,h,0,-10000,10000);\r //#endif\r //glFrustum(-2, 2, -2, 2, 1.0f, 100.0f);\r \r glMatrixMode(GL_MODELVIEW);\r glLoadIdentity();\r }\r // jt_resizeDrawBuffer();\r}\r\rvoid jt_resizeDrawBuffer(){\r // delete [] drawbuffer;\r // drawbuffer = new unsigned char[width()*height()*4];\r}\r\rint main(int argc,char** argv){\r\r\r glutInit(&argc,argv);\r glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGBA);\r glutInitWindowSize (INIT_WINDOW_WIDTH,INIT_WINDOW_HEIGHT);\r glutInitWindowPosition (INIT_WINDOW_X,INIT_WINDOW_Y);\r\r int gameMode = 0;\r if(argc>1){\r for(int i=0;i<strlen(argv[1]);i++){\r switch(argv[1][i]){\r case 'g':\r gameMode = true;\r }\r }\r }\r\r if(gameMode){\r glutGameModeString("1440x900:16@60");\r glutEnterGameMode();\r }else{\r glutCreateWindow (" ");\r }\r \r jttoolkit_init();\r glutMainLoop();\r\r //do we ever even get here?\r //FSOUND_Close();\r stop();\r exit(0);\r return 0;\r}\r\rint jttoolkit_init(){\r glutIdleFunc(idle);\r glutDisplayFunc(display);\r glutReshapeFunc(reshape);\r glutMouseFunc(mouseFunc);\r glutMotionFunc(mouseMotionFunc);\r glutPassiveMotionFunc(mousePassiveMotionFunc);\r glutKeyboardFunc (keyboardDown);\r glutKeyboardUpFunc (keyboardUp);\r glutSpecialFunc (specialFunc);\r glutTimerFunc(frameRate,timerFunc,0);\r \r // a whole bunch of switches for the openGL engine\r glEnable(GL_TEXTURE_2D);\r glEnable(GL_BLEND);\r glEnable(GL_DEPTH_TEST);\r //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);\r //glEnable(GL_LINE_SMOOTH);\r //glEnable(GL_POLYGON_SMOOTH);\r glLineWidth(1);\r // glDepthFunc(GL_LESS);//was GL_LEQUAL\r glDepthFunc(GL_LEQUAL);//was GL_LEQUAL\r glClearDepth(1.0f);\r glDisable(GL_DITHER);\r //glShadeModel(GL_SMOOTH);\r glMatrixMode(GL_PROJECTION); // The Projection Matrix\r glLoadIdentity(); // The Projection Matrix\r // Calculate The Aspect Ratio Of The Window\r //gluPerspective(45.0f,(float)wW/(float)wH,0.1f,100.0f);\r //gluLookAt(0,0,1,0,0,0,0,1,0);\r glMatrixMode(GL_MODELVIEW); // The Modelview Matrix\r glLoadIdentity(); // The Modelview Matrix\r //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Perspective Calculations\r //glEnable(GL_FOG);\r //glFogf(GL_FOG_START,-100);\r //glFogf(GL_FOG_END,-200);\r //glFogf(GL_FOG_DENSITY,0.1);\r //float r[] = {0.5,0.5,0.5,0.5};\r //glFogfv(GL_FOG_COLOR,r);\r //--------------------------------------------------------------------------------\r glClearColor(0,0,0,0);\r //also, if that doesn't work, check if the users screen is 640x48, then fullscreen the game.\r //#if defined(__DARWIN__)\r //problem with fullscreen - it disables the glut passive motion func.\r //#else\r //if(fullscreenmode)glutFullScreen();\r //#endif\r\r}\r\rint buildScreenFont(char *fontName, int size){\r return 0;\r}\r\r\rvoid _draw_single_screenFont(int fontID, char*text){\r \r glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);\r \r}\r\rvoid drawScreenFont(int fontID, char*text,int tracking){\r int i;\r int drawScreenFont_buffpt=0;\r int lineCounter=0;\r if (text == NULL)return;\r glPushAttrib(GL_LIST_BIT);\r glRasterPos3f(0,lineCounter,0);\r glListBase(fontID);\r for(i=0;i<strlen(text);i++){\r if(text[i]=='\n'){\r drawScreenFont_buff[drawScreenFont_buffpt]=0;\r _draw_single_screenFont(fontID,drawScreenFont_buff);\r lineCounter+=tracking;\r glRasterPos3f(0,lineCounter,0);\r drawScreenFont_buffpt=0;\r }else{\r drawScreenFont_buff[drawScreenFont_buffpt] = text[i];\r drawScreenFont_buffpt++;\r }\r }\r drawScreenFont_buff[drawScreenFont_buffpt]=0;\r _draw_single_screenFont(fontID,drawScreenFont_buff);\r glPopAttrib();\r}\r\r\rvoid killScreenFont(int fontID){\r glDeleteLists(fontID,256);\r}\r\r\rvoid lights(){\r glEnable(GL_LIGHT0);\r glEnable(GL_LIGHTING);\r glEnable(GL_COLOR_MATERIAL);\r glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r}\r\r\r\rvoid nolights(){\r glDisable(GL_LIGHT0);\r glDisable(GL_LIGHTING);\r glDisable(GL_COLOR_MATERIAL);\r}\r\r\rfloat randomFloat(){\r return ((float)rand())/((float)RAND_MAX);\r}\r\rvoid line(JPoint p1,JPoint p2){\r glBegin(GL_LINES);\r p1.glVertex();\r p2.glVertex();\r glEnd();\r}\r\rvoid bezier(JPoint p1,JPoint p2,JPoint p3,JPoint p4,int steps){\r float *Xs = new float[steps];\r float *Ys = new float[steps];\r float *Zs = new float[steps];\r\r\r interpolateBezier(\r p1.x,p1.y,p1.z,\r p2.x,p2.y,p2.z,\r p3.x,p3.y,p3.z,\r p4.x,p4.y,p4.z,\r steps,Xs,Ys,Zs) ;\r \r glBegin(GL_LINE_STRIP);\r p1.glVertex();\r for(int i=1;i<steps-1;i++){\r glVertex3f(Xs[i],Ys[i],Zs[i]);\r }\r p4.glVertex();\r glEnd();\r \r delete Xs;\r delete Ys;\r delete Zs;\r\r}\r\r\rvoid interpolateBezier(\r float P0X,float P0Y,float P0Z,\r float P1X,float P1Y,float P1Z,\r float P2X,float P2Y,float P2Z,\r float P3X,float P3Y,float P3Z,\r int segs,\r float Xs[] , float Ys[] , float Zs[]) {\r \r float t=0.0f,dt=1.0f/(float)segs; // calculating increment\r float Q0X,Q0Y,Q0Z;\r float Q1X,Q1Y,Q1Z;\r float Q2X,Q2Y,Q2Z;\r float R0X,R0Y,R0Z;\r float R1X,R1Y,R1Z;\r float x;float y;float z;\r float xx=P0X;float yy=P0Y;float zz=P0Z;\r for (int i=1;i<segs;i++) {\r Q0X = P0X + t*(P1X-P0X); Q0Y = P0Y + t*(P1Y-P0Y); Q0Z = P0Z + t*(P1Z-P0Z);\r Q1X = P1X + t*(P2X-P1X); Q1Y = P1Y + t*(P2Y-P1Y); Q1Z = P1Z + t*(P2Z-P1Z);\r Q2X = P2X + t*(P3X-P2X); Q2Y = P2Y + t*(P3Y-P2Y); Q2Z = P2Z + t*(P3Z-P2Z);\r R0X = Q0X + t*(Q1X-Q0X); R0Y = Q0Y + t*(Q1Y-Q0Y); R0Z = Q0Z + t*(Q1Z-Q0Z);\r R1X = Q1X + t*(Q2X-Q1X); R1Y = Q1Y + t*(Q2Y-Q1Y); R1Z = Q1Z + t*(Q2Z-Q1Z);\r x = R0X + t*(R1X-R0X);\r y = R0Y + t*(R1Y-R0Y);\r z = R0Z + t*(R1Z-R0Z);\r //drawLine(xx,yy,zz,x,y,z);\r Xs[i-1]=x;\r Ys[i-1]=y;\r Zs[i-1]=z;\r xx=x;\r yy=y;\r zz=z;\r t+=dt;\r }\r}\r\r\rfloat absf(float a){\r if(a<0)return -a;\r return a;\r}\r\r\rfloat getDist(float x1,float y1,float x2,float y2){\r double x = absf(x1-x2);\r double y = absf(y1-y2);\r x=x*x;\r y=y*y;\r return (float)sqrt(x+y);\r}\r\r\rvoid rect2polar(double x,double y,double returnPair[2]){\r returnPair[0] = getDist(0.0,0.0,x,y);\r returnPair[1] = atan2(y,x);\r}\r\rvoid polar2rect(double r,double theta,double returnPair[2]){\r returnPair[0] = r*cos(theta);\r returnPair[1] = r*sin(theta);\r}\r\r\r\r//tess\r\rvoid JTTessVertex(float x,float y, float z){\r //first look for available memory before allocating more.\r //printf("%f %f %f\n",x,y,z);\r doTessErrorCheck();\r //printf("1 %i\n",tessPtr);\r GLdouble *p = tesscache[tessBase+tessPtr];\r //printf("2\n",0);\r tessPtr++;\r \r p[0] = x;\r p[1] = y;\r p[2] = z;\r p[3] = 0;\r //printf("3\n",0);\r //if(tesscache!=0)tesscache->push((long)p);\r}\r\r\rvoid JTTessEnd(){\r //FLUSH IT!\r \r tobj = gluNewTess();\r _tessBind();\r \r if(tesscache!=0){\r gluTessBeginPolygon(tobj,NULL);\r gluTessBeginContour(tobj);\r \r for(int i=tessBase;i<tessBase+tessPtr;i++){\r GLdouble*t = tesscache[i];\r if((long)t==TESSCACHE_NEWCONTOUR){\r gluTessEndContour(tobj);\r gluTessBeginContour(tobj);\r } else {\r GLdouble *g = (GLdouble*)t;\r gluTessVertex(tobj,g,g);\r }\r }\r \r gluTessEndContour(tobj);\r gluTessEndPolygon(tobj);\r }\r gluDeleteTess(tobj);\r glFlush();\r //JTTessBegin();//reset to new.\r \r}\r\r\r/*\rvoid JTTessInit(int memsize){\r tessfreemem = new Vector();\r tesscache = new GLdouble*[memsize];\r tessmax = memsize;\r for(int i=0;i<memsize;i++){\r tesscache[i] = new GLdouble[12];\r }\r}\r*/\r\r\r\rvoid JTTessNewContour(){\r doTessErrorCheck();\r tesscache[tessBase+tessPtr] = (GLdouble*)TESSCACHE_NEWCONTOUR;\r tessPtr++;\r\r}\r\r\rvoid JTTessBegin(){\r /*\r if(tesscache!=0){\r // for(int i=0;i<tesscache->count ;i++){\r // long t = tesscache->get(i);\r // switch(t){\r // case TESSCACHE_NEWCONTOUR:break;\r // default:\r //printf("%i\n",t);\r //printf("%i\n",((GLdouble*)(t))[0]);\r //delete [] (GLdouble*)t;//i'm leaving this all in memory, but it's dangerous!\r //tessfreemem->push(t);\r //break;\r // }\r //}\r //delete tesscache;\r //tesscache = new Vector();\r \r } else { //it WAS zero.\r //tesscache = new Vector();\r }\r tessBase += tessPtr;//advance forward.\r tessPtr = 0;\r*/\r}\r\r\rvoid doTessErrorCheck(){\r if(tessPtr+tessBase>tessmax){\r printf("error:not enough memory allocated to JTTess",0);\r exit(0);\r }\r}\r\r\r\rvoid _tessBind(){ \r\r //#if defined (__DARWIN__)\r //#define TESSTYPE (GLvoid (*)(...))\r //#else\r //typedef GLvoid ( *GluTessCallbackType)(...);\r //#define TESSTYPE reinterpret_cast<GluTessCallbackType>\r //#endif\r /*\r \r gluTessCallback(tobj, GLU_TESS_VERTEX,\r TESSTYPE(glVertex3dv));\r gluTessCallback(tobj, GLU_TESS_BEGIN,\r TESSTYPE(JTTess_beginCallback));\r gluTessCallback(tobj, GLU_TESS_END,\r TESSTYPE(&JTTess_endCallback));\r gluTessCallback(tobj, GLU_TESS_ERROR,\r TESSTYPE(JTTess_errorCallback));\r gluTessCallback(tobj, GLU_TESS_COMBINE,\r TESSTYPE(JTTess_combineCallback)); \r gluTessProperty(tobj, GLU_TESS_WINDING_RULE,\r GLU_TESS_WINDING_POSITIVE);\r */\r}\r\r\r/* the callback routines registered by gluTessCallback() */\r\r\rvoid JTTESSCALLBACK JTTess_combineCallback(GLdouble coords[3], \r GLdouble *vertex_data[4],\r GLfloat weight[4], GLdouble **dataOut ){\r GLdouble *vertex;\r int i;\r doTessErrorCheck();\r vertex = tesscache[tessBase+tessPtr];//(GLdouble *) malloc(6 * sizeof(GLdouble));\r tessPtr++;\r vertex[0] = coords[0];\r vertex[1] = coords[1];\r vertex[2] = coords[2];\r for (i = 3; i < 7; i++)\r vertex[i] = weight[0] * vertex_data[0][i] \r + weight[1] * vertex_data[1][i]\r + weight[2] * vertex_data[2][i] \r + weight[3] * vertex_data[3][i];\r *dataOut = vertex;\r}\r\r\rvoid JTTESSCALLBACK JTTess_beginCallback(GLenum which){\r glBegin(which);\r}\r\rvoid JTTESSCALLBACK JTTess_endCallback(void)\r{\r glEnd();\r}\r\rvoid JTTESSCALLBACK JTTess_errorCallback(GLenum errorCode)\r{\r const GLubyte *estring;\r\r estring = gluErrorString(errorCode);\r fprintf (stderr, "Tessellation Error: %s\n", estring);\r exit (0);\r}\r\r\r/* new callback routines registered by these calls */\rvoid JTTESSCALLBACK JTTess_vertexCallback(GLvoid *vertex){\r const GLdouble *pointer;\r \r pointer = (GLdouble *) vertex;\r glColor3dv(pointer+3);\r glVertex3dv((const GLdouble*)vertex);\r}\r\r\r\rJoshFont *getFont(){\r return font;\r}\r\rJPoint mouse(){\r return JPoint(mouseX(),mouseY(),0);\r}\r\r/**\r saves the screen to a file. format support provided by image magick.\r supported formats: http://www.imagemagick.org/script/formats.php\r*/\rvoid saveScreen(char *filename){\r using namespace Magick; \r if(rawpixels==NULL){\r rawpixels = new unsigned char[width()*height()*3];\r }\r glReadPixels(0,0,width(),height(), GL_RGB , GL_UNSIGNED_BYTE ,rawpixels);\r \r /*\r //reverse the alpha vals.\r for(int i=0;i<width()*height();i++){\r rawpixels[i*4+3] = 255 - rawpixels[i*4+3];\r }\r */\r \r Image image(width(),height(),"RGB" , CharPixel , rawpixels);\r //image.modifyImage();\r image.flip();\r \r \r image.write(filename);//save\r //delete [] rawpixels;\r}\r\r\r\r/**\r saves the screen to a file. format support provided by image magick.\r supported formats: http://www.imagemagick.org/script/formats.php\r*/\rImage* getPixels(){\r using namespace Magick; \r if(rawpixels==NULL){\r rawpixels = new unsigned char[width()*height()*3];\r }\r glReadPixels(0,0,width(),height(), GL_RGB , GL_UNSIGNED_BYTE ,rawpixels);\r \r /*\r //reverse the alpha vals.\r for(int i=0;i<width()*height();i++){\r rawpixels[i*4+3] = 255 - rawpixels[i*4+3];\r }\r */\r \r Image*image = new Image(width(),height(),"RGB" , CharPixel , rawpixels);\r //image.modifyImage();\r image->flip();\r return image;\r}\r\r\r\r\r\r\r\r/* allocates new storage for an 8-bit image of the specified dimensions\r */\rpng_bytep* make_pixels(int width, int height) {\r int pixel_size = 3;\r //printf("debug debug debug 1\n",0);\r png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\r if (png_ptr == NULL) {\r \r return NULL;\r }\r //printf("debug debug debug 2\n",0);\r png_bytep *row_pointers = (unsigned char **)png_malloc(png_ptr, height*sizeof(png_bytep));\r for (int i = 0; i < height; i++)\r row_pointers[i] = (unsigned char *)png_malloc(png_ptr, width*pixel_size);\r //printf("debug debug debug 3\n",0);\r \r return row_pointers;\r}\r//--------------------------------------------------------------------------------------------\r\rvoid jt_frameRate(unsigned long f){\r frameRate = f;\r}\r\r\rvoid roundedRect(int gl_style,float x1,float y1,float x2,float y2,float radius,int steps){\r float inc = (PI*0.5)/steps;\r glBegin(gl_style);\r //draw a quarter circle here.\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i-PI*0.5) + x2 - radius;\r float y = radius*sin(inc*i-PI*0.5) + y1 + radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i) + x2 - radius;\r float y = radius*sin(inc*i) + y2 - radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i+PI*0.5) + x1 + radius;\r float y = radius*sin(inc*i+PI*0.5) + y2 - radius;\r glVertex2f(x,y);\r }\r\r \r for(int i=0;i<steps;i++){\r float x = radius*cos(inc*i+PI) + x1 + radius;\r float y = radius*sin(inc*i+PI) + y1 + radius;\r glVertex2f(x,y);\r }\r\r \r\r glEnd();\r}\r
\ No newline at end of file