mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
fix narrowing conversions (eg double to float, size_t to GLsizei)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user