I use cmake to download the freeimage library and I use kubuntu 14.x I had a problem with
"error: conflicting declaration 'typedef CARD8 BOOL'"
and I thought it would be nice to share my solution with people who have this problem!
install FreeImage on Linux:
sudo apt-get install libfreeimage-dev
In my CMakeLists.txt file, I have:
set(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY /usr/libs) find_path(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY, FreeImage.h) find_library(FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY, freeimage) include_directories(${FREEIMAGE_LIBRARY_AND_HEADER_DIRRECTORY}) target_link_libraries(freeimage)
And in my main.cpp I have:
#include <FreeImage.h> #ifndef CARD8 #define BYTE CARD8 #define BOOL CARD8 #endif
And some additional code to capture the OpenGl framework on disk:
void generateImage(){ int w, h; // get the width and height of the OpenGL window! glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GLubyte * pixels = new GLubyte[3*w*h]; glReadPixels(0,0,w,h,GL_RGB,GL_UNSIGNED_BYTE, pixels); FIBITMAP * image = FreeImage_ConvertFromRawBits(pixels,w,h,3 * w, 24, 0x0000FF, 0xFF0000, 0x00FF00, false); FreeImage_Save(FIF_BMP,image, "../img/text.bmp",0); //Free resource FreeImage_Unload(image); delete[] pixels; }
I hope this helps those who have problems with this!
Relations Cahin