diff --git a/Demos/OpenGL/GLDebugFont.cpp b/Demos/OpenGL/GLDebugFont.cpp index e2dbebbd5..0ac269e19 100644 --- a/Demos/OpenGL/GLDebugFont.cpp +++ b/Demos/OpenGL/GLDebugFont.cpp @@ -14,7 +14,33 @@ subject to the following restrictions: */ #include "GLDebugFont.h" -#include "GlutStuff.h" + + +#ifdef WIN32//for glut.h +#include +#endif + +//think different +#if defined(__APPLE__) && !defined (VMDMESA) +#include "TargetConditionals.h" +#if defined (TARGET_OS_IPHONE) || defined (TARGET_IPHONE_SIMULATOR) +#import +#define glOrtho glOrthof +#else +#include +#include +#include +#endif +#else + +#include +#ifdef _WINDOWS +#include +#include +#include +#endif +#endif + #include #include //for memset @@ -48,10 +74,13 @@ void GLDebugResetFont(int screenWidth,int screenHeight) } +#define USE_ARRAYS 1 void GLDebugDrawStringInternal(int x,int y,const char* string, const btVector3& rgb) { -const char* string2 = "test"; + + + const char* string2 = "test"; if (sTexture==-1) { GLDebugResetFont(sScreenWidth,sScreenHeight); @@ -59,7 +88,7 @@ const char* string2 = "test"; if (strlen(string)) { - glColor3f(rgb.getX(),rgb.getY(),rgb.getZ()); + glColor4f(rgb.getX(),rgb.getY(),rgb.getZ(),1.f); float cx; float cy; @@ -80,12 +109,40 @@ const char* string2 = "test"; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); + glOrtho(0,sScreenWidth,0,sScreenHeight,-1,1); + glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - glTranslated(x,sScreenHeight - y,0); + glTranslatef(x,sScreenHeight - y,0); +#if USE_ARRAYS + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState (GL_TEXTURE_COORD_ARRAY); +#endif + + GLfloat verts[] ={ + 0.0f, 1.0f, 0.0f, + -1.0f, -1.0f, 0.0f, + 1.0f, -1.0f, 0.0f, + 0.f,0.f,0.f + }; + + GLfloat uv_texcoords[] = { + 0,0, + 0,0, + 0,0, + 0,0 + }; + verts[0] = 0; verts[1] = 0; verts[2] = 0; + verts[3] = 16-1; verts[4] = 0; verts[5] = 0; + verts[6] = 16-1; verts[7] = 16-1; verts[8] = 0; + verts[9] = 0; verts[10] = 16-1; verts[11] = 0; + for (int i=0;i>16), GLubyte(_Color0>>8), GLubyte(_Color0), GLubyte(_Color0>>24)); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glLineWidth(2.0f); + glVertexPointer(2, GL_FLOAT, 0, vVertices); + glEnableClientState(GL_VERTEX_ARRAY); + glDrawArrays(GL_LINES,0,2); +#else + glLineWidth(13.0f); glBegin(GL_LINES); glColor4ub(GLubyte(_Color0>>16), GLubyte(_Color0>>8), GLubyte(_Color0), GLubyte(_Color0>>24)); glVertex2f((GLfloat)_X0+dx, (GLfloat)_Y0+dy); glColor4ub(GLubyte(_Color1>>16), GLubyte(_Color1>>8), GLubyte(_Color1), GLubyte(_Color1>>24)); glVertex2f((GLfloat)_X1+dx, (GLfloat)_Y1+dy); glEnd(); +#endif glDisable(GL_LINE_SMOOTH); } @@ -157,6 +92,28 @@ static void drawRect(int horStart, int vertStart, int horEnd, int vertEnd, unsig glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); +#ifdef USE_ARRAYS + GLfloat verts[] ={ + 0.0f, 1.0f, 0.0f, + -1.0f, -1.0f, 0.0f, + 1.0f, -1.0f, 0.0f, + 0.f,0.f,0.f + }; + + glColor4ub(GLubyte(argbColor00>>16), GLubyte(argbColor00>>8), GLubyte(argbColor00), GLubyte(argbColor00>>24)); + verts[0] = (GLfloat)horStart+dx; verts[1] = (GLfloat)vertStart+dy; + verts[2] = (GLfloat)horEnd+dx; verts[3] = (GLfloat)vertStart+dy; + verts[4] = (GLfloat)horEnd+dx; verts[5] = (GLfloat)vertEnd+dy; + verts[6] = (GLfloat)horStart+dx; verts[7] = (GLfloat)vertEnd+dy; + + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState (GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, verts); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + +#else glBegin(GL_QUADS); glColor4ub(GLubyte(argbColor00>>16), GLubyte(argbColor00>>8), GLubyte(argbColor00), GLubyte(argbColor00>>24)); glVertex2f((GLfloat)horStart+dx, (GLfloat)vertStart+dy); @@ -167,6 +124,8 @@ static void drawRect(int horStart, int vertStart, int horEnd, int vertEnd, unsig glColor4ub(GLubyte(argbColor01>>16), GLubyte(argbColor01>>8), GLubyte(argbColor01), GLubyte(argbColor01>>24)); glVertex2f((GLfloat)horStart+dx, (GLfloat)vertEnd+dy); glEnd(); +#endif + } void GL_DialogWindow::draw(btScalar deltaTime) @@ -222,7 +181,6 @@ void GL_DialogWindow::draw(btScalar deltaTime) int curVertPos = m_dialogVertPos; curVertPos += yInc; - glColor4f(1,1,1,1); GLDebugDrawString(m_dialogHorPos+m_dialogWidth/2-((strlen(m_dialogTitle)/2)*charWidth),m_dialogVertPos+yInc ,m_dialogTitle); curVertPos += 20; @@ -238,28 +196,10 @@ void GL_DialogWindow::draw(btScalar deltaTime) void GL_DialogWindow::saveOpenGLState() { - +#if 0 glPushAttrib(GL_ALL_ATTRIB_BITS); glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); - - if( glActiveTextureARB ) - { - glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &m_PrevActiveTextureARB); - int maxTexUnits = 1; - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTexUnits); - maxTexUnits = btMax(1, btMin(32, maxTexUnits)); - for( int i=0; i255 ) - m_MaxClipPlanes = 6; - } - for( int i=0; i +#endif + +//think different +#if defined(__APPLE__) && !defined (VMDMESA) +#include "TargetConditionals.h" +#if defined (TARGET_OS_IPHONE) || defined (TARGET_IPHONE_SIMULATOR) +#import +#define glOrtho glOrthof +#else +#include +#include +#include +#endif +#else + +#include +#ifdef _WINDOWS +#include +#include +#include +#endif +#endif #include "LinearMath/btScalar.h" #include "LinearMath/btAlignedObjectArray.h" class btTypedConstraint; diff --git a/Demos/OpenGL/RenderTexture.cpp b/Demos/OpenGL/RenderTexture.cpp index 3f12ca3ba..b91db7110 100644 --- a/Demos/OpenGL/RenderTexture.cpp +++ b/Demos/OpenGL/RenderTexture.cpp @@ -37,30 +37,43 @@ renderTexture::renderTexture(int width,int height) } -void renderTexture::grapicalPrintf(char* str, void* fontData, int startx,int starty) +void renderTexture::grapicalPrintf(char* str, void* fontData, int rasterposx,int rasterposy) { unsigned char c; - int rasterposx = startx; - int rasterposy = starty; + int x=0; + int xx=0; + while ((c = (unsigned char) *str++)) { + x=xx; + unsigned char* fontPtr = (unsigned char*) fontData; + char ch = c-32; + + int sx=ch%16; + int sy=ch/16; - unsigned char* bitmap = 0;//&fontData->bitmap_data[cd.data_offset]; - for (int y=0;y<8;y++) + for (int i=sx*16;i<(sx*16+16);i++) { - int bit = 128; - for (int x=0;x<8;x++) + int y=0; + for (int j=sy*16;j<(sy*16+16);j++) { - char packedColor = bitmap[y]; - float colorf = packedColor & bit ? 0.f : 1.f; + unsigned char packedColor = (fontPtr[i*3+255*256*3-(256*j)*3]); + //float colorf = packedColor ? 0.f : 1.f; + float colorf = packedColor/255.;// ? 0.f : 1.f; btVector4 rgba(colorf,colorf,colorf,1.f); - setPixel(rasterposx+x,rasterposy+8-y-1,rgba); - bit >>=1; + //if (colorf) + { + //setPixel(rasterposx+x,rasterposy+y,rgba); + addPixel(rasterposx+x,rasterposy+y,rgba); + } + //bit >>=1; + y++; } + x++; } - - rasterposx+= 8; + //xx+=16; + xx+=10; } } diff --git a/Demos/OpenGL/RenderTexture.h b/Demos/OpenGL/RenderTexture.h index 81e35eb8f..f252b453b 100644 --- a/Demos/OpenGL/RenderTexture.h +++ b/Demos/OpenGL/RenderTexture.h @@ -37,10 +37,19 @@ public: { unsigned char* pixel = &m_buffer[ (x+y*m_width) * 4]; - pixel[0] = (unsigned char)(255*rgba.getX()); - pixel[1] = (unsigned char)(255*rgba.getY()); - pixel[2] = (unsigned char)(255*rgba.getZ()); - pixel[3] = (unsigned char)(255*rgba.getW()); + pixel[0] = (unsigned char)(255.*rgba.getX()); + pixel[1] = (unsigned char)(255.*rgba.getY()); + pixel[2] = (unsigned char)(255.*rgba.getZ()); + pixel[3] = (unsigned char)(255.*rgba.getW()); + } + + inline void addPixel(int x,int y,const btVector4& rgba) + { + unsigned char* pixel = &m_buffer[ (x+y*m_width) * 4]; + pixel[0] = (unsigned char)btMin(255.f,((float)pixel[0] + 255.f*rgba.getX())); + pixel[1] = (unsigned char)btMin(255.f,((float)pixel[1] + 255.f*rgba.getY())); + pixel[2] = (unsigned char)btMin(255.f,((float)pixel[2] + 255.f*rgba.getZ())); +// pixel[3] = (unsigned char)btMin(255.f,((float)pixel[3] + 255.f*rgba.getW())); } inline btVector4 getPixel(int x,int y) diff --git a/Demos/Raytracer/Raytracer.cpp b/Demos/Raytracer/Raytracer.cpp index 54e47c760..95e9833b0 100644 --- a/Demos/Raytracer/Raytracer.cpp +++ b/Demos/Raytracer/Raytracer.cpp @@ -68,9 +68,9 @@ static btTransform transforms[maxNumObjects]; renderTexture* raytracePicture = 0; //this applies to the raytracer virtual screen/image buffer -static int screenWidth = 100; +static int screenWidth = 128;//256; //float aspectRatio = (3.f/4.f); -static int screenHeight = 80;//screenWidth * aspectRatio; +static int screenHeight = 64;//256;//screenWidth * aspectRatio; GLuint glTextureId; btConeShape myCone(1,1); @@ -423,12 +423,12 @@ void Raytracer::displayCallback() { for (int y=0;ysetPixel(x,y,rgba); } } - +#if 1 btVector3 rayTo; btTransform colObjWorldTransform; colObjWorldTransform.setIdentity(); @@ -485,18 +485,64 @@ void Raytracer::displayCallback() } } } - - - - - -#if 0 - raytracePicture->grapicalPrintf("CCD RAYTRACER",&BMF_font_helv10); - char buffer[256]; - sprintf(buffer,"%d RAYS / Frame",screenWidth*screenHeight*numObjects); - raytracePicture->grapicalPrintf(buffer,&BMF_font_helv10,0,10); #endif +extern unsigned char sFontData[]; + if (0) + { + + char* text="ABC abc 123 !@#"; + int x=0; + for (int cc = 0;ccsetPixel(x,y,rgba); + raytracePicture->addPixel(x,y,rgba); + } + y++; + } + x++; + } + } + } + + + //raytracePicture->grapicalPrintf("CCD RAYTRACER",sFontData); + char buffer[256]; + sprintf(buffer,"%d rays",screenWidth*screenHeight*numObjects); + //sprintf(buffer,"Toggle",screenWidth*screenHeight*numObjects); + //sprintf(buffer,"TEST",screenWidth*screenHeight*numObjects); + //raytracePicture->grapicalPrintf(buffer,sFontData,0,10);//&BMF_font_helv10,0,10); + raytracePicture->grapicalPrintf(buffer,sFontData,0,0);//&BMF_font_helv10,0,10); + + glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();