![]() I've tried over and over again to rearrange the project but every time I compile this happens. So what at first was "Resources / image.png" became "./././Resources/image.png", (which did work for all #include directives) but when I run the game I only see the black screen and console showing me messages like Failed to load image "./././Resources/image.png". Obviously I know that when saving the files in different directories, I had to update the paths. So far there hadn't been any problem with accessing resources, but since I decided to tidy up my project by organizing it in directories, my GetTexture, GetSoundBuffer and GetFont functions are unable to load images from the Resources folder. If they are, then that is most likely your problem, as engineer.jpg might *actually* be named or or whatever else.I am programming a little game in C ++ using Visual Studio Code with CMake as the Build System. Is Windows showing file extensions by default in Explorer for you? If it is *not*, then look at your image files and see if they are. I was about to say if that doesn't work then I have no idea, but then I had an idea. If any or all of that fails, run visual studio as administrator, and find the program executable for your program and change it run as administrator and try to loading one of the images that fails. ![]() as 3 or 4 channels and the only thing that matter is how you allocate your textures on the GPU.Īnyway, do you still have a copy of container.jpg that will load correctly? If so, can you try making a copy of it and seeing if the copy will load? If the copy will load, try opening it in MS Paint or anything else, and then just overwriting it with itself, and then try to get it to load in your program again. The number of channels you request be returned in the image data shouldn't matter when it comes to the image type, by which I mean you can have it return a PNG, JPG, BMP, PPM, etc. I assume you're on Windows, and I assume when you say "VS" that you mean Visual Studio, and not VSCode. Std::cout << "Failed to load image: " << failureReason << GlTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, Unsigned char* data2 = stbi_load("engineer.jpg", &width, &height, &nrChannels, 0) Std::cout << "Failed to load image: " << failureReason << std::endl GlTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data1) Ĭonst char* failureReason = stbi_failure_reason() Unsigned char* data1 = stbi_load("container.jpg", &width, &height, &nrChannels, 0) Stbi_set_flip_vertically_on_load(true) // tell stb_image.h to flip loaded textures on the y-axis load image, create texture and generate mipmap GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) ![]() GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) GlTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) Here's my code, but just as an fyi I also tried the solution code and had the same problem so I'm not really sure where to go from here.ĮDIT: Forgot to mention this but width, height, and nrChannels all return 0 and data is set to null when an image other than container.jpg is sent to stbi_load. I've tried dozens of other png/jpg files and the only one that does not return null is container.jpg. I've been working through the textbook and I've run into a problem where stbi_load refuses to load anything other than the container.jpg image provided by the online textbook. SOLVED: I made the mistake of adding the files VIA the solution explorer instead of directly adding them to the project files so the imgs were treated as links to the img file locations in my PC's download folder.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |