| 39 | TeapotRenderer::~TeapotRenderer() { Unload(); } |
| 40 | |
| 41 | void TeapotRenderer::Init() { |
| 42 | // Settings |
| 43 | glFrontFace(GL_CCW); |
| 44 | |
| 45 | // Load shader |
| 46 | GLint type = GetTextureType(); |
| 47 | if (type == GL_TEXTURE_CUBE_MAP) { |
| 48 | LoadShaders(&shader_param_, "Shaders/Cubemap.vsh", "Shaders/Cubemap.fsh"); |
| 49 | } else if (type == GL_TEXTURE_2D) { |
| 50 | LoadShaders(&shader_param_, "Shaders/2DTexture.vsh", |
| 51 | "Shaders/2DTexture.fsh"); |
| 52 | } else { |
| 53 | LoadShaders(&shader_param_, "Shaders/VS_ShaderPlain.vsh", |
| 54 | "Shaders/ShaderPlain.fsh"); |
| 55 | } |
| 56 | // Create Index buffer |
| 57 | num_indices_ = sizeof(teapotIndices) / sizeof(teapotIndices[0]); |
| 58 | glGenBuffers(1, &ibo_); |
| 59 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_); |
| 60 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(teapotIndices), teapotIndices, |
| 61 | GL_STATIC_DRAW); |
| 62 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 63 | |
| 64 | // Create VBO |
| 65 | num_vertices_ = sizeof(teapotPositions) / sizeof(teapotPositions[0]) / 3; |
| 66 | int32_t stride = sizeof(TEAPOT_VERTEX); |
| 67 | int32_t index = 0; |
| 68 | TEAPOT_VERTEX* p = new TEAPOT_VERTEX[num_vertices_]; |
| 69 | for (int32_t i = 0; i < num_vertices_; ++i) { |
| 70 | p[i].pos[0] = teapotPositions[index]; |
| 71 | p[i].pos[1] = teapotPositions[index + 1]; |
| 72 | p[i].pos[2] = teapotPositions[index + 2]; |
| 73 | |
| 74 | p[i].normal[0] = teapotNormals[index]; |
| 75 | p[i].normal[1] = teapotNormals[index + 1]; |
| 76 | p[i].normal[2] = teapotNormals[index + 2]; |
| 77 | index += 3; |
| 78 | } |
| 79 | glGenBuffers(1, &vbo_); |
| 80 | glBindBuffer(GL_ARRAY_BUFFER, vbo_); |
| 81 | glBufferData(GL_ARRAY_BUFFER, stride * num_vertices_, p, GL_STATIC_DRAW); |
| 82 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 83 | |
| 84 | delete[] p; |
| 85 | |
| 86 | UpdateViewport(); |
| 87 | mat_model_ = ndk_helper::Mat4::Translation(0, 0, -15.f); |
| 88 | |
| 89 | ndk_helper::Mat4 mat = ndk_helper::Mat4::RotationX(M_PI / 3); |
| 90 | mat_model_ = mat * mat_model_; |
| 91 | } |
| 92 | |
| 93 | void TeapotRenderer::UpdateViewport() { |
| 94 | // Init Projection matrices |
no outgoing calls
no test coverage detected