vertex glListBase



  • Versteht jemand den Code?

    #include "TheWorldOf.h"
    
    CTREPPEN::CTREPPEN()
    {
        //drawTreppe(positionX, positionZ, ebene, richtung, stufen, breite, hoehe, laenge, rotary);
    }
    
    void CTREPPEN::setUpTreppe(float positionX, float positionZ, float ebene, float stufen, float breite, float hoehe, float laenge, float rotary)
    {
        this->positionX = positionX;
        this->positionZ = positionZ;
        this->ebene = ebene;
        this->stufen = stufen;
        this->breite = breite;
        this->hoehe = hoehe;
        this->laenge = laenge;
        this->rotary = rotary;
    }
    
    void CTREPPEN::drawTreppe(float ebene, float myTallSize)
    {
    glPushMatrix ();
    
                    glTranslatef(positionX,0,positionZ);
    
                    glRotatef(-rotary,0,1.0f,0);
                    float steps = hoehe/stufen;
                    float tiefe = laenge/stufen;
                    for (float up = 0; up < stufen; up++)
                    {
                        glBegin(GL_POLYGON);
                        glNormal3f( 0.0f, 0.0f, 1.0f);
                        glTexCoord2f(breite,0.0); glVertex3f(0,(up*steps) + this->ebene + ebene + myTallSize,(up*tiefe));
                        glTexCoord2f(breite,steps); glVertex3f(0,(up*steps)+ steps + this->ebene + ebene + myTallSize,(up*tiefe));
                        glTexCoord2f(0.0,steps); glVertex3f(breite,(up*steps)+ steps + this->ebene + ebene + myTallSize,(up*tiefe));
                        glTexCoord2f(0.0,0.0); glVertex3f(breite,(up*steps) + this->ebene + ebene + myTallSize,(up*tiefe));
                        glEnd();
                        glBegin(GL_POLYGON);
                        glNormal3f( 0.0f, 0.0f, 1.0f);
                        glTexCoord2f(0.0,0.0); glVertex3f(breite,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe));
                        glTexCoord2f(0.0,steps); glVertex3f(breite,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe)+tiefe);
                        glTexCoord2f(breite,steps); glVertex3f(0,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe)+tiefe);
                        glTexCoord2f(breite,0.0); glVertex3f(0,(up*steps) + steps + this->ebene + ebene + myTallSize,(up*tiefe));
                        glEnd();
                        }
    glPopMatrix ();
    }
    
    AnsiString ausgabestr = "";
    
    LRESULT  CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);   // Declaration for WndProc
    #pragma hdrstop
    
    //---------------------------------------------------------------------------
    #pragma argsused
    
    vector<AnsiString> explode(AnsiString splitter, AnsiString textus)
    {
        vector<AnsiString> arr;
        int spl = splitter.Length();
        int y = 1;
        for(int x=1;x<textus.Length()+2;x++)
            if(textus.SubString(x,splitter.Length()) == splitter || x == textus.Length()+1)
            {
                arr.resize(arr.size()+1);
                arr[arr.size()-1] = textus.SubString(y,x-y);
                y = x + spl;
            }
        return arr;
    }
    
    void leseTexturFile(AnsiString Filename, vector<AnsiString> *TNames)
    {
      int iFileHandle;
      int iFileLength;
      int iBytesRead;
      char *pszBuffer;
      AnsiString str = "";
        try
        {
          iFileHandle = FileOpen(Filename, fmOpenRead);
          iFileLength = FileSeek(iFileHandle,0,2);
          FileSeek(iFileHandle,0,0);
          pszBuffer = new char[iFileLength+1];
          iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
          FileClose(iFileHandle);
          for (int i=0;i<iBytesRead;i++)
          {
            str = str + pszBuffer[i];
          }
          delete [] pszBuffer;
        }
        catch(...)
        {
          Application->MessageBox("Can't perform one of the following file operations: Open, Seek, Read, Close.", "File Error", IDOK);
        }
        vector<AnsiString> arr = explode("\r\n", str);
        for(unsigned int x=0; x<arr.size(); x++){
            if(arr[x].SubString(1,2) == "//")
            TNames->push_back(arr[x].SubString(3,arr[x].Length()-2));
        }
        //return TNames;
    }
    
    void readstr(FILE *f,char *string)
    {
            do
            {
                    fgets(string, 255, f);
            } while ((string[0] == '/') || (string[0] == '\n'));
            return;
    }
    
    int in_array(vector<AnsiString> arr, AnsiString str)
    {
        for(unsigned int x=0; x<arr.size(); x++)
            if(arr[x] == str) return x;
        return -1;
    }
    
    GLvoid BuildFont(GLvoid)        // Build Our Bitmap Font
    {
            HFONT        font;                // Windows font ID
            HFONT        oldfont;        // Used for good house keeping
    
            base = glGenLists(96);        // Storage for 96 characters
    
            font = CreateFont(        -16,                                                // Height of font
                                                    0,                                // Width of font
                                                    0,                                // Angle of escapement
                                                    0,                                // Orientation angle
                                                    FW_BOLD,                        // Font weight
                                                    FALSE,                          // Italic
                                                    FALSE,                                // Underline
                                                    FALSE,                                // Strikeout
                                                    ANSI_CHARSET,                   // Character set identifier
                                                    OUT_TT_PRECIS,                        // Output precision
                                                    CLIP_DEFAULT_PRECIS,            // Clipping precision
                                                    ANTIALIASED_QUALITY,                // Output quality
                                                    FF_DONTCARE|DEFAULT_PITCH,      // Family and pitch
                                                    "Courier New");                        // Font name
    
            oldfont = (HFONT)SelectObject(hDC, font);       // Selects the font we want
            wglUseFontBitmaps(hDC, 32, 96, base);           // Builds 96 characters starting at character 32
            SelectObject(hDC, oldfont);                        // Selects the font we want
            DeleteObject(font);                                // Delete the font
    }
    
    GLvoid KillFont(GLvoid)                 // Delete the font list
    {
            glDeleteLists(base, 96);        // Delete all 96 characters
    }
    
    GLvoid glPrint(const char *fmt, ...)    // Custom GL "Print" routine
    {
            char text[256];                        // Holds our string
            va_list ap;                        // Pointer to list of arguments
    
            if (fmt == NULL)                // If there's no text
                    return;                        // Do nothing
    
            va_start(ap, fmt);                // Parses the string for variables
                vsprintf(text, fmt, ap);        // And converts symbols to actual numbers
            va_end(ap);                        // Results are stored in text
    
            glPushAttrib(GL_LIST_BIT);        // Pushes the display list bits
            glListBase(base - 32);                // Sets the base character to 32
            glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);        // Draws the display list text
            glPopAttrib();                                                // Pops the display list bits
    }
    
    void getLastPosition()
    {
        //Letzte Position wieder aufnehemen
        int iFileHandle = FileOpen("reinspeichertext.txt", fmOpenRead);
        int iFileLength = FileSeek(iFileHandle,0,2);
        FileSeek(iFileHandle,0,0);
        char *pszBuffer = new char[iFileLength+1];
        int iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
        FileClose(iFileHandle);
        AnsiString s = "";
        for(int i=0; i< iFileLength; i++)
        s = s + pszBuffer[i];
        vector<AnsiString>arr = explode(" ", s);
        xpos = StrToFloat(Trim(arr[0]));
        zpos = StrToFloat(Trim(arr[1]));
        yrot = StrToFloat(Trim(arr[2]));
        ylook = yrot;
    }
    
    bool Pointtest(VERTiX P1,VERTiX P2,VERTiX P3, float xp, float zp)
    {
    VERTiX temp1,temp2,temp3;
    float Test1,Test2;
    
     temp1.x=P1.x-xp,
     temp1.z=P1.z-zp,
     temp2.x=P3.x-xp,
     temp2.z=P3.z-zp,
     temp3.x=P2.x-xp,
     temp3.z=P2.z-zp;
    
    Test1=temp1.x * temp2.z-temp1.z*temp2.x;
    Test2=temp2.x * temp3.z-temp2.z*temp3.x;
    
    if((Test1>0 && Test2>0)||(Test1<0 && Test2<0))
    {Test2=temp3.x * temp1.z-temp3.z*temp1.x;
      if((Test1>0 && Test2>0)||(Test1<0 && Test2<0)){
         //statusString = "!";
         return true;
         }else{
          //statusString = "-";
          return false ;
          }
    }
    else{
    //statusString = "-";
    return false;
    }
    }
    
    int terraVertIndex(float xp, float zp)
    {
    double fraction, integer;
    fraction = modf(xp, &integer);
    int X = integer;
    fraction = modf(zp, &integer);
    int Z = integer;
    
    VERTS v;
    int von = (X*Z)-3;
    if (von < 0) von = 0;
    for (int x=0; x<sector1.numtriangle; x++)
    {
        v = sector1.triangle[x];
        if (Pointtest(v.vertex[0],v.vertex[1],v.vertex[2], xp, zp)){
           return x;
        }
    }
    }
    
    float getHeight(SECTOR sector1, float ix, float iz, int index, int name)
    {
    float x1,y1,z1,x2,y2,z2,x3,y3,z3;
    float ret;
    
    VERTS v;
        v = sector1.triangle[index];
        x1 = v.vertex[0].x;
        y1 = v.vertex[0].y;
        z1 = v.vertex[0].z;
        x2 = v.vertex[1].x;
        y2 = v.vertex[1].y;
        z2 = v.vertex[1].z;
        x3 = v.vertex[2].x;
        y3 = v.vertex[2].y;
        z3 = v.vertex[2].z;
    
       int fall = 0;
        float lambda1, lambda2;
    
         if (x2 != x1){
             lambda2 = ( (iz-z1) - (ix-x1)*(z2-z1)/(x2-x1) )/( (z3-z1) - (x3-x1)*(z2-z1)/(x2-x1) );
             ret =  y1 +  (y2-y1)/(x2-x1)*(ix-x1)  +( (y3-y1)-(x3-x1)*(y2-y1)/(x2-x1) )*lambda2;
             fall = 1;
         }else{
             lambda2 = (ix-x1)/(x3-x2);
             lambda1 = ( (iz-z1) - (z3-z1)*lambda2 )/(z2-z1);
             ret = y1 + (y2-y1) * lambda1 + (y3-y1)*lambda2;
             fall = 2;
         }
    //if (name > 1 && (yRoll[name-1] > ret + 0.3 || yRoll[name-1] < ret + 0.3 || yRoll[name-1] > ret - 0.3 || yRoll[name-1] < ret - 0.3))
    //ret = yRoll[name-1];
    //ausgabestr = ausgabestr + st;
    //if (name == 0)
    //ausgabestr = ausgabestr + AnsiString(fall) + ": " + FloatToStrF(ret,0,3,3) + " \t N: " + AnsiString(N) + " \t x3: " + FloatToStrF(x3,0,3,3) + " \t y3: " + FloatToStrF(y3,0,3,3) + " \t z3: " + FloatToStrF(z3,0,3,3) + " \t xp: " + FloatToStrF(ix,0,3,3) + " \t zp: " + FloatToStrF(iz,0,3,3)  + "\r\n";
    //statusString = "return: " + FloatToStrF(ret,0,4,4) + " & N: " + AnsiString(N) + " & xpos: " + FloatToStrF(ix,0,4,4) + " & zpos: " + FloatToStrF(iz,0,4,4);
    return ret;
    }
    
    void SetupWorld()
    {
        getLastPosition();
    
        long L;
        TColor TC;
        int w,h;
        Graphics::TBitmap *bit = new Graphics::TBitmap;
        bit->LoadFromFile("Data\\Ebenen\\Scenen\\Scene1\\terrain001.bmp");
    
        w = bit->Width;
        h = bit->Height;
    
        vector<vector<float> > high;
        high.resize(w);
        for(int x=0; x<w; x++){
            high[x].resize(h);
            for (int z=0; z<h; z++){
                TC = bit->Canvas->Pixels[x][z];
                L = ColorToRGB(TC);
                high[x][z] = L/25.6;
            }
        }
        delete bit;
    
        sector1.numtriangle = (w*h)*2;
        sector1.triangle = new VERTS[sector1.numtriangle];
        int count = 0;
        GLfloat tX, tZ;
    
        for (int loopX = 0; loopX < w-1; loopX++)
        {
            for (int loopZ = 0; loopZ < h-1; loopZ++)
            {
                 tX = ((0.01)*loopX);
                 tZ = h-((0.01)*loopZ);
                 sector1.triangle[count].typ = 0;
                 sector1.triangle[count].matX = loopX;
                 sector1.triangle[count].index = count;
                 //sector1.triangle[count].matY = loopY;
                 sector1.triangle[count].matZ = loopZ;
    
                 sector1.triangle[count].vertex[0].x = -loopX;
                 sector1.triangle[count].vertex[0].y =  high[loopX][loopZ];
                 sector1.triangle[count].vertex[0].z = -loopZ;
                 sector1.triangle[count].vertex[0].u = tX+(0.01);
                 sector1.triangle[count].vertex[0].v = tZ-(0.00);
    
                 sector1.triangle[count].vertex[1].x = -loopX;
                 sector1.triangle[count].vertex[1].y =  high[loopX][loopZ+1];
                 sector1.triangle[count].vertex[1].z = -loopZ - 1;
                 sector1.triangle[count].vertex[1].u = tX+(0.01);
                 sector1.triangle[count].vertex[1].v = tZ-(0.01);
    
                 sector1.triangle[count].vertex[2].x = -loopX - 1;
                 sector1.triangle[count].vertex[2].y =  high[loopX+1][loopZ+1];
                 sector1.triangle[count].vertex[2].z = -loopZ - 1;
                 sector1.triangle[count].vertex[2].u = tX+(0.02);
                 sector1.triangle[count].vertex[2].v = tZ-(0.01);
    
                 count++;
    
                 sector1.triangle[count].index = count;
                 sector1.triangle[count].typ = 0;
    
                 sector1.triangle[count].vertex[0].x = -loopX;
                 sector1.triangle[count].vertex[0].y =  high[loopX][loopZ];
                 sector1.triangle[count].vertex[0].z = -loopZ;
                 sector1.triangle[count].vertex[0].u = tX+(0.01);
                 sector1.triangle[count].vertex[0].v = tZ-(0.00);
    
                 sector1.triangle[count].vertex[1].x = -loopX - 1;
                 sector1.triangle[count].vertex[1].y =  high[loopX+1][loopZ+1];
                 sector1.triangle[count].vertex[1].z = -loopZ - 1;
                 sector1.triangle[count].vertex[1].u = tX+(0.02);
                 sector1.triangle[count].vertex[1].v = tZ-(0.01);
    
                 sector1.triangle[count].vertex[2].x = -loopX - 1;
                 sector1.triangle[count].vertex[2].y =  high[loopX+1][loopZ];
                 sector1.triangle[count].vertex[2].z = -loopZ;
                 sector1.triangle[count].vertex[2].u = tX+(0.02);
                 sector1.triangle[count].vertex[2].v = tZ-(0.00);
    
                 sector1.triangle[count].matX = loopX;
                 //sector1.triangle[count].matY = loopY;
                 sector1.triangle[count].matZ = loopZ;
    
                 count++;
            }
        }
    
        int N;
        float up;
        balls.baelle = new BALL[2];
    
        balls.baelle[0].xRoll = -8.22;
        balls.baelle[0].zRoll = -8.22;
        N = terraVertIndex(balls.baelle[0].xRoll, balls.baelle[0].zRoll);
        up = getHeight(sector1, balls.baelle[0].xRoll, balls.baelle[0].zRoll, N, 0);
        balls.baelle[0].yRoll = 0;
        balls.baelle[0].oldY = up;
        balls.baelle[0].xDir = 0.03;
        balls.baelle[0].zDir = 0.06;
        balls.baelle[0].speed = 2;
        balls.baelle[0].xStart = balls.baelle[0].xRoll;
        balls.baelle[0].zStart = balls.baelle[0].zRoll;
        balls.baelle[0].liveStatus = 0;
        balls.baelle[0].gravitation = 5;  //Je größer desto leichter
    
        balls.baelle[1].xRoll = -6.22;
        balls.baelle[1].zRoll = -6.22;
        N = terraVertIndex(balls.baelle[1].xRoll, balls.baelle[1].zRoll);
        up = getHeight(sector1, balls.baelle[1].xRoll, balls.baelle[1].zRoll, N, 1);
        balls.baelle[1].yRoll = 0;
        balls.baelle[1].oldY = up;
        balls.baelle[1].xDir = 0.08;
        balls.baelle[1].zDir = 0.06;
        balls.baelle[1].speed = 3;
        balls.baelle[1].xStart = balls.baelle[1].xRoll;
        balls.baelle[1].zStart = balls.baelle[1].zRoll;
        balls.baelle[1].liveStatus = 1;
        balls.baelle[1].gravitation = 5;  //Je größer desto leichter
    
        high.clear();
        delete &high;
        return;
    }
    
    AUX_RGBImageRec *LoadBMP(char *Filename)                // Loads a bitmap image
    {
            FILE *File=NULL;                                // File handle
    
            if (!Filename)                                  // Make sure a filename was given
            {
                    return NULL;                            // If not return NULL
            }
    
            File=fopen(Filename,"r");                       // Check to see if the file exists
    
            if (File)                                       // Does the file exist?
            {
                    fclose(File);                           // Close the handle
                    return auxDIBImageLoad(Filename);       // Load the bitmap and return a pointer
            }
            return NULL;                                    // If load failed return NULL
    }
    
    int LoadGLTextures()                                    // Load bitmaps and convert to textures
    {
            int Status = false;                             // Status indicator
    
            AUX_RGBImageRec *TextureImage[1];               // Create storage space for the texture
    
            memset(TextureImage,0,sizeof(void *)*1);        // Set the pointer to NULL
    
            for (unsigned  int f=0; f<1; f++)
            {
                vector<AnsiString> arr;
                arr.push_back("Data/Texturen/Scenen/Scene1/Mauer1.bmp");
                arr.push_back("Data/Texturen/Scenen/Scene1/Mauer2.bmp");
                arr.push_back("Data/Texturen/Scenen/Scene1/Mauer3.bmp");
                arr.push_back("Data/Texturen/Scenen/Scene1/Kachel1.bmp");
                arr.push_back("Data/Texturen/Scenen/Scene1/black.bmp");
                arr.push_back("Data/Texturen/Scenen/Scene1/karoGray.bmp");
                for (unsigned int x=0; x<6; x++)
                {
                if (TextureImage[0]=LoadBMP(arr[x].c_str()))
                {
                    Status = true;                          // Set the status to TRUE
                    glGenTextures(3, &textureX[x][0]);          // Create three textures
    
                    // Niedrigste Qualität
                    glBindTexture(GL_TEXTURE_2D, textureX[x][0]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
                    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
                    // Mittlere Qualität
                    glBindTexture(GL_TEXTURE_2D, textureX[x][1]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
                    // Hohe Qualität
                    glBindTexture(GL_TEXTURE_2D, textureX[x][2]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
                    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
                }else{
                     return false;
                }
                //Bitmap aus dem RAM löschen
                if (TextureImage[0]){
                    if (TextureImage[0]->data){
                        free(TextureImage[0]->data);
                    }
                    free(TextureImage[0]);
                }
                }
            }
    
            return Status;          // Return the status
    }
    
    int LoadGLTerraTexture()                                    // Load bitmaps and convert to textures
    {
            int Status = false;                             // Status indicator
    
            AUX_RGBImageRec *TextureImage[1];               // Create storage space for the texture
    
            memset(TextureImage,0,sizeof(void *)*1);        // Set the pointer to NULL
    
                    TextureImage[0]=LoadBMP("Data\\Texturen\\Scenen\\Scene1\\terraCol001.bmp");
    
                    Status = true;                          // Set the status to TRUE
                    glGenTextures(3, &terraTexture[0][0]);          // Create three textures
    
                    // Niedrigste Qualität
                    glBindTexture(GL_TEXTURE_2D, terraTexture[0][0]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
                    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
                    // Mittlere Qualität
                    glBindTexture(GL_TEXTURE_2D, terraTexture[0][1]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
                    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
                    // Hohe Qualität
                    glBindTexture(GL_TEXTURE_2D, terraTexture[0][2]);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
                    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
    
                //Bitmap aus dem RAM löschen
                if (TextureImage[0]){
                    if (TextureImage[0]->data){
                        free(TextureImage[0]->data);
                    }
                    free(TextureImage[0]);
                }
    
            return Status;          // Return the status
    }
    
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)     // Resize and initialize the GL window
    {
            if (height == 0)                        // Prevent a divide by zero by
            {
                    height = 1;                     // Making height equal One
            }
    
            glViewport(0, 0, width, height);        // Reset the current viewport
    
            glMatrixMode(GL_PROJECTION);            // Select the projection matrix
            glLoadIdentity();                       // Reset the projection matrix
    
            // Calculate the aspect ratio of the window
            gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
    
            glMatrixMode(GL_MODELVIEW);             // Select the modelview matrix
            glLoadIdentity();                       // Reset the modelview matrix
    }
    
    // Loads the .RAW file and stores it in pHeightMap
    void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap)
    {
            FILE *pFile = NULL;
    
            // Open the file in read / binary mode.
            pFile = fopen( strName, "rb" );
    
            // Check to see if we found the file and could open it
            if ( pFile == NULL )
            {
                    // Display error message and stop the function
                    MessageBox(NULL, "Can't Find The Height Map!", "Error", MB_OK);
                    return;
            }
    
            fread( pHeightMap, 1, nSize, pFile );
    
            // After we read the data, it's a good idea to check if everything read fine
            int result = ferror( pFile );
    
            // Check if we received an error
            if (result)
            {
                    MessageBox(NULL, "Failed To Get Data!", "Error", MB_OK);
            }
    
            // Close the file.
            fclose(pFile);
    }
    
    int InitGL(GLvoid)      // All setup for OpenGL goes here
    {
    glShadeModel(GL_SMOOTH);
    
            leseTexturFile("Data/Ebenen/Scenen/Scene1/Ebenen.txt", &ebenenFileNames);
    
            //if (!LoadGLTextures())          // Jump to texture loading routine
            //{
            //        return false;           // If texture didn't load return FALSE
            //}
    
            if (!LoadGLTerraTexture())
            {
                    return false;
            }
    
            glEnable(GL_TEXTURE_2D);                // Enable texture mapping
            glBlendFunc(GL_SRC_ALPHA,GL_ONE);        // Set the blending function for translucency
            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);        // This will clear the background color to black
            glClearDepth(1.0);                        // Enables clearing of the depth buffer
    
            // GL_LEQUAL ,oder  GL_LESS(war am Anfang so)
            glDepthFunc(GL_LEQUAL);                        // The type of depth test to do
            glEnable(GL_DEPTH_TEST);                // Enables depth testing
            glShadeModel(GL_SMOOTH);                // Enables smooth color shading
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);        // Really nice perspective calculations
    
            glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
            glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
            glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
            glEnable(GL_LIGHT1);
    
            //sphere
            quadratic=gluNewQuadric();
            gluQuadricTexture(quadratic, GL_TRUE);
    
            BuildFont();                            // Build the font
            SetupWorld();
            return TRUE;            // Initialization went OK
    }
    
    void getPolygon()
    {
        //AnsiString s = "";
        //s = s + "xpos: " + FloatToStrF(xpos, 0,7,4) + ", zpos: " + FloatToStrF(zpos, 0,7,4) + ", yrot: " + FloatToStrF(yrot, 0,7,4);
    
        //statusString = s;
    }
    
    float ballSchub(float z)
    {
        z = z*(-1);
        if (z < 0 && z > -0.05) return -0.05;
        if (z > 0 && z < 0.05) return 0.05;
    
    //balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
    }
    
    int DrawGLScene(GLvoid)         // Here's where we do all the drawing
    {
    
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glColor3f(1.0f,1.0f,1.0f);
            glTranslatef(0.0f,0.0f,0.0f);
            glLoadIdentity();
    
            float a_q, b_q, c_q, d_q, e_q;
    
            GLfloat xtrans = -xpos;
            GLfloat ztrans = -zpos;
            GLfloat ytrans = -walkbias-0.25f;
            GLfloat sceneroty = 360.0f - yrot;
            ylook = sceneroty; //Nur zum speichern und laden
    
            glRotatef(lookupdown,1.0f,0.0,0.0);
            glRotatef(sceneroty,0,1.0f,0);
    
            glBindTexture(GL_TEXTURE_2D, terraTexture[0][filter]);
            glTranslatef(xtrans, ytrans, ztrans);
    
            for (int loop = 0; loop < sector1.numtriangle; loop++)
            {
                glBegin(GL_TRIANGLES);
                glNormal3f( 0.0f, 0.0f, 1.0f);
                for (int v=0; v<3; v++){
                    a_q = sector1.triangle[loop].vertex[v].x;
                    b_q = sector1.triangle[loop].vertex[v].y+ebene+terraUp;
                    c_q = sector1.triangle[loop].vertex[v].z;
                    d_q = sector1.triangle[loop].vertex[v].u;
                    e_q = sector1.triangle[loop].vertex[v].v;
                    glTexCoord2f(d_q,e_q); glVertex3f(a_q,b_q,c_q);
                }
                glEnd();
            }
    
            bp = true;
            glBindTexture(GL_TEXTURE_2D, textureX[0][filter]);
            for (int x=0; x<1; x++){
                switch(balls.baelle[x].liveStatus)
                {
                    case 0: glColor3f(0.0f,0.6f,0.3f);
                    break;
                    case 1: glColor3f(1.0f,1.0f,1.0f);
                    break;
                    default: glColor3f(1.0f,1.0f,1.0f);
                }
    
                //Dauerbremse
                //balls.baelle[x].xDir = balls.baelle[x].xDir - (balls.baelle[x].xDir/7000);
                //balls.baelle[x].zDir = balls.baelle[x].zDir - (balls.baelle[x].zDir/7000);
    
                float nextX = balls.baelle[x].xRoll + balls.baelle[x].xDir;
                float nextZ = balls.baelle[x].zRoll + balls.baelle[x].zDir;
    
                if(nextX == balls.baelle[x].xRoll && nextZ == balls.baelle[x].zRoll)
                {
                            balls.baelle[x].xRoll = balls.baelle[x].xStart;
                            balls.baelle[x].zRoll = balls.baelle[x].zStart;
                            balls.baelle[x].xDir = balls.baelle[x].xStart;
                            balls.baelle[x].zDir = balls.baelle[x].zStart;
                            break;
                }
    
                GLfloat up;
                if(nextX*(-1) > 1 && nextX*(-1) < 99 && nextZ*(-1) > 1 && nextZ*(-1) < 99){
                    int N = terraVertIndex(nextX, nextZ);
                    up = getHeight(sector1, nextX, nextZ, N, x+1);
                }
    
                try{
                    balls.baelle[x].xDir = balls.baelle[x].xDir+(((balls.baelle[x].oldY-up)*balls.baelle[x].xDir)/balls.baelle[x].gravitation);
                        if(balls.baelle[x].oldY-up >= 0.2 && balls.baelle[x].oldY-up <= -0.2)
                            balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
                }catch(...){
                    balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
                }
                try{
                    balls.baelle[x].zDir = balls.baelle[x].zDir+(((balls.baelle[x].oldY-up)*balls.baelle[x].zDir)/balls.baelle[x].gravitation);
                        if(balls.baelle[x].oldY-up >= 0.2 && balls.baelle[x].oldY-up <= -0.2)
                            balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
                }catch(...){
                    balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
                }
    
                if (balls.baelle[x].xRoll < -99 || balls.baelle[x].xRoll > 1)
                            balls.baelle[x].xDir = balls.baelle[x].xDir*(-1);
                if (balls.baelle[x].zRoll < -99 || balls.baelle[x].zRoll > 1)
                            balls.baelle[x].zDir = balls.baelle[x].zDir*(-1);
    
                balls.baelle[x].xRoll = balls.baelle[x].xRoll + balls.baelle[x].xDir;
                balls.baelle[x].zRoll = balls.baelle[x].zRoll + balls.baelle[x].zDir;
    
                if (recorder == true){
                ausgabestr = ausgabestr + "oY: " + FloatToStrF(balls.baelle[x].oldY,0,4,4) + "\tu: " + FloatToStrF(up,0,4,4) + "\txR: " + FloatToStrF(balls.baelle[x].xRoll,0,4,4) + "\tzR: " + FloatToStrF(balls.baelle[x].zRoll,0,4,4) + "\txD: " + FloatToStrF(balls.baelle[x].xDir,0,4,4) + "\tzD: " + FloatToStrF(balls.baelle[x].zDir,0,4,4) + "\r\n";
                }
    
                balls.baelle[x].oldY = up;
    
                try{
                glPushMatrix();
                glTranslatef(balls.baelle[x].xRoll,balls.baelle[x].yRoll+up+(terraUp-ebene)+0.22,balls.baelle[x].zRoll);
                gluSphere(quadratic,0.22,32,32);
                glPopMatrix();
                }catch(...){}
            }
            glColor3f(1.0f,1.0f,1.0f);
            bp = false;
            statusString = FloatToStrF(balls.baelle[0].xRoll ,0,4,4) + " : " + FloatToStrF(balls.baelle[0].zRoll,0,4,4);
    
            //glLoadIdentity();
            /*
            //Statusleiste zeichnen
    
            glPushMatrix();
            glBindTexture(GL_TEXTURE_2D, textureX[4][filter]);
            glBegin(GL_QUADS);
            glNormal3f( 0.0f, 0.0f, 0.001f);
            glTexCoord2f(0,0); glVertex3f(-0.5,-0.5,-0.125);
            glTexCoord2f(50,0); glVertex3f(-0.5,-0.0425,-0.125);
            glTexCoord2f(50,50); glVertex3f(0.5,-0.0425,-0.125);
            glTexCoord2f(0,50); glVertex3f(0.5,-0.5,-0.125);
            glEnd();
            glPopMatrix();
    
            */
            glLoadIdentity();
            //glPushMatrix();
            //gettime(&mTime);
            //mTime.ti_sec;
    
            glTranslatef(0.0f,0.0f,-0.73f);          // Move one unit into the screen
    
            // Pulsing colors based on text position
            //glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
            glBindTexture(GL_TEXTURE_2D, textureX[6][filter]);
            // Position the text on the screen
            glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.35f*float(sin(cnt2)));
            //glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), -0.2458f);
    
            //statusString = FloatToStrF(yRoll[0],0,3,3);// + " : " + FloatToStrF(yRoll[0],0,3,3) + " : " + FloatToStrF(zRoll[0],0,3,3) + " ~ " + FloatToStrF(xpos,0,3,3) + " : " + FloatToStrF(terraUp,0,3,3) + " : " + FloatToStrF(zpos,0,3,3);
            glPrint(statusString.c_str(), cnt1);
            //glPopMatrix();
    
            return true;            // Everything went OK
    }
    
    GLvoid KillGLWindow(GLvoid)     // Properly kill the window
    {
    
    AnsiString as = "";
    as = as + FloatToStrF(xpos, 0,7,4) + " ";
    as = as + FloatToStrF(zpos, 0,7,4) + " ";
    as = as + FloatToStrF(ylook, 0,7,4) + " ";
    as = as + FloatToStrF(heading, 0,7,4);
    int iFileHandle;
    int iLength;
    iFileHandle = FileCreate("reinspeichertext.txt");
    FileWrite(iFileHandle, as.c_str(), as.Length());
    FileClose(iFileHandle);
    
            if (fullscreen)         // Are we in fullscreen mode?
            {
                    ChangeDisplaySettings(NULL,0);  // If so switch back to the desktop
                    ShowCursor(true);               // Show mouse pointer
            }
    
            if (hRC)        // Do we have a rendering context?
            {
                    if (!wglMakeCurrent(NULL,NULL))         // Are we able to release the DC and RC contexts?
                    {
                            MessageBox(NULL,"Release of DC and RC failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
                    }
    
                    if (!wglDeleteContext(hRC))             // Are we able to delete the RC?
                    {
                            MessageBox(NULL,"Release rendering context failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
                    }
                    hRC = NULL;             // Set RC to NULL
            }
    
            if (hDC && !ReleaseDC(hWnd,hDC))        // Are we able to release the DC
            {
                    MessageBox(NULL,"Release device context failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
                    hDC = NULL;             // Set DC to NULL
            }
    
            if (hWnd && !DestroyWindow(hWnd))       // Are we able to destroy the window?
            {
                    MessageBox(NULL,"Could not release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
                    hWnd = NULL;            // Set hWnd to NULL
            }
    
            if (!UnregisterClass("OpenGL",hInstance))       // Are we able to unregister class
            {
                    MessageBox(NULL,"Could not unregister class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
                    hInstance = NULL;       // Set hInstance to NULL
            }
    }
    
    /*        This Code Creates Our OpenGL Window.  Parameters Are:
     *        title                        - Title To Appear At The Top Of The Window
     *        width                        - Width Of The GL Window Or Fullscreen Mode
     *        height                        - Height Of The GL Window Or Fullscreen Mode
     *        bits                        - Number Of Bits To Use For Color (8/16/24/32)
     *        fullscreenflag        - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)*/
    
    BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
    {
    
            WindowRect.left = (long)0;              // Set left value to 0
            WindowRect.right = (long)width;                // Set right value to requested width
            WindowRect.top = (long)0;               // Set top value to 0
            WindowRect.bottom = (long)height;       // Set bottom value to requested height
    
            fullscreen = fullscreenflag;              // Set the global fullscreen flag
    
            hInstance               = GetModuleHandle(NULL);                // Grab an instance for our window
            wc.style                = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;   // Redraw on size, and own DC for window
            wc.lpfnWndProc          = (WNDPROC) WndProc;                        // WndProc handles messages
            wc.cbClsExtra           = 0;                                        // No extra window data
            wc.cbWndExtra           = 0;                                        // No extra window data
            wc.hInstance            = hInstance;                                // Set the Instance
            wc.hIcon                = LoadIcon(NULL, IDI_WINLOGO);                // Load the default icon
            wc.hCursor              = LoadCursor(NULL, IDC_ARROW);                // Load the arrow pointer
            wc.hbrBackground        = NULL;                                        // No background required for GL
            wc.lpszMenuName                = NULL;                                        // We don't want a menu
            wc.lpszClassName        = "OpenGL";                                // Set the class name
    
            if (!RegisterClass(&wc))                                        // Attempt to register the window class
            {
                    MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    
                    return false;   // Return FALSE
            }
    
            if (fullscreen)         // Attempt fullscreen mode?
            {
                    DEVMODE dmScreenSettings;                                       // Device mode
                    memset(&dmScreenSettings,0,sizeof(dmScreenSettings));                // Makes sure memory's cleared
                    dmScreenSettings.dmSize         = sizeof(dmScreenSettings);     // Size of the devmode structure
                    dmScreenSettings.dmPelsWidth        = width;                        // Selected screen width
                    dmScreenSettings.dmPelsHeight        = height;                       // Selected screen height
                    dmScreenSettings.dmBitsPerPel        = bits;                                // Selected bits per pixel
                    dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
    
                    // Try to set selected mode and get results. NOTE: CDS_FULLSCREEN gets rid of start bar.
                    if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
                    {
                            // If the mode fails, offer two options. Quit or use windowed mode.
                            if (MessageBox(NULL,"The requested fullscreen mode is not supported by\nyour video card. Use windowed mode instead?","Acjhtuig",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
                            {
                                    fullscreen = false;       // Windowed mode selected. Fullscreen = FALSE
                            }
                            else
                            {
                                    // Pop up a message box letting user know the program is closing.
                                    MessageBox(NULL,"Program will now close.","ERROR",MB_OK|MB_ICONSTOP);
                                    return false;           // Return FALSE
                            }
                    }
            }
    
            if (fullscreen)                         // Are We Still In Fullscreen Mode?
            {
                    dwExStyle = WS_EX_APPWINDOW;    // Window extended style
                    dwStyle = WS_POPUP;                // Windows style
                    ShowCursor(false);                // Hide mouse pointer
            }
            else
            {
                    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;           // Window extended style
                    dwStyle=WS_OVERLAPPEDWINDOW;                            // Windows style
            }
    
            AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);     // Adjust window to true requested size
    
            // Create the window
            if (!(hWnd = CreateWindowEx(dwExStyle,          // Extended Style For The Window
                    "OpenGL",                                // Class name
                    title,                                        // Window title
                    dwStyle |                                // Defined window style
                    WS_CLIPSIBLINGS |                        // Required window style
                    WS_CLIPCHILDREN,                        // Required window style
                    0, 0,                                        // Window position
                    WindowRect.right-WindowRect.left,        // Calculate window width
                    WindowRect.bottom-WindowRect.top,        // Calculate window height
                    NULL,                                        // No parent window
                    NULL,                                        // No menu
                    hInstance,                                // Instance
                    NULL)))                                        // Dont pass anything to WM_CREATE
            {
                    KillGLWindow();                         // Reset the display
                    MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;                           // Return FALSE
            }
    
            static        PIXELFORMATDESCRIPTOR pfd =             // pfd tells windows how we want things to be
            {
                    sizeof(PIXELFORMATDESCRIPTOR),          // Size of this pixel format descriptor
                    1,                                        // Version number
                    PFD_DRAW_TO_WINDOW |                        // Format must support window
                    PFD_SUPPORT_OPENGL |                        // Format must support OpenGL
                    PFD_DOUBLEBUFFER,                        // Must support double buffering
                    PFD_TYPE_RGBA,                                // Request an RGBA format
                    bits,                                        // Select our color depth
                    0, 0, 0, 0, 0, 0,                        // Color bits ignored
                    0,                                        // No alpha buffer
                    0,                                        // Shift bit ignored
                    0,                                        // No accumulation buffer
                    0, 0, 0, 0,                                // Accumulation bits ignored
                    16,                                        // 16Bit Z-Buffer (Depth buffer)
                    0,                                        // No stencil buffer
                    0,                                        // No auxiliary buffer
                    PFD_MAIN_PLANE,                                // Main drawing layer
                    0,                                        // Reserved
                    0, 0, 0                                        // Layer masks ignored
            };
    
            if (!(hDC=GetDC(hWnd)))         // Did we get a device context?
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Can't create a GL device context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))        // Did windows find a matching pixel format?
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Can't find a suitable pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            if(!SetPixelFormat(hDC,PixelFormat,&pfd))       // Are we able to set the pixel format?
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Can't set the pixelformat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            if (!(hRC=wglCreateContext(hDC)))               // Are we able to get a rendering context?
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Can't create a GL rendering context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            if(!wglMakeCurrent(hDC,hRC))    // Try to activate the rendering context
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Can't activate the GL rendering context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            ShowWindow(hWnd,SW_SHOW);       // Show the window
            SetForegroundWindow(hWnd);      // Slightly higher priority
            SetFocus(hWnd);                 // Sets keyboard focus to the window
            ReSizeGLScene(width, height);   // Set up our perspective GL screen
    
            if (!InitGL())                  // Initialize our newly created GL window
            {
                    KillGLWindow();         // Reset the display
                    MessageBox(NULL,"Initialization failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
                    return false;           // Return FALSE
            }
    
            return true;                    // Success
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd,     // Handle for this window
                            UINT uMsg,      // Message for this window
                            WPARAM wParam,  // Additional message information
                            LPARAM lParam)  // Additional message information
    {
            switch (uMsg)                           // Check for windows messages
            {
                    case WM_ACTIVATE:               // Watch for window activate message
                    {
                            if (!HIWORD(wParam))    // Check minimization state
                            {
                                    active = true;  // Program is active
                            }
                            else
                            {
                                    active = false; // Program is no longer active
                            }
    
                            return 0;               // Return to the message loop
                    }
    
                    case WM_SYSCOMMAND:             // Intercept system commands
                    {
                            switch (wParam)         // Check system calls
                            {
                                    case SC_SCREENSAVE:     // Screensaver trying to start?
                                    case SC_MONITORPOWER:        // Monitor trying to enter powersave?
                                    return 0;       // Prevent from happening
                            }
                            break;                  // Exit
                    }
    
                    case WM_CLOSE:                  // Did we receive a close message?
                    {
                            PostQuitMessage(0);     // Send a quit message
                            return 0;               // Jump back
                    }
    
                    case WM_KEYDOWN:                // Is a key being held down?
                    {
                            keys[wParam] = true;    // If so, mark it as TRUE
                            return 0;               // Jump back
                    }
    
                    case WM_KEYUP:                  // Has a key been released?
                    {
                            keys[wParam] = false;   // If so, mark it as FALSE
                            return 0;               // Jump back
                    }
    
                    case WM_SIZE:                   // Resize the OpenGL window
                    {
                            ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord = Width, HiWord = Height
                            return 0;               // Jump back
                    }
    
                    case WM_LBUTTONDOWN:
                    {
                            mouse_x = LOWORD(lParam);
                            mouse_y = HIWORD(lParam);
                            click_x = LOWORD(lParam);
                            click_y = HIWORD(lParam);
    
                            //if (recorder == true){
                            int iFileHandle;
                            int iLength;
                            iFileHandle = FileCreate("reinspeichertext3.txt");
                            FileWrite(iFileHandle, ausgabestr.c_str(), ausgabestr.Length());
                            FileClose(iFileHandle);
                            //}
                            getPolygon();
                    }
                    case WM_RBUTTONDOWN:
                    {
                            if (recorder == false) {
                            ausgabestr = ausgabestr + "\r\n\t+++NEU+++\r\n";
                            recorder = true;
                            }else {
                            recorder = false;
                            }
                    }
    
                    case WM_MOUSEMOVE:
                    {
                            //float WWidth = ((WindowRect.right - WindowRect.left)/2);
    
                            //mouse_x = LOWORD(lParam);
                            //float mo = (mouse_x - WWidth);
                            //heading -= mo/100;
                            //yrot = lastYrot;
                            //if(mouse_x--)  yrot -=  1.0f;
                            //mouse_y = HIWORD(lParam);
                    }
    
            }
    
            // Pass all unhandled messages to DefWindowProc
            return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    
    WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
            MSG msg;                // Windows message structure
            bool done = false;      // Bool variable to exit loop
    
            // Ask the user which screen mode they prefer
            if (MessageBox(NULL,"Would you like to run in fullscreen mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
            {
                    fullscreen = false;       // Windowed mode
            }
    
            // Create our OpenGL window
            if (!CreateGLWindow("The Worldt of Tomorrow",640,480,16,fullscreen))
            {
                    return 0;               // Quit if window was not created
            }
    
            while(!done)            // Loop that runs while done = FALSE
            {
                    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))        // Is there a message waiting?
                    {
                            if (msg.message == WM_QUIT)             // Have we received a quit message?
                            {
                                    done = true;                    // If so done = TRUE
                            }
                            else                                    // If not, deal with window messages
                            {
                                    TranslateMessage(&msg);         // Translate the message
                                    DispatchMessage(&msg);          // Dispatch the message
                            }
                    }
                    else            // If there are no messages
                    {
    
                            // Draw the scene.  Watch for ESC key and quit messages from DrawGLScene()
                            if ((active && !DrawGLScene()) || keys[VK_ESCAPE])        // Active?  Was there a quit received?
                            {
                                    done = true;                    // ESC or DrawGLScene signalled a quit
                            }
                            else                                    // Not time to quit, update screen
                            {
                                    SwapBuffers(hDC);               // Swap buffers (double buffering)
                                    if (keys['B'] && !bp)
                                    {
                                            bp = true;
                                            blend = !blend;
                                            if (!blend)
                                            {
                                                    glDisable(GL_BLEND);
                                                    glEnable(GL_DEPTH_TEST);
                                            }
                                            else
                                            {
                                                    glEnable(GL_BLEND);
                                                    glDisable(GL_DEPTH_TEST);
                                            }
                                    }
                                    if (!keys['B'])
                                    {
                                            bp = false;
                                    }
    
                                    if (keys['L'] && !lp)
                                    {
                                            lp=TRUE;
                                            light=!light;
                                            if (!light)
                                            {
                                                    glDisable(GL_LIGHTING);
                                            }
                                            else
                                            {
                                                    glEnable(GL_LIGHTING);
                                            }
                                    }
                                    if (!keys['L'])
                                    {
                                            lp = false;
                                    }
    
                                    if (!keys['B'])
                                    {
                                            bp = false;
                                    }
    
                                    if (keys['F'] && !fp)
                                    {
                                            fp = true;
                                            filter+=1;
                                            if (filter>2)
                                            {
                                                    filter=0;
                                            }
                                    }
                                    if (!keys['F'])
                                    {
                                            fp = false;
                                    }
    
                                    if (keys[VK_PRIOR])
                                    {
                                            z-=0.02f;
                                      }
    
                                  if (keys[VK_NEXT])
                                    {
                                            z+=0.02f;
                                    }
    
                                    if (keys['S'])
                                    {
                                            xpos = 0.0f;
                                            zpos = 8.0f;
                                            yrot = 0.0f;
                                    }
                                    if (keys['W'])
                                    {
                                            xpos = 0.0f;
                                            zpos = -8.0f;
                                            yrot = 180.0f;
                                    }
                                    if (keys['D'])
                                    {
                                            xpos = 8.0f;
                                            zpos = 0.0f;
                                            yrot = 90.0f;
                                    }
                                    if (keys['A'])
                                    {
                                            xpos = -8.0f;
                                            zpos = 0.0f;
                                            yrot = 270.0f;
                                    }
    
                                    if (keys['U'])
                                    {
                                            if(ebene < 0.0125f)
                                            ebene += 0.0125f;
                                    }
                                    if (keys['J'])
                                    {
                                            ebene -= 0.0125f;
                                    }
    
                                    if (keys[VK_UP] || keys[104])
                                    {
                                        if(xpos*(-1) > 1 && xpos*(-1) < 99 && zpos*(-1) > 0 && zpos*(-1) < 99){
                                            int N = terraVertIndex(xpos, zpos);
                                            float up = -getHeight(sector1, xpos, zpos, N, 0);
                                            if (up - terraUp > -0.03){
                                                oldTerraUp = terraUp;
                                                oldXpos = xpos;
                                                oldZpos = zpos;
                                                terraUp = up;
                                                xpos -= (float)sin(heading*piover180) * 0.05f;
                                                zpos -= (float)cos(heading*piover180) * 0.05f;
                                                /*if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f;
                                                else                           walkbiasangle+= 10;
                                                walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
                                                }*/
                                            }else{
                                                 terraUp = oldTerraUp;
                                                 xpos = oldXpos;
                                                 zpos = oldZpos;
                                            }
                                        }
    
                                    }
    
                                    if (keys[VK_DOWN] || keys[98])
                                    {
                                        if(xpos*(-1) > 1 && xpos*(-1) < 99 && zpos*(-1) > 0 && zpos*(-1) < 99){
                                            int N = terraVertIndex(xpos, zpos);
                                            terraUp = -getHeight(sector1, xpos, zpos, N, 0);
                                        }
                                            //scaleValue -= (float)sin(heading*piover180) * 0.05f;//Landscape //Highmapping
                                            xpos += (float)sin(heading*piover180) * 0.05f;
                                            zpos += (float)cos(heading*piover180) * 0.05f;
                                            /*if (walkbiasangle <= 1.0f)
                                            {
                                                    walkbiasangle = 359.0f;
                                            }
                                            else
                                            {
                                                    walkbiasangle-= 10;
                                            }
                                            walkbias = (float)sin(walkbiasangle * piover180)/20.0f; */
                                    }
    
                                    if (keys[VK_RIGHT] || keys[102])
                                    {
                                            heading -= 1.0f;
                                            yrot = heading;
                                    }
    
                                    if (keys[VK_LEFT] || keys[100])
                                    {
                                            heading += 1.0f;
                                            yrot = heading;
                                    }
    
                                    if (keys[103])
                                    {
                                            xpos += 0.02f;
                                            zpos -= 0.02f;
                                    }
    
                                    if (keys[105])
                                    {
                                            xpos -= 0.02f;
                                            zpos += 0.02f;
                                    }
    
                                    if (keys[101])    //Adere Positionen
                                    {
                                            xpos = -1.5f;
                                            zpos = 0.1f;
                                            yrot = 270.0f;
                                            walkbiasangle = 270.0f;
                                            walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
                                    }
    
                                    if (keys[VK_PRIOR])
                                    {
                                            lookupdown-= 1.0f;
                                    }
    
                                    if (keys[VK_NEXT])
                                    {
                                            lookupdown+= 1.0f;
                                    }
    
                                    if (keys[VK_F1])                        // Is F1 neing pressed?
                                    {
                                            keys[VK_F1] = false;                // If so make key FALSE
                                            KillGLWindow();                        // Kill our current window
                                            fullscreen = !fullscreen;        // Toggle fullscreen / windowed mode
                                            // Recreate our OpenGL window
                                            if (!CreateGLWindow("The Worldt of Tomorrow",640,480,16,fullscreen))
                                            {
                                                    return 0;       // Quit if window was not created
                                            }
                                    }
                            }
                    }
            }
    
            // Shutdown
            KillGLWindow();         // Kill the window
            glDeleteTextures(4,terraTexture[0]);
            delete &ausgabestr;
            delete &statusString;
            delete &sector1;
            delete &balls;
            return (msg.wParam);    // Exit the program
    }
    //---------------------------------------------------------------------------
    


  • Mehr!!

    Bye, TGGC (Demo or Die)



  • Gehts nicht genauer, was du wissen willst? ^^
    Is halt ein kleines WinAPI-Programm, dass OpenGL benutzt, und das noch nicht mal besonders gut.^^
    Ratefrage: Ich las da TBitmap, tippe also mal auf Borland C++ Builder^^



  • Was TGGC damit sagen will: Niemand, der keinen persönlichen Vorteil darin erkennen kann, den Code für dich zu verstehen, ließt sich das hier durch. Und solche Altruisten gibt es nur sehr selten. 😉


Anmelden zum Antworten