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
491 stars 72 forks source link

Unable to use glm with Oglplus #92

Closed MaikKlein closed 9 years ago

MaikKlein commented 9 years ago

For some reason I can't use glm with oglplus. This line is giving me some headeach

Uniform<glm::vec2>(prog,"Color").Set(glm::vec2(1.,0.));

/..../oglplus/include/oglplus/interop/glm.hpp:61:1: error: no template named 'tvec2' in namespace 'glm::detail'; did you
      mean 'glm::tvec2'?
OGLPLUS_IMPL_GLM_VEC_UNIFORM_OPS(2)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am compiling with clang 4.5 on linux.

This is the file that is responsible https://github.com/matus-chochlik/oglplus/blob/bd811de7934d59524c2cbff628df34bb70366e50/include/oglplus/interop/glm.hpp#L37

And the complete source code:

#include <iostream>
#include <oglplus/interop/glm.hpp>
#include <GL/glew.h>
#include <oglplus/gl.hpp>
#include <oglplus/all.hpp>
#include <GLFW/glfw3.h>
int main(void)
{
  using namespace oglplus;
  GLFWwindow* window;

  /* Initialize the library */
  if (!glfwInit())
    return -1;

  /* Create a windowed mode window and its OpenGL context */
  window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
  if (!window)
  {
    glfwTerminate();
    return -1;
  }

  /* Make the window's context current */
  glfwMakeContextCurrent(window);
  glewInit();

  Context gl;
  auto s = gl.Version();

  std:: cout << s << std::endl;
  // Vertex shader
  VertexShader vs;
  // Fragment shader
  FragmentShader fs;
  // Program
  Program prog;
  // A vertex array object for the rendered triangle
  VertexArray triangle;
  // VBO for the triangle's vertices
  Buffer verts;
  vs.Source(" \
#version 330\n \
      in vec3 Position; \
      void main(void) \
      { \
      gl_Position = vec4(Position, 1.0); \
      } \
      ");
    // compile it
  try{
    vs.Compile();
  }
  catch(CompileError c){
  std:: cout << c.Log() << std::endl;
  }
  // set the fragment shader source
  fs.Source(" \
#version 330\n \
      uniform vec2 Color; \
      out vec4 fragColor; \
      void main(void) \
      { \
      fragColor = vec4(Color.x,0.0, 1.0, 1.0); \
      } \
      ");
    // compile it
    fs.Compile();
  // attach the shaders to the program
  prog.AttachShader(vs);
  prog.AttachShader(fs);
  // link and use it
  prog.Link();
  prog.Use();
  Uniform<glm::vec2>(prog,"Color").Set(glm::vec2(1.,0.));

  // bind the VAO for the triangle
  triangle.Bind();
  GLfloat triangle_verts[9] = {
    0.0f, 0.0f, 0.0f,
    1.0f, 0.0f, 0.0f,
    0.0f, 1.0f, 0.0f
  };
  // bind the VBO for the triangle vertices
  verts.Bind(Buffer::Target::Array);
  // upload the data
  Buffer::Data(Buffer::Target::Array, 9, triangle_verts);
  // setup the vertex attribs array for the vertices
  VertexArrayAttrib vert_attr(prog, "Position");
  vert_attr.Setup<GLfloat>(3);
  vert_attr.Enable();
  gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  gl.Disable(Capability::DepthTest);
  /* Loop until the user closes the window */
  //u.SetValue(v);

  while (!glfwWindowShouldClose(window))
  {
    /* Render here */

    /* Swap front and back buffers */
    glfwSwapBuffers(window);

    /* Poll for and process events */
    gl.Clear().ColorBuffer();
    gl.DrawArrays(PrimitiveType::Triangles, 0, 3);
    glfwPollEvents();
  }

  glfwTerminate();
  return 0;
}
matus-chochlik commented 9 years ago

Hi, which version of GLM are you using ?

MaikKlein commented 9 years ago

I am on the newest master https://github.com/g-truc/glm

The error really confuses me because there definitely is a tvec2 template in glm::detail.

I just tried

  using myvec2 = glm::detail::tvec2<float,glm::precision::mediump>;
  myvec2 v(1.0,0.0);
  Uniform<myvec2>(prog,"Color").Set(v);

I also tried to use some older versions of glm, but I can't go lower than 0.9.5 because it seems the file order has changed since then.

MaikKlein commented 9 years ago

Okay solved it. I had accidentally two versions of glm installed which confused me. The easy fix is s/detail:://g in https://github.com/matus-chochlik/oglplus/blob/bd811de7934d59524c2cbff628df34bb70366e50/include/oglplus/interop/glm.hpp

That is of course if you want to update to the newest version of glm otherwise I am going to fork it. Do you want to patch it yourself or should I make a patch?

MaikKlein commented 9 years ago

94

matus-chochlik commented 9 years ago

Thanks, for the patch. If I find some reliable way of detecting GLM version I'll probably add some #ifdefs to use the old definition where applicable.