matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
492 stars 72 forks source link

conversion of initializer list argument to const GLchar** not possible #124

Closed Eckart23 closed 8 years ago

Eckart23 commented 8 years ago

When using this line "shape = ShapeWrapperPtr(new shapes::ShapeWrapper" , I get the error: no matching constructor for initialization of 'shapes::ShapeWrapper'. In the wrapper.hpp, the error says that the candidate constructor is not viable because the conversion of initiazer list argument to const GLchar\ is not possible. I'm compiling on osx 10.11. with the xcode standard compiler. Do you know why I get this error?

matus-chochlik commented 8 years ago

Hi could You please paste the whole code? How is for example the ShapeWrapperPtr defined ?

Eckart23 commented 8 years ago

Hi, thanks for your reply! I'm trying to set up code from this project: https://github.com/OculusRiftInAction/OculusRiftInAction, which uses oglplus. My errors occurs in the attached code. Thanks in advance!

include "Common.h"

include <oglplus/shapes/plane.hpp>

Resource SCENE_IMAGES_DK1[2] = { Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK1_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK1_PNG };

Resource SCENE_IMAGES_DK2[2] = { Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK2_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK2_PNG };

class UndistortedExample : public RiftGlfwApp {

protected: TexturePtr textures[2]; ProgramPtr program; ShapeWrapperPtr shape;

public: virtual ~UndistortedExample() { }

void initGl() { using namespace oglplus; RiftGlfwApp::initGl(); Context::Disable(Capability::Blend); Context::Disable(Capability::DepthTest); Context::Disable(Capability::CullFace);

program = oria::loadProgram(
    Resource::SHADERS_TEXTURED_VS,
    Resource::SHADERS_TEXTURED_FS);
shape = ShapeWrapperPtr(new shapes::ShapeWrapper({ "Position", "TexCoord" }, shapes::Plane(
    Vec3f(1, 0, 0),
    Vec3f(0, 1, 0)
  ), *program));

Resource * sceneImages = SCENE_IMAGES_DK2;
if (hmd->Type == ovrHmd_DK1) {
  sceneImages = SCENE_IMAGES_DK1;
}

for_each_eye([&](ovrEyeType eye) {
  textures[eye] = oria::load2dTexture(sceneImages[eye]);
});

}

virtual void shutdownGl() { program.reset(); shape.reset(); for_each_eye([&](ovrEyeType eye) { textures[eye].reset(); }); RiftGlfwApp::shutdownGl(); }

void draw() { using namespace oglplus;

DefaultFramebuffer().Bind(Framebuffer::Target::Draw);
Context::Clear().ColorBuffer();
for_each_eye([&](ovrEyeType eye) {
  renderEye(eye);
});

}

void renderEye(ovrEyeType eye) { viewport(eye); // Stacks::modelview().identity().rotate(HALF_PI, Vectors::X_AXIS); textures[eye]->Bind(oglplus::Texture::Target::_2D); oria::renderGeometry(shape, program); } };

include "Common.h"

include <oglplus/shapes/plane.hpp>

Resource SCENE_IMAGES_DK1[2] = { Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK1_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK1_PNG };

Resource SCENE_IMAGES_DK2[2] = { Resource::IMAGES_TUSCANY_UNDISTORTED_LEFT_DK2_PNG, Resource::IMAGES_TUSCANY_UNDISTORTED_RIGHT_DK2_PNG };

class UndistortedExample : public RiftGlfwApp {

protected: TexturePtr textures[2]; ProgramPtr program; ShapeWrapperPtr shape;

public: virtual ~UndistortedExample() { }

void initGl() { using namespace oglplus; RiftGlfwApp::initGl(); Context::Disable(Capability::Blend); Context::Disable(Capability::DepthTest); Context::Disable(Capability::CullFace);

program = oria::loadProgram(
    Resource::SHADERS_TEXTURED_VS,
    Resource::SHADERS_TEXTURED_FS);
shape = ShapeWrapperPtr(new shapes::ShapeWrapper({ "Position", "TexCoord" }, shapes::Plane(
    Vec3f(1, 0, 0),
    Vec3f(0, 1, 0)
  ), *program));

Resource * sceneImages = SCENE_IMAGES_DK2;
if (hmd->Type == ovrHmd_DK1) {
  sceneImages = SCENE_IMAGES_DK1;
}

for_each_eye([&](ovrEyeType eye) {
  textures[eye] = oria::load2dTexture(sceneImages[eye]);
});

}

virtual void shutdownGl() { program.reset(); shape.reset(); for_each_eye([&](ovrEyeType eye) { textures[eye].reset(); }); RiftGlfwApp::shutdownGl(); }

void draw() { using namespace oglplus;

DefaultFramebuffer().Bind(Framebuffer::Target::Draw);
Context::Clear().ColorBuffer();
for_each_eye([&](ovrEyeType eye) {
  renderEye(eye);
});

}

void renderEye(ovrEyeType eye) { viewport(eye); // Stacks::modelview().identity().rotate(HALF_PI, Vectors::X_AXIS); textures[eye]->Bind(oglplus::Texture::Target::_2D); oria::renderGeometry(shape, program); } };

RUN_OVR_APP(UndistortedExample)

matus-chochlik commented 8 years ago

OK, could You check how is the OGLPLUS_NO_INITIALIZER_LISTS preprocessor symbol defined?

Eckart23 commented 8 years ago

ifndef OGLPLUS_NO_INITIALIZER_LISTS

if defined(BOOST_NO_CXX11_INITIALIZER_LISTS) ||\

defined(BOOST_NO_INITIALIZER_LISTS)

define OGLPLUS_NO_INITIALIZER_LISTS 1

else

define OGLPLUS_NO_INITIALIZER_LISTS 0

endif

endif

matus-chochlik commented 8 years ago

Yeah, I know :) but what is the actual value defined when you compile the source. Either it it defined as 1 and then the initializer list constructors are undefined or it is 0 and there is some other problem. Maybe GLchar is something different than char on MacOSX ?

Eckart23 commented 8 years ago

When I compile it, it is defined as 1.

matus-chochlik commented 8 years ago

OK, this means that the detection of support for initializer lists for some reason thought that initializer lists don't work properly. You can try to #define OGLPLUS_NO_INITIALIZER_LISTS 0 before including oglplus headers to manually enable initialize_list-related feature. You could also try to compile the file ./config/cpp/has_INITIALIZER_LISTS.cpp to see why the compiler failed to detect support for ILs.

HTH

Eckart23 commented 8 years ago

Unfortunatly, even with doing #define OGLPLUS_NO_INITIALIZER_LISTS 0 the program compiles but then crashes. I have done ./config/cpp/has_INITIALIZER_LISTS.cpp and got:

./config/cpp/has_INITIALIZER_LISTS.cpp: line 1: /Applications: is a directory ./config/cpp/has_INITIALIZER_LISTS.cpp: line 2: CHANGELOG: command not found ./config/cpp/has_INITIALIZER_LISTS.cpp: line 3: syntax error near unexpected token (' ./config/cpp/has_INITIALIZER_LISTS.cpp: line 3: * Software License, Version 1.0. (See accompanying file'

matus-chochlik commented 8 years ago

Hmm .. You have to compile the ./config/cpp/has_INITIALIZER_LISTS.cpp file with the compiler.

Eckart23 commented 8 years ago

Oh yes, obviously. This tells me: ./config/cpp/has_INITIALIZER_LISTS.cpp:12:21: error: expected expression std::vector v({0,1,2,3,4,5,6,7,8,9}};

matus-chochlik commented 8 years ago

Did You also specify the -std=c++11 option to the compiler?

Eckart23 commented 8 years ago

Yes, it seems to give me an empty output.

matus-chochlik commented 8 years ago

And if You manually define OGLPLUS_NO_INITIALIZER_LISTS to 0 then the program crashes where? (You for example dereference the program pointer, is it valid?)

Eckart23 commented 8 years ago

It crashes at this position:
ObjectName(const ObjectName& that) OGLPLUS_NOEXCEPT(true) : _name(that._name) { }

in the name_tpl.hpp file. I have not yet dereferenced the program pointer.

matus-chochlik commented 8 years ago

Could You step through it in a debugger and see in what context is that ObjectName constructor called ?

Eckart23 commented 8 years ago

With the debugger I stepped back to:

shape = ShapeWrapperPtr(new shapes::ShapeWrapper({ "Position", "TexCoord" }, shapes::Plane( Vec3f(1, 0, 0), Vec3f(0, 1, 0) ), *program));

matus-chochlik commented 8 years ago

Then the *program must have been dereferenced, since the {"Position", "TexCoord"} is an initializer list, shapes::Plane does not store any internal object which would have an ObjectName and the third argument is the pointer and all arguments must be evaluated prior to calling the ShapeWrapper constructor.

Eckart23 commented 8 years ago

Yes, this was the mistake. It's now running perfectly! Many thanks for your friendly help!

matus-chochlik commented 8 years ago

No problem! I'm glad it works.