本文整理汇总了C++中model::loadFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ model::loadFromFile方法的具体用法?C++ model::loadFromFile怎么用?C++ model::loadFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model
的用法示例。
在下文中一共展示了model::loadFromFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
bool initialize()
{
// Initialize basic geometry and shaders for this example
std::vector<unsigned short> faces;
std::vector<glm::vec3> vertices;
std::vector<glm::vec2> texCoords;
// Read our .obj file
sun.loadFromFile("../bin/nonPlanets/sun.txt");
models[0].loadFromFile("../bin/planetInfo/mercury.txt");
models[1].loadFromFile("../bin/planetInfo/venus.txt");
models[2].loadFromFile("../bin/planetInfo/earth.txt");
models[3].loadFromFile("../bin/planetInfo/mars.txt");
models[4].loadFromFile("../bin/planetInfo/jupiter.txt");
models[5].loadFromFile("../bin/planetInfo/saturn.txt");
models[6].loadFromFile("../bin/planetInfo/uranus.txt");
models[7].loadFromFile("../bin/planetInfo/neptune.txt");
models[8].loadFromFile("../bin/planetInfo/pluto.txt");
//--Geometry done
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
//Set shader char pointers
shaderLoader x;
const char *vs = x.load("../bin/vertexShader.vert");
const char *fs = x.load("../bin/fragmentShader.frag");
//compile the shaders
GLint shader_status;
// Vertex shader first
glShaderSource(vertex_shader, 1, &vs, NULL);
glCompileShader(vertex_shader);
//check the compile status
glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &shader_status);
if(!shader_status)
{
std::cerr << "[F] FAILED TO COMPILE VERTEX SHADER!" << std::endl;
return false;
}
// Now the Fragment shader
glShaderSource(fragment_shader, 1, &fs, NULL);
glCompileShader(fragment_shader);
//check the compile status
glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &shader_status);
if(!shader_status)
{
std::cerr << "[F] FAILED TO COMPILE FRAGMENT SHADER!" << std::endl;
return false;
}
//Now we link the 2 shader objects into a program
//This program is what is run on the GPU
program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
//check if everything linked ok
glGetProgramiv(program, GL_LINK_STATUS, &shader_status);
//this defines a cube, this is why a model loadfer is nice
loc_position = glGetAttribLocation(program,
const_cast<const char*>("v_position"));
if(loc_position == -1)
{
std::cerr << "[F] POSITION NOT FOUND" << std::endl;
return false;
}
loc_tex = glGetAttribLocation(program,
const_cast<const char*>("_texcoord"));
if(loc_tex == -1)
{
std::cerr << "[F] TEXTURE CORD. NOT FOUND" << std::endl;
return false;
}
loc_mvpmat = glGetUniformLocation(program,
const_cast<const char*>("mvpMatrix"));
if(loc_mvpmat == -1)
{
std::cerr << "[F] MVPMATRIX NOT FOUND" << std::endl;
return false;
}
loc_texc = glGetUniformLocation(program,
const_cast<const char*>("sampler"));
if(loc_tex == -1)
{
std::cerr << "[F] TEXTURE SAMPLER NOT FOUND" << std::endl;
//.........这里部分代码省略.........