C++ OpenGL stb_image.h 错误
C++ OpenGL stb_image.h errors
我正在关注 https://learnopengl.com/ (specifically https://learnopengl.com/Advanced-OpenGL/Depth-testing) and I have many errors to do with stbi. Error Log image here (Below I have also attached the complete Output tab). I have added the "#define STB_IMAGE_IMPLEMENTATION" at the top of the main.cpp file (and not in a header). If I don't use any stb_image functionalities, the project compiles and runs. I have had projects where stb_image worked fine, but all those projects that worked were x86 (or 32-bit). It seems that I can not get stb_image with x64 (or 64-bit). I know that x64 itself works since other projects without stb_image that were x64 have compiled. I have also looked back to where I downloaded the header file for stb_image and there was no option for x64 vs x86 as there was only one universal option. Here is an image of how the files are organized: File hierarchy 中的 OpenGL 教程。我还将包括我的 main.cpp 文件,但如果您想查看特定文件,请告诉我。我是 c++ 的新手,因为我来自 java 和 python,所以感谢您的帮助。
#define STB_IMAGE_IMPLEMENTATION
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stb_image.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <Shader.h>
#include <Camera.h>
#include <Model.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void processInput(GLFWwindow* window);
unsigned int loadTexture(const char* path);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = (float)SCR_WIDTH / 2.0;
float lastY = (float)SCR_HEIGHT / 2.0;
bool firstMouse = true;
// timing
float deltaTime = 0.0f;
float lastFrame = 0.0f;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
// tell GLFW to capture our mouse
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS); // always pass the depth test (same effect as glDisable(GL_DEPTH_TEST))
// build and compile shaders
// -------------------------
Shader shader("depth_testing.vs", "depth_testing.fs");
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float cubeVertices[] = {
// positions // texture Coords
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
};
float planeVertices[] = {
// positions // texture Coords (note we set these higher than 1 (together with GL_REPEAT as texture wrapping mode). this will cause the floor texture to repeat)
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
-5.0f, -0.5f, 5.0f, 0.0f, 0.0f,
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
5.0f, -0.5f, -5.0f, 2.0f, 2.0f
};
// cube VAO
unsigned int cubeVAO, cubeVBO;
glGenVertexArrays(1, &cubeVAO);
glGenBuffers(1, &cubeVBO);
glBindVertexArray(cubeVAO);
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
// plane VAO
unsigned int planeVAO, planeVBO;
glGenVertexArrays(1, &planeVAO);
glGenBuffers(1, &planeVBO);
glBindVertexArray(planeVAO);
glBindBuffer(GL_ARRAY_BUFFER, planeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(planeVertices), &planeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
// load textures
// -------------
unsigned int cubeTexture = loadTexture("resources/textures/container.jpg");
unsigned int floorTexture = loadTexture("resources/textures/awesomeface.png");
// shader configuration
// --------------------
shader.use();
shader.setInt("texture1", 0);
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// per-frame time logic
// --------------------
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.use();
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = camera.GetViewMatrix();
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
shader.setMat4("view", view);
shader.setMat4("projection", projection);
// cubes
glBindVertexArray(cubeVAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cubeTexture);
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, -1.0f));
shader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 0.0f));
shader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
// floor
glBindVertexArray(planeVAO);
glBindTexture(GL_TEXTURE_2D, floorTexture);
shader.setMat4("model", glm::mat4(1.0f));
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &cubeVAO);
glDeleteVertexArrays(1, &planeVAO);
glDeleteBuffers(1, &cubeVBO);
glDeleteBuffers(1, &planeVBO);
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
camera.ProcessKeyboard(UP, deltaTime);
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
camera.ProcessKeyboard(DOWN, deltaTime);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos; // reversed since y-coordinates go from bottom to top
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
// glfw: whenever the mouse scroll wheel scrolls, this callback is called
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(yoffset);
}
// utility function for loading a 2D texture from file
// ---------------------------------------------------
unsigned int loadTexture(char const* path)
{
unsigned int textureID;
glGenTextures(1, &textureID);
int width, height, nrComponents;
unsigned char* data = stbi_load(path, &width, &height, &nrComponents, 0);
if (data)
{
GLenum format;
if (nrComponents == 1)
format = GL_RED;
else if (nrComponents == 3)
format = GL_RGB;
else if (nrComponents == 4)
format = GL_RGBA;
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
stbi_image_free(data);
}
else
{
std::cout << "Texture failed to load at path: " << path << std::endl;
stbi_image_free(data);
}
return textureID;
}
Build started...
1>------ Build started: Project: DepthTesting, Configuration: Debug x64 ------
1>main.cpp
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\Shader.h(56,40): warning C4101: 'e': unreferenced local variable
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(677,12): error C2084: function 'int stbi__cpuid3(void)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(677): message : see previous definition of 'stbi__cpuid3'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(699,12): error C2084: function 'int stbi__sse2_available(void)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(699): message : see previous definition of 'stbi__sse2_available'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,17): error C2065: 'stbi__cpuid3': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,31): error C2440: 'initializing': cannot convert from 'int (__cdecl *)(void)' to 'int'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,15): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(762,3): error C2371: 'stbi__context': redefinition; different basic types
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(762): message : see declaration of 'stbi__context'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(768,13): error C2084: function 'void stbi__start_mem(stbi__context *,const stbi_uc *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(768): message : see previous definition of 'stbi__start_mem'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(778,13): error C2084: function 'void stbi__start_callbacks(stbi__context *,stbi_io_callbacks *,void *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(778): message : see previous definition of 'stbi__start_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(792,12): error C2084: function 'int stbi__stdio_read(void *,char *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(792): message : see previous definition of 'stbi__stdio_read'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(797,13): error C2084: function 'void stbi__stdio_skip(void *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(797): message : see previous definition of 'stbi__stdio_skip'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(807,12): error C2084: function 'int stbi__stdio_eof(void *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(807): message : see previous definition of 'stbi__stdio_eof'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(812,26): error C2374: 'stbi__stdio_callbacks': redefinition; multiple initialization
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(812): message : see declaration of 'stbi__stdio_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(819,13): error C2084: function 'void stbi__start_file(stbi__context *,FILE *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(819): message : see previous definition of 'stbi__start_file'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(821,5): error C2065: 'stbi__start_callbacks': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(828,13): error C2084: function 'void stbi__rewind(stbi__context *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(828): message : see previous definition of 'stbi__rewind'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(839,5): error C2365: 'STBI_ORDER_RGB': redefinition; previous definition was 'enumerator'
...
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1286,13): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1288,20): error C2065: 'stbi__err': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1294,18): error C2084: function 'stbi_uc *stbi_load_from_file(FILE *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1294): message : see previous definition of 'stbi_load_from_file'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1298,5): error C2065: 'stbi__start_file': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,14): error C2065: 'stbi__load_and_postprocess_8bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,71): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,71): message : could be 'unsigned char *stbi__load_and_postprocess_8bit(stbi__context *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1307,23): error C2084: function 'stbi_us *stbi_load_from_file_16(FILE *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1307): message : see previous definition of 'stbi_load_from_file_16'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1311,5): error C2065: 'stbi__start_file': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,14): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,72): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,72): message : could be 'stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1320,18): error C2084: function 'stbi_us *stbi_load_16(const char *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1320): message : see previous definition of 'stbi_load_16'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,15): error C2065: 'stbi__fopen': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,42): error C2440: 'initializing': cannot convert from 'FILE *(__cdecl *)(const char *,const char *)' to 'FILE *'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,13): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1324,30): error C2065: 'stbi__err': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,14): error C2065: 'stbi_load_from_file_16': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,61): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,61): message : could be 'stbi_us *stbi_load_from_file_16(FILE *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1333,18): error C2084: function 'stbi_us *stbi_load_16_from_memory(const stbi_uc *,int,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1333): message : see previous definition of 'stbi_load_16_from_memory'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1336,5): error C2065: 'stbi__start_mem': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1337,12): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1340,18): error C2084: function 'stbi_us *stbi_load_16_from_callbacks(const stbi_io_callbacks *,void *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1340): message : see previous definition of 'stbi_load_16_from_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1343,5): error C2065: 'stbi__start_callbacks': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1344,12): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1344,89): fatal error C1003: error count exceeds 100; stopping compilation
1>Done building project "DepthTesting.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
正如 Retired Ninja 在评论中提到的那样,您要做的就是将 #define STB_IMAGE_IMPLEMENTATION 和 #include stb_image.h 放在所有还包含的 headers 之后stb_image.h 文件。修复此问题后,程序会运行,但我收到一个未找到框架的错误,但我认为这是一个独立的问题。
我正在关注 https://learnopengl.com/ (specifically https://learnopengl.com/Advanced-OpenGL/Depth-testing) and I have many errors to do with stbi. Error Log image here (Below I have also attached the complete Output tab). I have added the "#define STB_IMAGE_IMPLEMENTATION" at the top of the main.cpp file (and not in a header). If I don't use any stb_image functionalities, the project compiles and runs. I have had projects where stb_image worked fine, but all those projects that worked were x86 (or 32-bit). It seems that I can not get stb_image with x64 (or 64-bit). I know that x64 itself works since other projects without stb_image that were x64 have compiled. I have also looked back to where I downloaded the header file for stb_image and there was no option for x64 vs x86 as there was only one universal option. Here is an image of how the files are organized: File hierarchy 中的 OpenGL 教程。我还将包括我的 main.cpp 文件,但如果您想查看特定文件,请告诉我。我是 c++ 的新手,因为我来自 java 和 python,所以感谢您的帮助。
#define STB_IMAGE_IMPLEMENTATION
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stb_image.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <Shader.h>
#include <Camera.h>
#include <Model.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
void processInput(GLFWwindow* window);
unsigned int loadTexture(const char* path);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
// camera
Camera camera(glm::vec3(0.0f, 0.0f, 3.0f));
float lastX = (float)SCR_WIDTH / 2.0;
float lastY = (float)SCR_HEIGHT / 2.0;
bool firstMouse = true;
// timing
float deltaTime = 0.0f;
float lastFrame = 0.0f;
int main()
{
// glfw: initialize and configure
// ------------------------------
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
// glfw window creation
// --------------------
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, mouse_callback);
glfwSetScrollCallback(window, scroll_callback);
// tell GLFW to capture our mouse
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// glad: load all OpenGL function pointers
// ---------------------------------------
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// configure global opengl state
// -----------------------------
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS); // always pass the depth test (same effect as glDisable(GL_DEPTH_TEST))
// build and compile shaders
// -------------------------
Shader shader("depth_testing.vs", "depth_testing.fs");
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
float cubeVertices[] = {
// positions // texture Coords
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
};
float planeVertices[] = {
// positions // texture Coords (note we set these higher than 1 (together with GL_REPEAT as texture wrapping mode). this will cause the floor texture to repeat)
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
-5.0f, -0.5f, 5.0f, 0.0f, 0.0f,
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
5.0f, -0.5f, 5.0f, 2.0f, 0.0f,
-5.0f, -0.5f, -5.0f, 0.0f, 2.0f,
5.0f, -0.5f, -5.0f, 2.0f, 2.0f
};
// cube VAO
unsigned int cubeVAO, cubeVBO;
glGenVertexArrays(1, &cubeVAO);
glGenBuffers(1, &cubeVBO);
glBindVertexArray(cubeVAO);
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), &cubeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
// plane VAO
unsigned int planeVAO, planeVBO;
glGenVertexArrays(1, &planeVAO);
glGenBuffers(1, &planeVBO);
glBindVertexArray(planeVAO);
glBindBuffer(GL_ARRAY_BUFFER, planeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(planeVertices), &planeVertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glBindVertexArray(0);
// load textures
// -------------
unsigned int cubeTexture = loadTexture("resources/textures/container.jpg");
unsigned int floorTexture = loadTexture("resources/textures/awesomeface.png");
// shader configuration
// --------------------
shader.use();
shader.setInt("texture1", 0);
// render loop
// -----------
while (!glfwWindowShouldClose(window))
{
// per-frame time logic
// --------------------
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
// input
// -----
processInput(window);
// render
// ------
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.use();
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = camera.GetViewMatrix();
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
shader.setMat4("view", view);
shader.setMat4("projection", projection);
// cubes
glBindVertexArray(cubeVAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cubeTexture);
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, -1.0f));
shader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(2.0f, 0.0f, 0.0f));
shader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
// floor
glBindVertexArray(planeVAO);
glBindTexture(GL_TEXTURE_2D, floorTexture);
shader.setMat4("model", glm::mat4(1.0f));
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// optional: de-allocate all resources once they've outlived their purpose:
// ------------------------------------------------------------------------
glDeleteVertexArrays(1, &cubeVAO);
glDeleteVertexArrays(1, &planeVAO);
glDeleteBuffers(1, &cubeVBO);
glDeleteBuffers(1, &planeVBO);
glfwTerminate();
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
camera.ProcessKeyboard(UP, deltaTime);
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
camera.ProcessKeyboard(DOWN, deltaTime);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
// glfw: whenever the mouse moves, this callback is called
// -------------------------------------------------------
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos; // reversed since y-coordinates go from bottom to top
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
// glfw: whenever the mouse scroll wheel scrolls, this callback is called
// ----------------------------------------------------------------------
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(yoffset);
}
// utility function for loading a 2D texture from file
// ---------------------------------------------------
unsigned int loadTexture(char const* path)
{
unsigned int textureID;
glGenTextures(1, &textureID);
int width, height, nrComponents;
unsigned char* data = stbi_load(path, &width, &height, &nrComponents, 0);
if (data)
{
GLenum format;
if (nrComponents == 1)
format = GL_RED;
else if (nrComponents == 3)
format = GL_RGB;
else if (nrComponents == 4)
format = GL_RGBA;
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
stbi_image_free(data);
}
else
{
std::cout << "Texture failed to load at path: " << path << std::endl;
stbi_image_free(data);
}
return textureID;
}
Build started...
1>------ Build started: Project: DepthTesting, Configuration: Debug x64 ------
1>main.cpp
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\Shader.h(56,40): warning C4101: 'e': unreferenced local variable
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(677,12): error C2084: function 'int stbi__cpuid3(void)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(677): message : see previous definition of 'stbi__cpuid3'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(699,12): error C2084: function 'int stbi__sse2_available(void)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(699): message : see previous definition of 'stbi__sse2_available'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,17): error C2065: 'stbi__cpuid3': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,31): error C2440: 'initializing': cannot convert from 'int (__cdecl *)(void)' to 'int'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(701,15): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(762,3): error C2371: 'stbi__context': redefinition; different basic types
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(762): message : see declaration of 'stbi__context'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(768,13): error C2084: function 'void stbi__start_mem(stbi__context *,const stbi_uc *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(768): message : see previous definition of 'stbi__start_mem'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(778,13): error C2084: function 'void stbi__start_callbacks(stbi__context *,stbi_io_callbacks *,void *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(778): message : see previous definition of 'stbi__start_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(792,12): error C2084: function 'int stbi__stdio_read(void *,char *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(792): message : see previous definition of 'stbi__stdio_read'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(797,13): error C2084: function 'void stbi__stdio_skip(void *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(797): message : see previous definition of 'stbi__stdio_skip'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(807,12): error C2084: function 'int stbi__stdio_eof(void *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(807): message : see previous definition of 'stbi__stdio_eof'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(812,26): error C2374: 'stbi__stdio_callbacks': redefinition; multiple initialization
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(812): message : see declaration of 'stbi__stdio_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(819,13): error C2084: function 'void stbi__start_file(stbi__context *,FILE *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(819): message : see previous definition of 'stbi__start_file'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(821,5): error C2065: 'stbi__start_callbacks': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(828,13): error C2084: function 'void stbi__rewind(stbi__context *)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(828): message : see previous definition of 'stbi__rewind'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(839,5): error C2365: 'STBI_ORDER_RGB': redefinition; previous definition was 'enumerator'
...
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1286,13): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1288,20): error C2065: 'stbi__err': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1294,18): error C2084: function 'stbi_uc *stbi_load_from_file(FILE *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1294): message : see previous definition of 'stbi_load_from_file'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1298,5): error C2065: 'stbi__start_file': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,14): error C2065: 'stbi__load_and_postprocess_8bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,71): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1299,71): message : could be 'unsigned char *stbi__load_and_postprocess_8bit(stbi__context *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1307,23): error C2084: function 'stbi_us *stbi_load_from_file_16(FILE *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1307): message : see previous definition of 'stbi_load_from_file_16'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1311,5): error C2065: 'stbi__start_file': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,14): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,72): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1312,72): message : could be 'stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1320,18): error C2084: function 'stbi_us *stbi_load_16(const char *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1320): message : see previous definition of 'stbi_load_16'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,15): error C2065: 'stbi__fopen': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,42): error C2440: 'initializing': cannot convert from 'FILE *(__cdecl *)(const char *,const char *)' to 'FILE *'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1322,13): message : There is no context in which this conversion is possible
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1324,30): error C2065: 'stbi__err': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,14): error C2065: 'stbi_load_from_file_16': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,61): error C2568: '=': unable to resolve function overload
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1325,61): message : could be 'stbi_us *stbi_load_from_file_16(FILE *,int *,int *,int *,int)'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1333,18): error C2084: function 'stbi_us *stbi_load_16_from_memory(const stbi_uc *,int,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1333): message : see previous definition of 'stbi_load_16_from_memory'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1336,5): error C2065: 'stbi__start_mem': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1337,12): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1340,18): error C2084: function 'stbi_us *stbi_load_16_from_callbacks(const stbi_io_callbacks *,void *,int *,int *,int *,int)' already has a body
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1340): message : see previous definition of 'stbi_load_16_from_callbacks'
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1343,5): error C2065: 'stbi__start_callbacks': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1344,12): error C2065: 'stbi__load_and_postprocess_16bit': undeclared identifier
1>C:\Users\caleb\Documents\OpenGL\AdvancedOpenGL\DepthTesting\include\stb_image.h(1344,89): fatal error C1003: error count exceeds 100; stopping compilation
1>Done building project "DepthTesting.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
正如 Retired Ninja 在评论中提到的那样,您要做的就是将 #define STB_IMAGE_IMPLEMENTATION 和 #include stb_image.h 放在所有还包含的 headers 之后stb_image.h 文件。修复此问题后,程序会运行,但我收到一个未找到框架的错误,但我认为这是一个独立的问题。