Qt5-based Viewer: fix build.

pull/1048/head
Kim Kulling 2016-10-21 12:50:41 +02:00
parent fe0cfc52bc
commit 3b61ff4cf2
5 changed files with 126 additions and 121 deletions

View File

@ -77,6 +77,7 @@ OPTION ( ASSIMP_BUILD_TESTS
ON ON
) )
IF(MSVC) IF(MSVC)
set (CMAKE_PREFIX_PATH "D:\\libs\\devil")
OPTION( ASSIMP_INSTALL_PDB OPTION( ASSIMP_INSTALL_PDB
"Install MSVC debug files." "Install MSVC debug files."
ON ON
@ -336,10 +337,10 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
# Why here? Maybe user do not want Qt viewer and have no Qt. # Why here? Maybe user do not want Qt viewer and have no Qt.
# Why assimp_qt_viewer/CMakeLists.txt still contain similar check? # Why assimp_qt_viewer/CMakeLists.txt still contain similar check?
# Because viewer can be build independently of Assimp. # Because viewer can be build independently of Assimp.
FIND_PACKAGE(Qt5 QUIET) FIND_PACKAGE(Qt5Widgets QUIET)
FIND_PACKAGE(DevIL QUIET) FIND_PACKAGE(DevIL QUIET)
FIND_PACKAGE(OpenGL QUIET) FIND_PACKAGE(OpenGL QUIET)
IF ( Qt5_FOUND AND IL_FOUND AND OPENGL_FOUND) IF ( Qt5Widgets_FOUND AND IL_FOUND AND OPENGL_FOUND)
ADD_SUBDIRECTORY( tools/assimp_qt_viewer/ ) ADD_SUBDIRECTORY( tools/assimp_qt_viewer/ )
ELSE() ELSE()
SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "") SET ( ASSIMP_QT_VIEWER_DEPENDENCIES "")
@ -356,7 +357,7 @@ IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
ENDIF (NOT OPENGL_FOUND) ENDIF (NOT OPENGL_FOUND)
MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}") MESSAGE (WARNING "Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: ${ASSIMP_QT_VIEWER_DEPENDENCIES}")
ENDIF ( Qt5_FOUND AND IL_FOUND AND OPENGL_FOUND) ENDIF ( Qt5Widgets_FOUND AND IL_FOUND AND OPENGL_FOUND)
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS ) ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )
IF ( ASSIMP_BUILD_SAMPLES) IF ( ASSIMP_BUILD_SAMPLES)

View File

