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. To all this, it is also worth mentioning that I am using Linux.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. cpp files, here is where i call GetTexture, GetSoundBuffer The organization of the project is as follows: Build: Set(SFML_DIR "$ sfml-audio sfml-graphics sfml-window sfml-system) GetFont: sf::Font& Game::GetFont(std::string _fileName)ĬMakeLists.txt: cmake_minimum_required(VERSION 3.18) Sound->loadFromFile(_fileName) sounds = sound SoundBufferPtr sound = std::make_shared() GetSoundBuffer: sf::SoundBuffer& Game::GetSoundBuffer(std::string _fileName) GetTexture: sf::Texture& Game::GetTexture(std::string _fileName) I don't know much about CMake and I don't know if the problem is with my CMakeLists.txt file or with my previously mentioned functions, which I doubt as they worked perfectly before. 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. I am programming a little game in C ++ using Visual Studio Code with CMake as the Build System.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |