It is currently Sat Apr 29, 2017 10:26 am

All times are UTC - 5 hours




 Page 1 of 1 [ 8 posts ] 
Author Message
 Post subject: Shader VMK 77 - PNG File Loader
PostPosted: Sun Mar 22, 2015 1:18 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
In this video I show how to use the libpng library to load PNG files and convert them into OpenGL textures to use in the Shader Engine.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Sun Mar 22, 2015 9:27 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I'm not sure what is going on, but on this line of code:
 // Read Image Data From The File
   png_read_png( png.pStruct, png.pInfo, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, NULL ); 

It is throwing an unhandled exception. I have tried multiple solutions too. On my computer I have 3 different SDK versions for the libPng I have version 1.56 that uses zlib 1.2.5, version 1.612 that uses zlib 1.2.8 and the newest version 1.616 that uses zlib 1.28. I have 3 different environment variables for each of these. I have all three of these build out for both debug and release. I have tried all 3 versions and I keep getting the same unhandled exception. I have used the console application to read in the test png file that is found in the C++ series with all 3 versions and it reads in the file and parses correctly. I do not see any errors in this projects source. In the textureFileReader.cpp file in the loadPng() I set a break point at the beginning of the function. It does open the file, get the header and confirms the information. It is when it gets to the png_read_png() that it is throwing this error regardless of which version and build of the library I use. At this point I am stumped as to what is going on. I have read through the documentation and can not seem to find any appropriate help. I do not know if it makes a difference that I am using VS2012 or not where as these libs were built in either 2008 or 2010 versions. I have yet to port this shader engine project to vs2013, but I was think of doing this soon. Any help or suggestions would be appreciated.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 12:53 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I went back through the process of building the pngLibs for each of the 3 versions I have. Using the win32 console project to read in your test file from the C++ series, all 3 versions open and recognize the test.png as a png file. They display the proper text on the screen for the data between all three. The 1.56 version does not display any warnings, however in the 1.612 & 1.616 versions both of them give me this warning message on the console output
libpng warning: iCCP: known incorrect sRGB profile
when it reaches this line of code
   // Read Image Data From The File
   png_read_png( png.pStruct, png.pInfo, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, NULL );
but they display all the correct data. I do not know if this could be the cause of the problem or not, but all 3 do display RGB color image with Alpha channel, 4x9 pixels, 4 color channels, 16 bytes per row, and all of the appropriate pixel data with color and alpha information. I'll keep going through the process to see if I can find the cause of my current problem. If I have to go back to my GameEngine or GhostToast and add the png loaders there to see if each of the libraries work there, then it could be that I'm using VS2012 with the ShaderEngine, since Ghost is in VS2010 and GameEngine is in VS2008. The function that is giving me this warning in the newer versions is also the same function call that was giving me the unhandled exception in my ShaderEngine causing the program to crash.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 4:13 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
After a hours of working through this problem here is what I have come up with so far.

In my Ghost game engine which is built in VS2010 I can link both versions 1.56 and the newest 1.616 and successfully build and render the PNG test image from the OpenGL tips and tricks series. Using the exact same methods of importing the (Debug) version of the libraries and using the appropriate environment variables(paths) both of them build in the ShaderEngine which is built in VS2012 but neither of them render the PNG graphic. Both 1.56 and 1.616 crash on this line

   // Read Image Data From The File
   png_read_png( png.pStruct, png.pInfo, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, NULL );
with this or a similar error:
Unhandled exception at 0x77308E19 (ntdll.dll) in Game_debug.exe: 0xC0000005: Access violation writing location 0x00000014.
which breaks in this file: [pngrio.c] on this line 61
check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr);

I can not seem to figure out why it is building and working in VS2010 but not in VS2012


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 8:03 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
In your Shader Engine, Open your Game Projects's Property Pages > Configuration Properties > C/C++ > Code Generation.

Look at what you have set for your Runtime Library Setting. If you are creating a debug build you most likely will have "Multi-threaded Debug DLL" selected here.

Now open the libPng solution. If you are building the Shader Engine in VS2012 then you have to build libPng with VS2012 too. I don't remember if libPng comes with a VS2012 setup for you, if not, just open libPng's VS2010 project in VS2012 and it should update all the settings for you.

Make sure that your libPng property pages all are using Configuration Properties > General > Platform Toolset v120 (This value will be v100 if you are using vs2010 so make sure this was changed over correctly).

Also make sure that your library and dll that you build all are using the same Runtime Library Setting as your Shader engine.

Once you have build the library and created the libPng15.dll, copy over the new dll to your Game\_build directory and make sure you are pointing at the correct location for the new libPng15.lib file that you just created.

Do a clean of your Shader Engine, and rebuild everything using the new libPng library that you are pointing to. Now when you run your code everything should work fine.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 1:07 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
After taking your advice into consideration here is what I did on my PC: I created 3 folders inside of my pngLib folder where my other libraries exist. These three folders are VS2010, VS2012 & VS2013 respectively. I then took the newest libpng v1.6.16 and newest zlib v1.2.8 folders and placed the extracted contents into each of the folders. Then I went into my environment variables and renamed the original from PNG_SDK to PNG_SDK_2010 and set the path to the same directly in libpng but within the VS2010 folder, opened the project for libpng using VS2010 and built both release and debug versions. I went into my Toast project and corrected the include paths and pasted the newly built library in the project did a clean of the solution and Toast worked. I repeated this process for the libpng within the VS2012 folder built out both release and debug, fixed the paths in the ShaderEngine this time using PNG_SDK_2012 instead of PNG_SDK_2010 and pasted the dll from this debug build into the project did a clean of the solution and "NO CRASHES" It renders to the screen! :).. I will do the same process for VS2013 when I am ready to port the ShaderEngine over to it. I was thinking on these lines, last night but I spent to many hours on it and was getting tired, so I just ended up going to sleep. Thank you for the advice.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 1:34 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
I'm glad you got it working. I'm sure this thread will help others who may also run into the same problem when using the libpng library.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 77 - PNG File Loader
PostPosted: Mon Mar 23, 2015 2:05 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
Not just the libpng but any other library that is built in one version of Visual Studio and trying to use its compiled library in another version of Visual Studio. It is good to know ahead of time that which ever version of Visual Studio you are using, any libraries that you are linking against either it be a static lib or dll should be built from the same version that your project is being built in, along with the same debug / release version run times, character sets, and even possibly the optimization codes.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron