Пример #1
0
  void save(gloost::Matrix& m, const char* path){
    FILE* f = fopen(path, "wb");
#ifdef GLOOST_SYSTEM_MATH_WITH_FLOAT
    fwrite(m.data(), sizeof(float), 16, f);
#else
    fwrite(m.data(), sizeof(double), 16, f);
#endif
  }
Пример #2
0
  void load(gloost::Matrix& m, const char* path){
    FILE* f = fopen(path, "rb");
    if(NULL == f)
      return;
#ifdef GLOOST_SYSTEM_MATH_WITH_FLOAT
    fread(m.data(), sizeof(float), 16, f);
#else
    fread(m.data(), sizeof(double), 16, f);
#endif
  }
Пример #3
0
//Initialisierungsfunktion
void Initialize(int argc, char* argv[])
{
    GLenum GlewInitResult;//neue Variable vom Typ GLenum (um GLEW initialisation zu prüfen)

    //initialisiert das anzeige-Window
    InitWindow(argc, argv);

    glewExperimental = GL_TRUE;//GLEW erhät Informationen zu den Erweiterungen des Grafiktreibers
    GlewInitResult = glewInit();//initialisieren von GLEW

    //Überprüfen, ob GLEW Initialisierung erfolgreich, wenn nicht wird ein Error geworfen und Programm beendet
    if (GLEW_OK != GlewInitResult)
    {
        fprintf(
            stderr,
            "ERROR: %s\n",
            glewGetErrorString(GlewInitResult)
        );
        glutExit();
    }

    //Ausgabe der OpenGL Version
    fprintf(
        stdout,
        "INFO: OpenGL Version: %s\n",
        glGetString(GL_VERSION)
    );

    glGetError();//gibt Fehlerinformationen aus
    glClearColor(0.20f, 0.2f, 0.2f, 0.0f); //setzt die Farbe, mit der die Buffer gecleart werden (Parameter bezüglich GLUT_RGBA)

    glEnable(GL_DEPTH_TEST);//aktiviert: Tiefenvergleiche und update des Tiefenbuffers (Wenn nicht aktiviert: kein tiefenvergleich, selbst mit aktiviertem Tiefenbuffer)
    glDepthFunc(GL_LESS);//Spezifiziert die Variable, die für den Tiefenbuffer genutzt wird (in diesem Fall: wenn Übergebene Tiefenvariable kleiner(Less) als die gespeicherte ist)

    ModelViewMatrixStack.loadIdentity();//setzt die aktuelle Matrix als Identitätsmatrix
    ProjectionMatrix.setIdentity();//setzt die Projektionsmatrix als Identitätsmatrix
    SetupShader();//Lädt und linked die shader
    LoadModel();//Lädt modelle
    loadTextures();//texturen laden
    initParticleSystem();//initialize particle system
    std::cout<<"\nChange Shader:\n"<<
             "1 - simple Shader\n"<<
             "2 - phong Shader\n"<<
             "\n"<<
             "Particle System:\n"<<
             "y - decrease maximum Lifetime of the particles\n"<<
             "x - increase maximum Lifetime of the particles\n"<<
             "\n"<<
             "c - decrease color alpha\n"<<
             "v - increase color alpha\n"<<
             "\n"<<
             "b - decrease particle count\n"<<
             "n - increase particle count\n"<<
             "\n"<<
             "o - increase comet speed\n"<<
             "l - decrease comet speed\n";
}
Пример #4
0
//Funktion um die Größe des Windows anzupassen (jedes mal wenn die Window-Größe angepasst wird, wird die Windowsize angepasst)
void ResizeFunction(int Width, int Height)
{
    //neue Größen
    CurrentWidth = Width;
    CurrentHeight = Height;
    //angabe der neuen Bildebene - parameter 1 und 2 sind Koordinate für linke untere Ecke der Bildebene, die anderen beiden sind Breite und Höhe der Ebene
    glViewport(0, 0, CurrentWidth, CurrentHeight);

    //Perpektive
    gloost::gloostPerspective(ProjectionMatrix,
                              60.0f,
                              (float)CurrentWidth / CurrentHeight,
                              1.0f,
                              100.0f
                             );

    glUseProgram(ShaderIds[0]);//Programm Objekt als Teil des Renderstates
    glUniformMatrix4fv(ProjectionMatrixUniformLocation[shadingModel], 1, GL_FALSE, ProjectionMatrix.data());//Setzt Wert der Variablen des Objektes
    glUseProgram(0);
}
Пример #5
0
//called every frame this functions draw
void Draw(void)
{
    int now = glutGet(GLUT_ELAPSED_TIME);

    // Rotation
    float rotation = now*0.001;


    //////////////////////////////////////////////////////////////////////////



    gloost::Matrix cameraTransform;
    cameraTransform.setIdentity();
    //cameraTransform.setRotateX(-0.38);
    cameraTransform.setTranslate(0.0,0.0,10.0);
    cameraTransform.invert();

    //reset the modelmatrix
    ModelViewMatrixStack.clear();
    ModelViewMatrixStack.loadMatrix(cameraTransform);

    gloost::Matrix normalMatrix;

    //Schleife für 8 Objekte
    for(int i=0; i<11; ++i)
    {
        //save the current transformation onto the MatrixStack
        ModelViewMatrixStack.push();
        switch (i)
        {
        case(0):
            //Sonne - no transformation
            //ModelViewMatrixStack.rotate(rotation,0.0,1.0,0.0);
            //ModelViewMatrixStack.scale(8);
            break;
        case(1):
            //Merkur
            ModelViewMatrixStack.rotate(rotation*2,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(1.0,0.0,0.0);
            ModelViewMatrixStack.scale(0.45);
            break;
        case(2):
            //Venus
            ModelViewMatrixStack.rotate(rotation*3,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(2.15,0.0,0.0);
            ModelViewMatrixStack.scale(0.4);
            break;
        case(3):
            //Erde
            ModelViewMatrixStack.rotate(-rotation*2.3,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(-3.1,0.0,0.0);
            ModelViewMatrixStack.scale(0.4);

            //um bumpmapping zu prüfen, nur diese transformationen für die erde zulassen:
            /*ModelViewMatrixStack.translate(0.0,0.0,8.5);
            ModelViewMatrixStack.rotate(-rotation*0.1,0.0,1.0,0.0);
            ModelViewMatrixStack.scale(1);*/
            break;
        case(4):
            //Erde-mond
            ModelViewMatrixStack.rotate(-rotation*2.3,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(-3.1,0.0,0.0);
            ModelViewMatrixStack.rotate(-rotation*7,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(0.45,0.0,0.0);
            ModelViewMatrixStack.scale(0.2);
            break;
        case(5):
            //Mars
            ModelViewMatrixStack.rotate(rotation*1.5,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(4.3,0.0,0.0);
            ModelViewMatrixStack.scale(0.6);
            break;
        case(6):
            //Jupiter
            ModelViewMatrixStack.rotate(-rotation*0.5,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(5.8,0.0,0.0);
            ModelViewMatrixStack.scale(0.8);
            break;
        case(7):
            //Saturn
            ModelViewMatrixStack.rotate(-rotation*0.2,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(7.3,0.0,0.0);
            ModelViewMatrixStack.scale(0.5);
            break;
        case(8):
            //Jupiter-Titan
            ModelViewMatrixStack.rotate(-rotation*0.5,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(5.8,0.0,0.0);
            ModelViewMatrixStack.rotate(rotation*2.33,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(0.6,0.0,0.0);
            ModelViewMatrixStack.scale(0.2);
            break;
        case(9):
            //Saturn-ring
            ModelViewMatrixStack.rotate(-rotation*0.2,0.0,1.0,0.0);
            ModelViewMatrixStack.translate(7.3,0.0,0.0);
            ModelViewMatrixStack.rotate(0.4,1.0,0.0,0.0);
            ModelViewMatrixStack.scale(1.5,0.01,1.5);
            break;
        case(10):
            //Komet
            ModelViewMatrixStack.rotate(rotation*0.2*cometSpeedMul,0.0,1.0,0.0);
            /*ModelViewMatrixStack.translate(8.0,0.0,0.0);
            ModelViewMatrixStack.scale(0.2);*/
            ModelViewMatrixStack.translate(0.0,0.0,8.5);
            //ModelViewMatrixStack.rotate(-rotation*0.1,0.0,1.0,0.0);
            ModelViewMatrixStack.scale(0.2);
            break;
        default:
            break;
        }
        {
            if(shadingModel == 0) {
                glUseProgram(ShaderIds[0]);
            }
            else
            {
                glUseProgram(ShaderIds[3]);
            }

            // transfer ModelViewMatrix for Geometry 1 to Shaders
            glUniformMatrix4fv(ModelViewMatrixUniformLocation[shadingModel], 1, GL_FALSE, ModelViewMatrixStack.top().data());

            //set the NormalMatrix for Geometry 1
            normalMatrix = ModelViewMatrixStack.top();

            normalMatrix.invert();
            normalMatrix.transpose();

            // transfer NormalMatrix for Geometry 1 to Shaders
            glUniformMatrix4fv(NormalMatrixUniformLocation[shadingModel], 1, GL_FALSE, normalMatrix.data());

            glUniformMatrix4fv(ProjectionMatrixUniformLocation[shadingModel], 1, GL_FALSE, ProjectionMatrix.data());

            //bind the Geometry
            glBindVertexArray(BufferIds[0]);

            //texuren aktivieren
            glEnable(GL_TEXTURE_2D);
            glActiveTexture(GL_TEXTURE0);
            //location bekannt machen
            glUniform1i(textureUniformLocation[shadingModel],0);
            //textur binden
            glBindTexture(GL_TEXTURE_2D,textures[i]);

            //Planet3 (erde) hat normalmap
            if(i == 3) {
                glActiveTexture(GL_TEXTURE1);
                glUniform1i(bumpmapUniformLocation,1);
                glBindTexture(GL_TEXTURE_2D,textures[12]);
            }
            else {
                glActiveTexture(GL_TEXTURE1);
                glUniform1i(bumpmapUniformLocation,1);
                glBindTexture(GL_TEXTURE_2D,0);
            }

            // draw Geometry 1
            //if(i != 10)//nur um partikel im kometen zu sehen
            glDrawElements(GL_TRIANGLES, mesh->getTriangles().size()*3, GL_UNSIGNED_INT, 0);
        }

        //##################particles#####################
        if(i == 10) { //nur beim Kometen zeichnen
            glUseProgram(ShaderIds[6]); //activate the particle shader Programm
            //deklarate the uniform data
            glUniformMatrix4fv(ModelViewMatrixUniformLocation[2],1,GL_FALSE,ModelViewMatrixStack.top().data());
            glUniformMatrix4fv(ProjectionMatrixUniformLocation[2],1,GL_FALSE,ProjectionMatrix.data());
            glUniform4f(particleColUniformLocation,particleCol.r,particleCol.g,particleCol.b,particleCol.a);
            glUniform1i(particleLifetimeUniformLocation,particleLifetime);

            glBindVertexArray(VertexArrayIds[0]); //bind the VAO

            //****FeedbackBuffer befüllen start****
            glEnable(GL_RASTERIZER_DISCARD);
            glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, VertexArrayIds[2]); //Feedbackbuffer ist VertexArrayIds[2]
            glBeginTransformFeedback(GL_POINTS);
            glDrawArrays(GL_POINTS, 0, particleCount);
            glEndTransformFeedback();
            glFlush();
            glDisable(GL_RASTERIZER_DISCARD);
            ///****FeedbackBuffer befüllen ende****

            Particle shaderFeedback[maxParticleCount]; //Feedback Array anlegen

            glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(shaderFeedback), shaderFeedback); //feedback data in das array legen

            //std::cout<<shaderFeedback[1].x<<" "<<shaderFeedback[1].y<<" "<<shaderFeedback[1].z<<" "<<shaderFeedback[1].w<<" "<<shaderFeedback[1].age<<std::endl;

            glBindVertexArray(VertexArrayIds[1]); //DataBuffer binden
            glBufferData(GL_ARRAY_BUFFER, sizeof(shaderFeedback), shaderFeedback, GL_STATIC_DRAW); //DataBuffer mit Feedback Daten befüllen


            glEnable(GL_BLEND); //Blending aktivieren
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Blending Funktion setzen
            glDrawArrays(GL_POINTS, 0, particleCount); //Particles Zeichnen
            glDisable(GL_BLEND); //Blending deaktivieren
        }
        //###########################################################
        //load last transformation from stack
        ModelViewMatrixStack.pop();
    }

    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);
    glUseProgram(ShaderIds[3]);
    glBindVertexArray(BufferIds[0]);
    //skybox

    ModelViewMatrixStack.push();
    ModelViewMatrixStack.scale(100);


    glUniformMatrix4fv(ModelViewMatrixUniformLocation[shadingModel], 1, GL_FALSE, ModelViewMatrixStack.top().data());

    //set the NormalMatrix for Geometry 1
    normalMatrix = ModelViewMatrixStack.top();

    normalMatrix.invert();
    normalMatrix.transpose();

    // transfer NormalMatrix for Geometry 1 to Shaders
    glUniformMatrix4fv(NormalMatrixUniformLocation[shadingModel], 1, GL_FALSE, normalMatrix.data());

    glUniformMatrix4fv(ProjectionMatrixUniformLocation[shadingModel], 1, GL_FALSE, ProjectionMatrix.data());

    //bind the Geometry
    glBindVertexArray(BufferIds[1]);

    glEnable(GL_TEXTURE_2D);
    glActiveTexture(GL_TEXTURE0);
    glUniform1i(textureUniformLocation[shadingModel],0);
    glBindTexture(GL_TEXTURE_2D,textures[11]);

    // draw skybox
    glDrawElements(GL_TRIANGLES,mesh2->getTriangles().size()*3, GL_UNSIGNED_INT, 0);


    ModelViewMatrixStack.pop();


    //the next transformation will be relative to bunny 1
    glBindVertexArray(0);
    glUseProgram(0);

}