Ejemplo n.º 1
0
Mesh* Assets::getMesh(std::string fileName)
{
	if(fileName == "") return nullptr;

	Assets* ins = Assets::get(); // get instance

	// Primitive meshes
	if(fileName == "triangle") return ins->_primitives.getMesh(PrimitiveShapes::TRIANGLE);
	if(fileName == "cube") return ins->_primitives.getMesh(PrimitiveShapes::CUBE);
	if(fileName == "sphere") return ins->_primitives.getMesh(PrimitiveShapes::SPHERE);


	std::map<std::string, Mesh*>::iterator it;
	it = ins->_meshes.find(fileName);
	
	if(it != ins->_meshes.end()) // then it found it!
	{
		return it->second;
	}
	else // try to load it!
	{
		Mesh* newMesh = nullptr;
		std::string filePath = ASSETS_PATH + "models/" + fileName;
		newMesh = loadMeshFromFile(filePath);
		if(newMesh == nullptr)
		{
			std::cout << "Failed to load " << fileName << " model\n";
			return nullptr;
		}
		
		// Add texture to map and return
		ins->_meshes.emplace(fileName, newMesh);
		newMesh->setFilePath(fileName);
		return newMesh;
	}
}
Ejemplo n.º 2
0
DockWidget3DSettings::DockWidget3DSettings(QWidget *parent, GLWidget* ptr_gl) :
    QDockWidget(parent),ptr_glWidget(ptr_gl),
    ui(new Ui::DockWidget3DSettings)
{
    ui->setupUi(this);
    close();
    setContentsMargins(0,0,0,0);

    // Connect all the sliders and other widgets
    connect(ui->horizontalSliderDepthScale ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderUVScale    ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderUVXOffset  ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderUVYOffset  ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));

    connect(ui->horizontalSliderSpecularI     ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderDiffuseI      ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderLightPower    ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));
    connect(ui->horizontalSliderLightRadius   ,SIGNAL(valueChanged(int)),this,SLOT(updateSettings(int)));

    connect(ui->comboBoxPerformanceNoRays     ,SIGNAL(activated(int)),this,SLOT(updateSettings(int)));
    connect(ui->comboBoxPerformanceNoTessSub  ,SIGNAL(activated(int)),this,SLOT(updateSettings(int)));
    connect(ui->checkBoxPerformanceCullFace   ,SIGNAL(clicked()),this,SLOT(updateSettings()));
    connect(ui->checkBoxPerformanceSimplePBR  ,SIGNAL(clicked()),this,SLOT(updateSettings()));
    connect(ui->checkBoxBloomEffect           ,SIGNAL(clicked()),this,SLOT(updateSettings()));
    connect(ui->checkBoxDOFEffect             ,SIGNAL(clicked()),this,SLOT(updateSettings()));
    connect(ui->checkBoxLensFlaresEffect      ,SIGNAL(clicked()),this,SLOT(updateSettings()));
    connect(ui->checkBoxShowTriangleEdges     ,SIGNAL(clicked()),this,SLOT(updateSettings()));

    connect(ui->comboBoxShadingModel          ,SIGNAL(activated(int)),    this,SLOT(selectShadingModel(int)));
    connect(ui->comboBoxShadingType           ,SIGNAL(activated(int)),    this,SLOT(updateSettings(int)));

    // loading 3d mesh signal and eviromental maps
    connect(ui->pushButtonLoadMesh            ,SIGNAL(released()),        ptr_glWidget,SLOT(loadMeshFromFile()));
    connect(ui->comboBoxChooseOBJModel        ,SIGNAL(activated(QString)),ptr_glWidget,SLOT(chooseMeshFile(QString)));
    connect(ui->comboBoxSkyBox                ,SIGNAL(activated(QString)),ptr_glWidget,SLOT(chooseSkyBox(QString)));


    // send current settings to glWidget
    connect(this,SIGNAL(signalSettingsChanged(Display3DSettings)),ptr_glWidget,SLOT(updatePerformanceSettings(Display3DSettings)));
    // ------------------------------------------------------- //
    //               Loading cub maps folders
    // ------------------------------------------------------- //
    qDebug() << "Loading cubemaps folders:";
    QDir currentDir(_find_data_dir(QString(RESOURCE_BASE) + "Core/2D/skyboxes"));
    currentDir.setFilter(QDir::Dirs);
    QStringList entries = currentDir.entryList();
    qDebug() << "Looking for enviromental maps in Core/2D/skyboxes:";
    for( QStringList::ConstIterator entry=entries.begin(); entry!=entries.end(); ++entry ){
        QString dirname=*entry;
        if(dirname != tr(".") && dirname != tr("..")){
            qDebug() << "Enviromental map:" << dirname;
            ui->comboBoxSkyBox->addItem(dirname);
        }
    }// end of for
    // setting cube map for glWidget
    ptr_glWidget->chooseSkyBox(ui->comboBoxSkyBox->currentText(),true);

}
Ejemplo n.º 3
0
// setup
int main(int argc, char *argv[])
{
    GLenum err = 0;
    /*********************************************
     * GLFW SETUP
     *********************************************/
    err = glfwInit();
    if (!err)
    {
        fputs("Failed to load the GLFW library", stderr);
        exit(EXIT_FAILURE);
    }

    /*********************************************
     * STATE SETUP (initialize gl context)
     *********************************************/
    // must be setup before glew so that a valid openGL
    // context exists (created with the window)

    w_state = new WorldState();
    c_state.init(*w_state);

    /*********************************************
     * GLEW SETUP
     *********************************************/
    err = glewInit();
    if (err != GLEW_OK)
    {
        fputs("Failed to initialize the GLEW library", stderr);
        exit(EXIT_FAILURE);
    }

    /*********************************************
     * STATE SETUP (construct render states)
     *********************************************/
    // must be setup after glew so that GL array
    // objects exist

    r_state[0] = new RenderState(3);
    r_state[1] = new RenderState(3);

    /*********************************************
     * SHADER SETUP
     *********************************************/
    // read default shaders from file
    GLuint shaderProgram[2] = {0};
    GLuint shaders[2] = {0};

    buildShader(GL_VERTEX_SHADER, "default.vs.glsl", shaders[0]);
    buildShader(GL_FRAGMENT_SHADER, "default.fs.glsl", shaders[1]);

    // create default shader program
    shaderProgram[0] = buildProgram(2, shaders);

    // bind shader program
    w_state->setProgram(0, shaderProgram[0]);
    w_state->useProgram(0);

    // setup the transform matrices and uniform variables
    w_state->loadTransforms();
    w_state->loadLights();
    w_state->loadMaterials();

    /*********************************************
     * LOAD MESH
     *********************************************/
    
    g_mesh = loadMeshFromFile(*r_state[0], "Mesh/arma.obj");

    /*********************************************
     * SET GL STATE
     *********************************************/ 
    glEnable(GL_DEPTH_TEST);

    /*********************************************
     * RENDER LOOP
     *********************************************/
    glfwSetTime(0.0);
    while (!glfwWindowShouldClose(c_state.window))
        display();

    /*********************************************
     * CLEAN UP
     *********************************************/
    delete g_mesh;
    glfwTerminate();

    exit(EXIT_SUCCESS);
}