@ -3,12 +3,12 @@ set(PROJECT_VERSION "")
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED) find_package(Qt5Widgets REQUIRED)
find_package(DevIL REQUIRED) find_package(DevIL REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include_directories( include_directories(
${QT_INCLUDES} ${Qt5Widgets_INCLUDES}
${Assimp_SOURCE_DIR}/include ${Assimp_SOURCE_DIR}/include
${Assimp_SOURCE_DIR}/code ${Assimp_SOURCE_DIR}/code
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
@ -21,15 +21,16 @@ link_directories(${Assimp_BINARY_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall")
set(assimp_qt_viewer_SRCS main.cpp loggerview.cpp glview.cpp mainwindow.cpp) set(assimp_qt_viewer_SRCS main.cpp loggerview.cpp glview.cpp mainwindow.cpp)
qt4_wrap_ui(UISrcs mainwindow.ui) qt5_wrap_ui(UISrcs mainwindow.ui)
qt4_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp) qt5_wrap_cpp(MOCrcs mainwindow.hpp glview.hpp)
add_executable(${PROJECT_NAME} ${assimp_qt_viewer_SRCS} ${UISrcs} ${MOCrcs}) add_executable(${PROJECT_NAME} ${assimp_qt_viewer_SRCS} ${UISrcs} ${MOCrcs})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${IL_LIBRARIES} ${OPENGL_LIBRARIES} assimp) target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${IL_LIBRARIES} ${OPENGL_LIBRARIES} assimp)
qt5_use_modules(${PROJECT_NAME} Widgets OpenGL)
if(WIN32) # Check if we are on Windows if(WIN32) # Check if we are on Windows
if(MSVC) # Check if we are using the Visual Studio compiler if(MSVC) # Check if we are using the Visual Studio compiler
set_target_properties(TestProject PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") #set_target_properties(TestProject PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
elseif(CMAKE_COMPILER_IS_GNUCXX) elseif(CMAKE_COMPILER_IS_GNUCXX)
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows") # Not tested
else() else()

View File

@ -9,7 +9,7 @@
#include <GL/glu.h> #include <GL/glu.h>
// Header files, DevIL. // Header files, DevIL.
#include <IL/il.h> #include <il.h>
// Header files, Assimp. // Header files, Assimp.
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>
@ -56,15 +56,15 @@ void CGLView::SHelper_Camera::SetDefault()
void CGLView::Material_Apply(const aiMaterial* pMaterial) void CGLView::Material_Apply(const aiMaterial* pMaterial)
{ {
GLfloat tcol[4]; GLfloat tcol[4];
aiColor4D taicol; aiColor4D taicol;
unsigned int max; unsigned int max;
int ret1, ret2; int ret1, ret2;
int texture_index = 0; int texture_index = 0;
aiString texture_path; aiString texture_path;
auto set_float4 = [](float f[4], float a, float b, float c, float d) { f[0] = a, f[1] = b, f[2] = c, f[3] = d; }; auto set_float4 = [](float f[4], float a, float b, float c, float d) { f[0] = a, f[1] = b, f[2] = c, f[3] = d; };
auto color4_to_float4 = [](const aiColor4D *c, float f[4]) { f[0] = c->r, f[1] = c->g, f[2] = c->b, f[3] = c->a; }; auto color4_to_float4 = [](const aiColor4D *c, float f[4]) { f[0] = c->r, f[1] = c->g, f[2] = c->b, f[3] = c->a; };
///TODO: cache materials ///TODO: cache materials
// Disable color material because glMaterial is used. // Disable color material because glMaterial is used.
@ -158,124 +158,127 @@ std::list<aiMatrix4x4> mat_list;
} while(node_cur != nullptr); } while(node_cur != nullptr);
} }
// multiplicate all matrices in reverse order // multiply all matrices in reverse order
for(std::list<aiMatrix4x4>::reverse_iterator rit = mat_list.rbegin(); rit != mat_list.rend(); rit++) pOutMatrix = pOutMatrix * (*rit); for ( std::list<aiMatrix4x4>::reverse_iterator rit = mat_list.rbegin(); rit != mat_list.rend(); rit++)
{
pOutMatrix = pOutMatrix * (*rit);
}
} }
void CGLView::ImportTextures(const QString& pScenePath) void CGLView::ImportTextures(const QString& pScenePath)
{ {
auto LoadTexture = [&](const QString& pFileName) -> bool ///TODO: IME texture mode, operation. auto LoadTexture = [&](const QString& pFileName) -> bool ///TODO: IME texture mode, operation.
{ {
ILboolean success; ILboolean success;
GLuint id_ogl_texture;// OpenGL texture ID. GLuint id_ogl_texture;// OpenGL texture ID.
if(!pFileName.startsWith(AI_EMBEDDED_TEXNAME_PREFIX)) if(!pFileName.startsWith(AI_EMBEDDED_TEXNAME_PREFIX))
{ {
ILuint id_image;// DevIL image ID. ILuint id_image;// DevIL image ID.
QString basepath = pScenePath.left(pScenePath.lastIndexOf('/') + 1);// path with '/' at the end. QString basepath = pScenePath.left(pScenePath.lastIndexOf('/') + 1);// path with '/' at the end.
QString fileloc = (basepath + pFileName); QString fileloc = (basepath + pFileName);
fileloc.replace('\\', "/"); fileloc.replace('\\', "/");
ilGenImages(1, &id_image);// Generate DevIL image ID. ilGenImages(1, &id_image);// Generate DevIL image ID.
ilBindImage(id_image); ilBindImage(id_image);
success = ilLoadImage(fileloc.toLocal8Bit()); success = ilLoadImage(fileloc.toLocal8Bit());
if(!success) if(!success)
{ {
LogError(QString("Couldn't load Image: %1").arg(fileloc)); LogError(QString("Couldn't load Image: %1").arg(fileloc));
return false; return false;
} }
// Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA. // Convert every colour component into unsigned byte. If your image contains alpha channel you can replace IL_RGB with IL_RGBA.
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
if(!success) if(!success)
{ {
LogError("Couldn't convert image."); LogError("Couldn't convert image.");
return false; return false;
} }
glGenTextures(1, &id_ogl_texture);// Texture ID generation. glGenTextures(1, &id_ogl_texture);// Texture ID generation.
mTexture_IDMap[pFileName] = id_ogl_texture;// save texture ID for filename in map mTexture_IDMap[pFileName] = id_ogl_texture;// save texture ID for filename in map
glBindTexture(GL_TEXTURE_2D, id_ogl_texture);// Binding of texture ID. glBindTexture(GL_TEXTURE_2D, id_ogl_texture);// Binding of texture ID.
// Redefine standard texture values // Redefine standard texture values
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);// We will use linear interpolation for magnification filter. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);// We will use linear interpolation for magnification filter.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);// We will use linear interpolation for minifying filter. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);// We will use linear interpolation for minifying filter.
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0,
ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());// Texture specification. ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());// Texture specification.
//Cleanup //Cleanup
ilDeleteImages(1, &id_image);// Because we have already copied image data into texture data we can release memory used by image. ilDeleteImages(1, &id_image);// Because we have already copied image data into texture data we can release memory used by image.
} }
else else
{ {
struct SPixel_Description struct SPixel_Description
{ {
const char* FormatHint; const char* FormatHint;
const GLint Image_InternalFormat; const GLint Image_InternalFormat;
const GLint Pixel_Format; const GLint Pixel_Format;
}; };
constexpr SPixel_Description Pixel_Description[] = { constexpr SPixel_Description Pixel_Description[] = {
{"rgba8880", GL_RGB, GL_RGB}, {"rgba8880", GL_RGB, GL_RGB},
{"rgba8888", GL_RGBA, GL_RGBA} {"rgba8888", GL_RGBA, GL_RGBA}
}; };
constexpr size_t Pixel_Description_Count = sizeof(Pixel_Description) / sizeof(SPixel_Description); constexpr size_t Pixel_Description_Count = sizeof(Pixel_Description) / sizeof(SPixel_Description);
size_t idx_description; size_t idx_description;
// Get texture index. // Get texture index.
bool ok; bool ok;
size_t idx_texture = pFileName.right(strlen(AI_EMBEDDED_TEXNAME_PREFIX)).toULong(&ok); size_t idx_texture = pFileName.right(strlen(AI_EMBEDDED_TEXNAME_PREFIX)).toULong(&ok);
if(!ok) if(!ok)
{ {
LogError("Can not get index of the embedded texture from path in material."); LogError("Can not get index of the embedded texture from path in material.");
return false; return false;
} }
// Create alias for conveniance. // Create alias for conveniance.
const aiTexture& als = *mScene->mTextures[idx_texture]; const aiTexture& als = *mScene->mTextures[idx_texture];
if(als.mHeight == 0)// Compressed texture. if(als.mHeight == 0)// Compressed texture.
{ {
LogError("IME: compressed embedded textures are not implemented."); LogError("IME: compressed embedded textures are not implemented.");
} }
else else
{ {
ok = false; ok = false;
for(size_t idx = 0; idx < Pixel_Description_Count; idx++) for(size_t idx = 0; idx < Pixel_Description_Count; idx++)
{ {
if(als.CheckFormat(Pixel_Description[idx].FormatHint)) if(als.CheckFormat(Pixel_Description[idx].FormatHint))
{ {
idx_description = idx; idx_description = idx;
ok = true; ok = true;
break; break;
} }
} }
if(!ok) if(!ok)
{ {
LogError(QString("Unsupported format hint for embedded texture: [%1]").arg(als.achFormatHint)); LogError(QString("Unsupported format hint for embedded texture: [%1]").arg(als.achFormatHint));
return false; return false;
} }
glGenTextures(1, &id_ogl_texture);// Texture ID generation. glGenTextures(1, &id_ogl_texture);// Texture ID generation.
mTexture_IDMap[pFileName] = id_ogl_texture;// save texture ID for filename in map mTexture_IDMap[pFileName] = id_ogl_texture;// save texture ID for filename in map
glBindTexture(GL_TEXTURE_2D, id_ogl_texture);// Binding of texture ID. glBindTexture(GL_TEXTURE_2D, id_ogl_texture);// Binding of texture ID.
// Redefine standard texture values // Redefine standard texture values
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);// We will use linear interpolation for magnification filter. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);// We will use linear interpolation for magnification filter.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);// We will use linear interpolation for minifying filter. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);// We will use linear interpolation for minifying filter.
// Texture specification. // Texture specification.
glTexImage2D(GL_TEXTURE_2D, 0, Pixel_Description[idx_description].Image_InternalFormat, als.mWidth, als.mHeight, 0, glTexImage2D(GL_TEXTURE_2D, 0, Pixel_Description[idx_description].Image_InternalFormat, als.mWidth, als.mHeight, 0,
Pixel_Description[idx_description].Pixel_Format, GL_UNSIGNED_BYTE, (uint8_t*)als.pcData); Pixel_Description[idx_description].Pixel_Format, GL_UNSIGNED_BYTE, (uint8_t*)als.pcData);
}// if(als.mHeight == 0) else }// if(als.mHeight == 0) else
}// if(!filename.startsWith(AI_EMBEDDED_TEXNAME_PREFIX)) else }// if(!filename.startsWith(AI_EMBEDDED_TEXNAME_PREFIX)) else
return true; return true;
};// auto LoadTexture = [&](const aiString& pPath) };// auto LoadTexture = [&](const aiString& pPath)
if(mScene == nullptr) if(mScene == nullptr)
{ {

View File

@ -325,7 +325,7 @@ bool selected = ui->lstLight->isItemSelected(ui->lstLight->currentItem());
mGLView->updateGL(); mGLView->updateGL();
} }
void MainWindow::on_lstCamera_clicked(__unused const QModelIndex &index) void MainWindow::on_lstCamera_clicked( const QModelIndex &)
{ {
mGLView->Camera_Set(ui->lstLight->currentRow()); mGLView->Camera_Set(ui->lstLight->currentRow());
mGLView->updateGL(); mGLView->updateGL();

View File

@ -6,7 +6,7 @@
#pragma once #pragma once
// Header files, Qt. // Header files, Qt.
#include <QMainWindow> #include <QtWidgets>
// Header files, project. // Header files, project.
#include "glview.hpp" #include "glview.hpp"