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:
@@ -115,7 +115,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -213,8 +213,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;
|
||||
@@ -235,13 +238,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -259,7 +262,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -297,7 +300,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
@@ -120,7 +120,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -224,8 +224,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;
|
||||
@@ -246,13 +249,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -270,7 +273,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -308,7 +311,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
@@ -214,7 +214,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -329,8 +329,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;
|
||||
@@ -351,13 +354,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -375,7 +378,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -413,7 +416,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
@@ -255,7 +255,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -369,8 +369,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;
|
||||
@@ -391,13 +394,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -415,7 +418,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -453,7 +456,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
@@ -277,8 +277,8 @@ int main()
|
||||
for (unsigned int mip = 0; mip < maxMipLevels; ++mip)
|
||||
{
|
||||
// reisze framebuffer according to mip-level size.
|
||||
unsigned int mipWidth = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipHeight = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipWidth = static_cast<unsigned int>(128 * std::pow(0.5, mip));
|
||||
unsigned int mipHeight = static_cast<unsigned int>(128 * std::pow(0.5, mip));
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, captureRBO);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight);
|
||||
glViewport(0, 0, mipWidth, mipHeight);
|
||||
@@ -343,7 +343,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -467,8 +467,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;
|
||||
@@ -489,13 +492,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -513,7 +516,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -551,7 +554,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
@@ -314,8 +314,8 @@ int main()
|
||||
for (unsigned int mip = 0; mip < maxMipLevels; ++mip)
|
||||
{
|
||||
// reisze framebuffer according to mip-level size.
|
||||
unsigned int mipWidth = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipHeight = 128 * std::pow(0.5, mip);
|
||||
unsigned int mipWidth = static_cast<unsigned int>(128 * std::pow(0.5, mip));
|
||||
unsigned int mipHeight = static_cast<unsigned int>(128 * std::pow(0.5, mip));
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, captureRBO);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight);
|
||||
glViewport(0, 0, mipWidth, mipHeight);
|
||||
@@ -380,7 +380,7 @@ int main()
|
||||
{
|
||||
// per-frame time logic
|
||||
// --------------------
|
||||
float currentFrame = glfwGetTime();
|
||||
auto currentFrame = static_cast<GLfloat>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
@@ -567,8 +567,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;
|
||||
@@ -589,13 +592,13 @@ 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));
|
||||
}
|
||||
|
||||
// renders (and builds at first invocation) a sphere
|
||||
// -------------------------------------------------
|
||||
unsigned int sphereVAO = 0;
|
||||
unsigned int indexCount;
|
||||
GLsizei indexCount;
|
||||
void renderSphere()
|
||||
{
|
||||
if (sphereVAO == 0)
|
||||
@@ -613,7 +616,7 @@ void renderSphere()
|
||||
|
||||
const unsigned int X_SEGMENTS = 64;
|
||||
const unsigned int Y_SEGMENTS = 64;
|
||||
const float PI = 3.14159265359;
|
||||
const float PI = 3.14159265359f;
|
||||
for (unsigned int x = 0; x <= X_SEGMENTS; ++x)
|
||||
{
|
||||
for (unsigned int y = 0; y <= Y_SEGMENTS; ++y)
|
||||
@@ -651,7 +654,7 @@ void renderSphere()
|
||||
}
|
||||
oddRow = !oddRow;
|
||||
}
|
||||
indexCount = indices.size();
|
||||
indexCount = static_cast<GLsizei>(indices.size());
|
||||
|
||||
std::vector<float> data;
|
||||
for (unsigned int i = 0; i < positions.size(); ++i)
|
||||
|
||||
Reference in New Issue
Block a user