本文整理汇总了C++中Loader::LoadToVAO方法的典型用法代码示例。如果您正苦于以下问题:C++ Loader::LoadToVAO方法的具体用法?C++ Loader::LoadToVAO怎么用?C++ Loader::LoadToVAO使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Loader
的用法示例。
在下文中一共展示了Loader::LoadToVAO方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadObjModel
RawModel OBJLoader::LoadObjModel(const std::string& fileName, Loader& loader)
{
clock_t startTime = clock();
// Open the file as read only
FILE* file;
if (fopen_s(&file, ("../res/models/" + fileName + ".obj").c_str(), "r") != 0)
{
printf("Failed to open: %s\n", fileName);
}
// Storage variables
std::vector<glm::vec2> textures, tempTextures;
std::vector<glm::vec3> vertices, normals, tempNormals;
std::vector<int> indices;
char *type, *token, *stop = 0;
double x, y, z;
char line[256];
while (fgets(line, 256, file) != NULL)
{
token = NULL;
type = strtok_s(line, " ", &token);
// V is vertex points
if (type[0] == 'v' && type[1] == NULL)
{
x = strtod(token, &stop);
token = stop + 1; // Move to the next value
y = strtod(token, &stop);
token = stop + 1; // Move to the next value
z = strtod(token, &stop);
// Store a new vertex
vertices.push_back(glm::vec3(x, y, z));
}
// VT is vertex texture coordinates
else if (type[0] == 'v' && type[1] == 't')
{
x = strtod(token, &stop);
token = stop + 1; // Move to the next value
y = 1 - strtod(token, &stop);
// Store a new texture
tempTextures.push_back(glm::vec2(x, y));
}
else if (type[0] == 'v' && type[1] == 'n')
{
x = strtod(token, &stop);
token = stop + 1; // Move to the next value
y = strtod(token, &stop);
token = stop + 1; // Move to the next value
z = strtod(token, &stop);
// Store a new normal
tempNormals.push_back(glm::vec3(x, y, z));
}
// F is the index list for faces
else if (type[0] == 'f')
{
if (indices.size() == 0)
{
// Set the size of the array
textures.resize(vertices.size());
normals.resize(vertices.size());
}
// Process set of vertex data
ProcessVertices(token, indices, tempTextures, textures, tempNormals, normals);
}
}
fclose(file);
printf("Load time: %dms\n", clock() - startTime);
return loader.LoadToVAO(vertices, textures, normals, indices);
}
示例2: Start
//Game loop
void GameManager::Start(){
std::cout << "Game loop is now running.\n";
Loader loader;
StaticShader staticShader("basicShader");
Renderer renderer(staticShader, m_displayManager->GetAspect());
float vertices[] = {
// Front face
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// Back face
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
// Top face
-1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
// Bottom face
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, 1.0,
// Right face
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
// Left face
-1.0, -1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
-1.0, 1.0, -1.0
};
int indices[] = {
0, 1, 2, 0, 2, 3, // front
4, 5, 6, 4, 6, 7, // back
8, 9, 10, 8, 10, 11, // top
12, 13, 14, 12, 14, 15, // bottom
16, 17, 18, 16, 18, 19, // right
20, 21, 22, 20, 22, 23 // left
};
float texCoords[] = {
0, 0,
0, 1,
1, 1,
1, 0,
0, 0,
0, 1,
1, 1,
1, 0,
0, 0,
0, 1,
1, 1,
1, 0,
0, 0,
0, 1,
1, 1,
1, 0,
0, 0,
0, 1,
1, 1,
1, 0,
0, 0,
0, 1,
1, 1,
1, 0
};
//RawModel model = loader.LoadToVAO(vertices, sizeof(vertices) / sizeof(vertices[0]));
RawModel model = loader.LoadToVAO(vertices, indices, texCoords,
sizeof(vertices) / sizeof(vertices[0]),
sizeof(indices) / sizeof(indices[0]),
sizeof(texCoords) / sizeof(texCoords[0]));
ModelTexture texture(loader.LoadTexture("image"));
TexturedModel texturedModel(model, texture);
Entity entity(texturedModel,
glm::vec3(0, 0, -5), glm::vec3(0, 0, 0), glm::vec3(1, 1, 1)
);
Camera camera;
float x = -0.001f;
//.........这里部分代码省略.........