bool Model::Load(const char *filename) { Clear(); int format = FormatFromFilename(filename); bool rval = false; bool needToOptimize = true; switch (format) { case format_none: #ifdef MODEL_ENABLE_ASSIMP rval = LoadAssimp(filename); #endif break; case format_h3d: rval = LoadH3D(filename); needToOptimize = false; break; } if (!rval) return false; LoadPostProcess(needToOptimize); return true; }
void Model::Load_OBJ(){ SDL_Log( "\n" ); SDL_Log( "%s:", this->Name.c_str() ); /* //With LoadOBJ( ): this->Init = LoadOBJ( this->OBJPathFile.c_str(), this->Vertices, this->Uvs, this->Normals ); std::vector <glm::vec3> Vertices_tmp; std::vector <glm::vec2> Uvs_tmp; std::vector <glm::vec3> Normals_tmp; IndexVBO( this->Vertices, this->Uvs, this->Normals, this->Indices, Vertices_tmp, Uvs_tmp, Normals_tmp ); this->Vertices = Vertices_tmp; this->Uvs = Uvs_tmp; this->Normals = Normals_tmp; */ //faster //with Assimp: this->Init = LoadAssimp( this->OBJPathFile.c_str(), this->Vertices, this->Uvs, this->Normals, this->Indices ); this->SetCollision(); LoadMTL( this->MTLPathFile.c_str(), this->Ambient, this->Diffuse, this->Specular, this->Shininess ); if( this->Ambient.x == 0.0f and this->Ambient.y == 0.0f and this->Ambient.z == 0.0f ){ this->Ambient = glm::vec3( 0.2f ); } }
void InitializeResources() { printf("InitializeResources()\n"); // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units ProjectionMatrix = glm::perspective( 45.0f, // The horizontal Field of View, in degrees : the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in) 4.0f / 3.0f, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ? 0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues. 100.0f // Far clipping plane. Keep as little as possible. ); // Or, for an ortho camera : //glm::mat4 Projection = glm::ortho(-10.0f,10.0f,-10.0f,10.0f,0.0f,100.0f); // In world coordinates // Camera matrix ViewMatrix = glm::lookAt( cameraLoc, // Camera is cameraLoc, in World Space cameraDir, // and looks to cameraDir orientation // Head is orientation ); ModelMatrix = glm::mat4(1.0f); // Model matrix : an identity matrix (model will be at the origin) // Our ModelViewProjection : multiplication of our 3 matrices MVP = ProjectionMatrix * ViewMatrix * ModelMatrix; // Remember, matrix multiplication is the other way around //loads object bool res = LoadAssimp("Resources/cheb.obj", indices, vertices, uvs, normals); // index the vbo indices.clear(); indexVBO(vertices, uvs, normals, indices, indexed_vertices, indexed_uvs, indexed_normals); // Vertex Array Object and set it as the current one glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); // Create and compile our GLSL program from the shaders //ShaderIDs[0] = LoadShaders( "VertexShader.vs", "FragmentShader.fs" ); pickingProgramID = LoadShaders( "Picking.vertexshader", "Picking.fragmentshader" ); gprogramID = LoadShaders( "TransformVertexShader.vertexshader", "ColorFragmentShader.fragmentshader" ); ProgramID = LoadShaders( "VertexShader.vs", "FragmentShader.fs" ); ShaderIDs[0] = ProgramID; ProgramID = LoadShaders( "WireFrame_VertexShader.vs", "FragmentShader.fs" ); ShaderIDs[1] = ProgramID; // Get a handle for our uniforms MatrixID = glGetUniformLocation(ProgramID, "MVP"); ViewMatrixID = glGetUniformLocation(ProgramID, "V"); ModelMatrixID = glGetUniformLocation(ProgramID, "M"); NormalMatrixID = glGetUniformLocation(ProgramID, "NormalMatrix"); // Loads the texture Texture = loadDDS("Resources/purple.DDS"); // Sets the uniform for the texture sampler TextureID = glGetUniformLocation(ProgramID, "myTexturesampler"); // Generate a vertex buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // Give our vertices to OpenGL. glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(glm::vec3), &indexed_vertices[0], GL_STATIC_DRAW); // Generate a vertex buffer, put the resulting identifier in vertexbuffer glGenBuffers(1, &uvbuffer); // The following commands will talk about our 'uvbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); // Give our uv's to OpenGL. glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(glm::vec2), &indexed_uvs[0], GL_STATIC_DRAW); // Generate a normal buffer, put the resulting identifier in normalbuffer glGenBuffers(1, &normalbuffer); // The following commands will talk about our 'normalbuffer' buffer glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); // Give our normal's to OpenGL. glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(glm::vec3), &indexed_normals[0], GL_STATIC_DRAW); // Generate a index buffer, put the resulting identifier in elementbuffer glGenBuffers(1, &elementbuffer); // The following commands will talk about our 'elementbuffer' buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer); // Give our index's to OpenGL. glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned short), &indices[0], GL_STATIC_DRAW); // Use our shader glUseProgram(ShaderIDs[0]); LightPosID = glGetUniformLocation(ProgramID, "lightPos"); CameraID = glGetUniformLocation(ProgramID, "C"); gVertexArrayID; glGenVertexArrays(1, &gVertexArrayID); glBindVertexArray(gVertexArrayID); gvertexbuffer; glGenBuffers(1, &gvertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, gvertexbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); colorbuffer; glGenBuffers(1, &colorbuffer); glBindBuffer(GL_ARRAY_BUFFER, colorbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(g_color_buffer_data), g_color_buffer_data, GL_STATIC_DRAW); }
void Light::Load(){ SDL_Log( "\n" ); this->Init = LoadAssimp( this->OBJPathFile.c_str(), this->Vertices, this->Uvs, this->Normals, this->Indices ); this->BindVAO(); }