MCPcopy Create free account
hub / github.com/VictorGordan/opengl-tutorials / Draw

Method Draw

YoutubeOpenGL 27 - Normal Maps/Mesh.cpp:26–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26void Mesh::Draw
27(
28 Shader& shader,
29 Camera& camera,
30 glm::mat4 matrix,
31 glm::vec3 translation,
32 glm::quat rotation,
33 glm::vec3 scale
34)
35{
36 // Bind shader to be able to access uniforms
37 shader.Activate();
38 VAO.Bind();
39
40 // Keep track of how many of each type of textures we have
41 unsigned int numDiffuse = 0;
42 unsigned int numSpecular = 0;
43
44 for (unsigned int i = 0; i < textures.size(); i++)
45 {
46 std::string num;
47 std::string type = textures[i].type;
48 if (type == "diffuse")
49 {
50 num = std::to_string(numDiffuse++);
51 }
52 else if (type == "specular")
53 {
54 num = std::to_string(numSpecular++);
55 }
56 textures[i].texUnit(shader, (type + num).c_str(), i);
57 textures[i].Bind();
58 }
59 // Take care of the camera Matrix
60 glUniform3f(glGetUniformLocation(shader.ID, "camPos"), camera.Position.x, camera.Position.y, camera.Position.z);
61 camera.Matrix(shader, "camMatrix");
62
63 // Initialize matrices
64 glm::mat4 trans = glm::mat4(1.0f);
65 glm::mat4 rot = glm::mat4(1.0f);
66 glm::mat4 sca = glm::mat4(1.0f);
67
68 // Transform the matrices to their correct form
69 trans = glm::translate(trans, translation);
70 rot = glm::mat4_cast(rotation);
71 sca = glm::scale(sca, scale);
72
73 // Push the matrices to the vertex shader
74 glUniformMatrix4fv(glGetUniformLocation(shader.ID, "translation"), 1, GL_FALSE, glm::value_ptr(trans));
75 glUniformMatrix4fv(glGetUniformLocation(shader.ID, "rotation"), 1, GL_FALSE, glm::value_ptr(rot));
76 glUniformMatrix4fv(glGetUniformLocation(shader.ID, "scale"), 1, GL_FALSE, glm::value_ptr(sca));
77 glUniformMatrix4fv(glGetUniformLocation(shader.ID, "model"), 1, GL_FALSE, glm::value_ptr(matrix));
78
79 // Draw the actual mesh
80 glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
81}

Callers 1

mainFunction · 0.45

Calls 8

mat4Class · 0.85
scaleFunction · 0.85
ActivateMethod · 0.45
BindMethod · 0.45
sizeMethod · 0.45
texUnitMethod · 0.45
c_strMethod · 0.45
MatrixMethod · 0.45

Tested by

no test coverage detected