コード例 #1
0
ファイル: MS3D.cpp プロジェクト: GiR-Zippo/GWAN-Engine
void MS3D::reloadTextures()
{
    for ( int i = 0; i < m_numMaterials; i++ )
    {
        if ( strlen( m_pMaterials[i].m_pTextureFilename ) > 0 )
        {
            std::stringstream fn;
            std::string file = m_pMaterials[i].m_pTextureFilename;
            file = file.substr(0, file.length() - 4);
            fn << _path << file << ".png";
            TextureLoader *tload = new TextureLoader();
            m_pMaterials[i].m_texture = tload->LoadTexture( fn.str().c_str() );
            delete tload;
        }
        else
        {
            m_pMaterials[i].m_texture = 0;
        }
    }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: cdrofenik/neptunePhysics
int main() {

    DisplayManager displayManager(WINDOW_WIDTH, WINDOW_HEIGHT, "Neptune Physics Simulator");
    displayManager.Enable(GL_DEPTH_TEST);
    //displayManager.Enable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    //Input handling
    glfwSetInputMode(displayManager.getWindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
    glfwSetKeyCallback(displayManager.getWindow(), key_callback);
    glfwSetCursorPosCallback(displayManager.getWindow(), mouse_callback);

    //TODO: Add to camera setup
    glm::mat4 model;
    glm::mat4 view;
    glm::mat4 projection;
    projection = glm::perspective(45.0f, WINDOW_WIDTH / (float)WINDOW_HEIGHT, 0.1f, 100.0f);

    Renderer objRenderer;
    ObjectLoader objLoader;

    //Load Texture
    TextureLoader textLoader;
    GLuint textureId = textLoader.LoadTexture("..\\..\\external\\resources\\textures\\container.png");

    //Loading OBJ mesh
    auto meshRawModel = objLoader.LoadMesh("..\\..\\external\\resources\\objects\\suzanneSmall.obj");

    //Init physics system
    npDiscreteDynamicsWorld* world = new npDiscreteDynamicsWorld();
    initializeObjects(world, meshRawModel.minVector, meshRawModel.maxVector);

    Light staticLight;
    staticLight.position = glm::vec3(0.0f, 1.0f, 10.0f);
    staticLight.color = glm::vec3(1.0f, 1.0f, 1.0f);

    //Init Shaders
    ModelShader meshShader("shaders\\vertexShader.vert", "shaders\\fragmentShader.frag");
    ModelShader BVShader("shaders\\BVvertexShader.vert", "shaders\\BVfragmentShader.frag");

    while (!glfwWindowShouldClose(displayManager.getWindow()))
    {
        GLdouble currentFrame = glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;

        glfwPollEvents();
        gameCamera.ProcessKeyboard(keys, deltaTime);

        objRenderer.PrepareForRendering();

        if (!pauseSimulation) {
            world->stepSimulation(deltaTime);
        }
        
        for (size_t i = 0; i < 2; i++)
        {
            auto rigidBdy = world->getRigidBody(i);

            #ifdef _DEBUG
            if (!pauseSimulation) {
                Log_DEBUG("main.cpp - 197", "Body position:", rigidBdy.getPosition());
            }
            #endif

            npMatrix4 resultingModelMatrix = create4x4Matrix(rigidBdy.getTransformMatrix()).transpose();

            //drawableBV has VBOs (vertex, color)
            BVShader.Use();
            BVShader.LoadViewMatrix(gameCamera.GetViewMatrix());
            BVShader.LoadProjectionMatrix(projection);
            BVShader.LoadModelMatrix(resultingModelMatrix);
            objRenderer.Render(drawableModelList.at(i));
            BVShader.Stop();

            //meshRawModel has other VBOs (vertex, normal, texCoords)
            meshShader.Use();
            meshShader.LoadViewMatrix(gameCamera.GetViewMatrix());
            meshShader.LoadProjectionMatrix(projection);
            meshShader.LoadModelMatrix(resultingModelMatrix);
            meshShader.LoadLightPosition(staticLight.position);
            meshShader.LoadLightColor(staticLight.color);
            meshShader.LoadShineVariables(0.0f, 0.0f);
            textLoader.UseTexture(textureId, meshShader.getProgramID(), "ourTexture");
            objRenderer.Render(meshRawModel, wireFrameMode);
            meshShader.Stop();
        }

        displayManager.UpdateDisplay();
    }

    objLoader.CleanUp();
    textLoader.CleanUp();
    displayManager.CloseDisplay();

    return 1;
    
}