Commit e35d91aa authored by Robert Menzel's avatar Robert Menzel
Browse files

added cmake file to include directly in case no lib of ACGL should get build,...

added cmake file to include directly in case no lib of ACGL should get build, fixed a normal creation bug
parent 1b5d5de4
#
# Use this to compile ACGL as a library. To include it statically compiled into
# your own project you can also just include the CMakeListsStaticInclude.txt:
# INCLUDE(${CMAKE_SOURCE_DIR}/CMakeListsStaticInclude.txt)
#
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
################################################################################
......@@ -15,7 +20,7 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/GlobalAndLocalExternACGL.txt)
# OpenGL Support
IF(NOT DEFINED ACGL_OPENGL_SUPPORT)
SET(ACGL_OPENGL_SUPPORT CORE_42 CACHE STRING "")
SET_PROPERTY(CACHE ACGL_OPENGL_SUPPORT PROPERTY STRINGS CORE_32 CORE_33 CORE_40 CORE_41 CORE_41_ES CORE_42 FULL_21 FULL_30 FULL_31 FULL_32 FULL_33 FULL_40 FULL_41 FULL_42 ES_20)
SET_PROPERTY(CACHE ACGL_OPENGL_SUPPORT PROPERTY STRINGS CORE_32 CORE_33 CORE_40 CORE_41 CORE_42 CORE_43 CORE_42 FULL_21 FULL_30 FULL_31 FULL_32 FULL_33 FULL_40 FULL_41 FULL_42 FULL_43 ES_20)
ENDIF()
# Error Level
......@@ -44,20 +49,11 @@ SET(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib")
# Project Files
################################################################################
# Find all used files of certain file-types
FILE(GLOB_RECURSE SOURCE_FILES_C "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
FILE(GLOB_RECURSE SOURCE_FILES_CC "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc")
FILE(GLOB_RECURSE SOURCE_FILES_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
FILE(GLOB_RECURSE HEADER_FILES_H "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
FILE(GLOB_RECURSE HEADER_FILES_HH "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hh")
FILE(GLOB_RECURSE HEADER_FILES_HPP "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")
SET(HEADER_FILES ${HEADER_FILES_H} ${HEADER_FILES_HH} ${HEADER_FILES_HPP})
SET(SOURCE_FILES ${SOURCE_FILES_C} ${SOURCE_FILES_CC} ${SOURCE_FILES_CPP})
# Add ACGL to the include path
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include")
#
# if ACGL should not get compiled as a library, just include the following file
# into the projects CMakeList.txt
#
INCLUDE(${CMAKE_SOURCE_DIR}/CMakeListsStaticInclude.txt)
################################################################################
# Defines
......@@ -79,19 +75,6 @@ IF(DEFINED ACGL_COMPILE_WITH_QT)
SET(LIBRARIES ${LIBRARIES} ${QT_LIBRARIES})
ENDIF()
# GLM
#FIND_PACKAGE(GLM REQUIRED)
#INCLUDE_DIRECTORIES(${GLM_INCLUDE_DIR})
# GLEW
#IF(DEFINED ACGL_PLATFORM_DESKTOP)
# #MESSAGE("GLEW")
# FIND_PACKAGE(GLEW REQUIRED)
# ADD_DEFINITIONS(${GLEW_DEFINES})
# INCLUDE_DIRECTORIES(${GLEW_INCLUDE_DIR})
# SET(LIBRARIES ${LIBRARIES} ${GLEW_LIBRARIES})
#ENDIF()
################################################################################
# Final Definition
################################################################################
......
#
# To build ACGL as a library, use the CMakeLists.txt
# To build it statically into a project just include this file,
# e.g.: INCLUDE(${CMAKE_SOURCE_DIR}/extern/acgl/CMakeListsStaticInclude.txt)
#
# Find all used files of certain file-types
FILE(GLOB_RECURSE SOURCE_FILES_C "${CMAKE_CURRENT_LIST_DIR}/src/*.c")
FILE(GLOB_RECURSE SOURCE_FILES_CC "${CMAKE_CURRENT_LIST_DIR}/src/*.cc")
FILE(GLOB_RECURSE SOURCE_FILES_CPP "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp")
FILE(GLOB_RECURSE HEADER_FILES_H "${CMAKE_CURRENT_LIST_DIR}/include/*.h")
FILE(GLOB_RECURSE HEADER_FILES_HH "${CMAKE_CURRENT_LIST_DIR}/include/*.hh")
FILE(GLOB_RECURSE HEADER_FILES_HPP "${CMAKE_CURRENT_LIST_DIR}/include/*.hpp")
SET(HEADER_FILES ${HEADER_FILES} ${HEADER_FILES_H} ${HEADER_FILES_HH} ${HEADER_FILES_HPP})
SET(SOURCE_FILES ${SOURCE_FILES} ${SOURCE_FILES_C} ${SOURCE_FILES_CC} ${SOURCE_FILES_CPP})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/include)
cmake @ d68c5f45
Subproject commit c82510d12c5f5c6d94696193163e838afc7db4ab
Subproject commit d68c5f4579f5f94ad7ef455e49aae35797ce36df
......@@ -30,15 +30,10 @@ protected:
//! Constructor is protected => singleton.
Settings()
: mResourcePath (""),
mTexturePath ("Texture/"),
mGeometryPath ("Geometry/"),
mShaderPath ("Shader/")
mTexturePath (""),
mGeometryPath (""),
mShaderPath ("")
{
# if defined(ACGL_OPENGL_VERSION_21)
// use an alternative path if compiled for old OpenGL
mShaderPath = "Shader21/";
ACGL::Utils::message() << "compiled for OpenGL 2.1: using alternative shader folder Shader21/" << std::endl;
# endif
}
public:
......
......@@ -16,9 +16,10 @@
*
*
* This wrapper can get configured with external defines:
* ACGL_OPENGL_PROFILE_CORE : CORE: if possible include/load only core OpenGL functions
* FULL: support for CORE and deprecated functions
* ACGL_OPENGL_PROFILE_CORE : if defined: if possible include/load only core OpenGL functions
* if not defined: support for CORE and deprecated functions
* (NOTE: the OpenGL context itself is not created by ACGL!)
* ACGL_OPENGL_ES : if defined: assume OpenGL ES (2.0 or 3.0)
* ACGL_OPENGL_VERSION_41 : (or other versions): minimal OpenGL version that can be assumed to be present.
* The app can't run on older contexts and will probably terminate at startup.
* Set this to a low version and it will run on lost machines
......@@ -28,7 +29,6 @@
* functions of the latest GL version are loaded (if available) and the header
* of the latest version gets included. ACGL however will only assume the version
* set by ACGL_OPENGL_VERSION_XY to be present.
* ACGL_PLATFORM_DESKTOP : DESKTOP vs. MOBILE plattform = GL vs. GL ES
*
* ACGL_USE_GLEW : if this is set, GLEW gets used to load the GL functions,
* otherwise an internal GL loader based on glLoadGen gets used on desktop systems.
......
......@@ -87,7 +87,7 @@ inline bool ACGL_ARB_compute_shader() {
#endif
}
// anisotrophic texture filtering
// ARB debug output
inline bool ACGL_ARB_debug_output() {
#ifdef ACGL_EXTENSION_LOADER_GLLOADGEN
return (ogl_ext_ARB_debug_output != ogl_LOAD_FAILED);
......
......@@ -28,282 +28,4 @@ bool GeometryDataControlFileOBJ::load(SharedGeometryData& geometry) const
return true;
else
return false;
/*
std::string fullFileName = getFullFilePath();
std::string line = "";
std::ifstream fileStream(fullFileName.c_str(), std::ifstream::in);
std::vector<GLfloat> sharedVertexVector;
std::vector<GLfloat> sharedTexCoordVector;
std::vector<GLfloat> sharedNormalVector;
uint_t texCoordElements = 0;
uint_t texCoordDimension = 0;
sharedVertexVector.resize(4);
sharedNormalVector.resize(3);
bool elementOK = true;
bool lineOK = true;
uint_t lineNumber = 0;
if (!fileStream.is_open())
{
error() << "Failed to open file: " << fullFileName << std::endl;
return false;
}
//Read the first line
if (fileStream.good()) std::getline(fileStream, line);
//
// read in vertex, texture and normal data:
//
while (fileStream.good())
{
if (StringOperations::startsWith(line, "vt"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
//The first occurence of vt gives us the number of texture coordinates per vertex.
if (texCoordElements == 0)
{
texCoordElements = elements.size();
texCoordDimension = texCoordElements - 1;
sharedTexCoordVector.resize(texCoordDimension);
}
if ((uint_t)elements.size() == texCoordElements)
{
for(uint_t i = 1; i < texCoordElements; ++i)
sharedTexCoordVector.push_back(StringOperations::to<GLfloat>(elements[i], &elementOK));
}
else
{
//If a later texture coordinate is defined wrong, we enter zeros, because
//otherwise the indices would be intermixed.
for(uint_t i = 1; i < texCoordElements; ++i)
sharedTexCoordVector.push_back(0.0f);
lineOK = false;
}
}
else if (StringOperations::startsWith(line, "vn"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
if (elements.size() == 4)
{
sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[1], &elementOK));
sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[2], &elementOK));
sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[3], &elementOK));
}
else
{
//If a later texture coordinate is defined wrong, we enter zeros, because
//otherwise the indices would be intermixed.
sharedNormalVector.push_back(0.0f);
sharedNormalVector.push_back(0.0f);
sharedNormalVector.push_back(0.0f);
lineOK = false;
}
}
else if (StringOperations::startsWith(line, "v"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
if (elements.size() == 4)
{
sharedVertexVector.push_back(StringOperations::to<GLfloat>(elements[1], &elementOK));
sharedVertexVector.push_back(StringOperations::to<GLfloat>(elements[2], &elementOK));
sharedVertexVector.push_back(StringOperations::to<GLfloat>(elements[3], &elementOK));
sharedVertexVector.push_back(1.0f);
}
else
{
lineOK = false;
}
}
else if (StringOperations::startsWith(line, "f"))
{
//As soon as the first f occurs, we assume that all vertex
//positions, normals and tex coords have been defined!
break;
}
if (!lineOK)
{
warning() << "Format of line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
lineOK = true;
}
if (!elementOK)
{
warning() << "Element in line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
elementOK = true;
}
++lineNumber;
getline(fileStream, line);
}
bool hasNormals = sharedNormalVector.size() != 3;
if (!hasNormals) {
message() << "The file " << fullFileName << " has no normals!" << std::endl;
}
//By default the number of attributes is 1 (only vertices)
uint_t attributes = 1;
//Then we check for other attributes like normals...
if (hasNormals)
attributes++;
//...or tex coords
if (texCoordDimension > 0)
attributes++;
//By default components is the size of 4, because vertices have 3 components (x,y,z,w)
uint_t components = 4;
//If there are normals we have to add another 3 elements
if (hasNormals)
components += 3;
//We then add the number of tex coord components. This number is 0, if there are none
components += texCoordDimension;
std::vector<GLfloat> interleavedDataVector;
typedef GLuint IndexType;
std::vector<IndexType> indexVector;
//
// read faces:
//
uint_t index = 0;
while (fileStream.good())
{
if (StringOperations::startsWith(line, "f"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
uint_t uiPolygonSize = elements.size() - 1;
if (uiPolygonSize > 2)
{
for(size_t i = 1; i < elements.size(); ++i)
{
if (i > 3)
{
//If we have more than 3 vertices, we have to triangulate in a simple way.
//E.g. for a quad 1234 we should get 123 134.
indexVector.push_back(index - i + 1);
indexVector.push_back(index - 1);
}
indexVector.push_back(index++);
std::vector<std::string> indices = StringOperations::split(elements[i], '/', false);
if (indices.size() == 3 && hasNormals && texCoordDimension > 0)
{
uint_t sharedIndex = StringOperations::to<IndexType>(indices[0], &elementOK);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 2]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 3]);
sharedIndex = StringOperations::to<IndexType>(indices[2], &elementOK);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex]);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex + 2]);
sharedIndex = StringOperations::to<IndexType>(indices[1], &elementOK);
for(uint_t i = 0; i < texCoordDimension; ++i)
interleavedDataVector.push_back(sharedTexCoordVector[texCoordDimension * sharedIndex + i]);
}
else if (indices.size() == 3 && hasNormals)
{
uint_t sharedIndex = StringOperations::to<IndexType>(indices[0], &elementOK);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 2]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 3]);
sharedIndex = StringOperations::to<IndexType>(indices[2], &elementOK);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex]);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedNormalVector[3 * sharedIndex + 2]);
}
else if (indices.size() == 2 && texCoordDimension > 0)
{
uint_t sharedIndex = StringOperations::to<IndexType>(indices[0], &elementOK);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 2]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 3]);
sharedIndex = StringOperations::to<IndexType>(indices[1], &elementOK);
for(uint_t i = 0; i < texCoordDimension; ++i)
interleavedDataVector.push_back(sharedTexCoordVector[texCoordDimension * sharedIndex + i]);
}
else if (indices.size() == 1)
{
uint_t sharedIndex = StringOperations::to<IndexType>(indices[0], &elementOK);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 1]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 2]);
interleavedDataVector.push_back(sharedVertexVector[4 * sharedIndex + 3]);
}
else
{
for(uint_t j = 0; j < components; ++j)
interleavedDataVector.push_back(0.0f);
lineOK = false;
}
}
}
else
{
lineOK = false;
}
}
if (!lineOK)
{
warning() << "Format of line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
lineOK = true;
}
if (!elementOK)
{
warning() << "Element in line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
elementOK = true;
}
++lineNumber;
getline(fileStream, line);
}
fileStream.close();
// flatten interleavedDataVector -> data
uint_t totalIndices = indexVector.size();
float *data = new float[ totalIndices * components ];
for(uint_t ind = 0; ind < totalIndices; ++ind)
{
for(uint_t comp = 0; comp < components; ++comp)
{
data[ind * components + comp] = interleavedDataVector[indexVector[ind] * components + comp];
}
}
geometry->setSize( totalIndices * components * sizeof(float) );
geometry->setData( (GLubyte*)data );
geometry->setStrideSize( components * sizeof(float) );
ArrayBuffer::Attribute apos = { "aPosition", GL_FLOAT, 4, 0, GL_FALSE, 0, GL_FALSE };
geometry->mAttributes.push_back( apos );
if (hasNormals) {
ArrayBuffer::Attribute anorm = { "aNormal", GL_FLOAT, 3, 4*sizeof(float), GL_FALSE, 0, GL_FALSE };
geometry->mAttributes.push_back( anorm );
}
if (texCoordDimension > 0) {
int offset = (hasNormals?7:4);
offset *= sizeof(float);
ArrayBuffer::Attribute atex = { "aTexCoord", GL_FLOAT, (int_t)texCoordDimension, (GLuint) offset, GL_FALSE, 0, GL_FALSE };
geometry->mAttributes.push_back( atex );
}
return true;
*/
}
......@@ -40,6 +40,10 @@ SharedShaderProgram ShaderProgramControlFiles::create(void)
SharedShaderProgram shaderProgram(new ShaderProgram());
std::vector<std::string>::size_type numberOfFiles = mFileNames.size();
if (numberOfFiles == 0) {
Utils::error() << "Can't create ShaderProgram from 0 files!" << std::endl;
return SharedShaderProgram();
}
// some of the files have correct types already, some not yet -> try to guess the rest
for (std::vector<std::string>::size_type file = 0; file < numberOfFiles; ++file) {
......
......@@ -273,9 +273,14 @@ SharedGeometryData loadGeometryDataFromOBJ(const std::string& _filename, bool _c
}
else
{
debug() << "model has no normals, computing face normals" << std::endl;
hasNormals = true;
}
}
if (hasNormals) {
// if the model has normals defined, no face normals have to get computed
_computeNormals = false;
}
// all data are read from the file. construct an ArrayBuffer from the data
data = SharedGeometryData(new GeometryData());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment