fix narrowing conversions (eg double to float, size_t to GLsizei)

This commit is contained in:
N. Pattakos
2022-01-07 23:13:19 +01:00
parent 47a6664845
commit 72f3e37150
59 changed files with 371 additions and 238 deletions

View File

@@ -146,8 +146,8 @@ int main()
glUseProgram(shaderProgram);
// update shader uniform
float timeValue = glfwGetTime();
float greenValue = sin(timeValue) / 2.0f + 0.5f;
auto timeValue = glfwGetTime();
auto greenValue = static_cast<GLfloat>(sin(timeValue) / 2.0 + 0.5);
int vertexColorLocation = glGetUniformLocation(shaderProgram, "ourColor");
glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f);

View File

@@ -184,7 +184,7 @@ int main()
// ---------------------
transform = glm::mat4(1.0f); // reset it to identity matrix
transform = glm::translate(transform, glm::vec3(-0.5f, 0.5f, 0.0f));
float scaleAmount = sin(glfwGetTime());
auto scaleAmount = static_cast<GLfloat>(sin(glfwGetTime()));
transform = glm::scale(transform, glm::vec3(scaleAmount, scaleAmount, scaleAmount));
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, &transform[0][0]); // this time take the matrix value array's first element as its memory pointer value

View File

@@ -222,8 +222,8 @@ int main()
// camera/view transformation
glm::mat4 view = glm::mat4(1.0f); // make sure to initialize matrix to identity matrix first
float radius = 10.0f;
float camX = sin(glfwGetTime()) * radius;
float camZ = cos(glfwGetTime()) * radius;
auto camX = static_cast<GLfloat>(sin(glfwGetTime()) * radius);
auto camZ = static_cast<GLfloat>(cos(glfwGetTime()) * radius);
view = glm::lookAt(glm::vec3(camX, 0.0f, camZ), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
ourShader.setMat4("view", view);

View File

@@ -212,7 +212,7 @@ int main()
{
// per-frame time logic
// --------------------
float currentFrame = glfwGetTime();
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
@@ -276,7 +276,7 @@ void processInput(GLFWwindow *window)
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
float cameraSpeed = 2.5 * deltaTime;
auto cameraSpeed = static_cast<GLfloat>(2.5 * deltaTime);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
cameraPos += cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)

View File

@@ -221,7 +221,7 @@ int main()
{
// per-frame time logic
// --------------------
float currentFrame = glfwGetTime();
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
@@ -289,7 +289,7 @@ void processInput(GLFWwindow *window)
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
float cameraSpeed = 2.5 * deltaTime;
auto cameraSpeed = static_cast<GLfloat>(2.5 * deltaTime);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
cameraPos += cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
@@ -311,8 +311,11 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
{
auto xpos = static_cast<GLfloat>(xposIn);
auto ypos = static_cast<GLfloat>(yposIn);
if (firstMouse)
{
lastX = xpos;

View File

@@ -216,7 +216,7 @@ int main()
{
// per-frame time logic
// --------------------
float currentFrame = glfwGetTime();
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
@@ -306,8 +306,11 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
void mouse_callback(GLFWwindow* window, double xposIn, double yposIn)
{
auto xpos = static_cast<GLfloat>(xposIn);
auto ypos = static_cast<GLfloat>(yposIn);
if (firstMouse)
{
lastX = xpos;
@@ -328,5 +331,5 @@ void mouse_callback(GLFWwindow* window, double xpos, double ypos)
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(yoffset);
camera.ProcessMouseScroll(static_cast<GLfloat>(yoffset));
}