13 #include <Eigen/OpenGLSupport> 15 using namespace Eigen;
20 #define VERIFY_MATRIX(CODE,REF) { \ 23 Matrix<float,4,4,ColMajor> m; m.setZero(); \ 24 glGet(GL_MODELVIEW_MATRIX, m); \ 25 if(!(REF).cast<float>().isApprox(m)) { \ 26 std::cerr << "Expected:\n" << ((REF).cast<float>()) << "\n" << "got\n" << m << "\n\n"; \ 28 VERIFY_IS_APPROX((REF).cast<float>(), m); \ 31 #define VERIFY_UNIFORM(SUFFIX,NAME,TYPE) { \ 32 TYPE value; value.setRandom(); \ 34 int loc = glGetUniformLocation(prg_id, #NAME); \ 35 VERIFY((loc!=-1) && "uniform not found"); \ 36 glUniform(loc,value); \ 37 EIGEN_CAT(glGetUniform,SUFFIX)(prg_id,loc,data.data()); \ 38 if(!value.isApprox(data)) { \ 39 std::cerr << "Expected:\n" << value << "\n" << "got\n" << data << "\n\n"; \ 41 VERIFY_IS_APPROX(value, data); \ 44 #define VERIFY_UNIFORMi(NAME,TYPE) { \ 45 TYPE value = TYPE::Random().eval().cast<float>().cast<TYPE::Scalar>(); \ 47 int loc = glGetUniformLocation(prg_id, #NAME); \ 48 VERIFY((loc!=-1) && "uniform not found"); \ 49 glUniform(loc,value); \ 50 glGetUniformiv(prg_id,loc,(GLint*)data.data()); \ 51 if(!value.isApprox(data)) { \ 52 std::cerr << "Expected:\n" << value << "\n" << "got\n" << data << "\n\n"; \ 54 VERIFY_IS_APPROX(value, data); \ 59 int infologLength, charsWritten;
61 glGetProgramiv(objectID,GL_INFO_LOG_LENGTH, &infologLength);
64 infoLog =
new GLchar[infologLength];
65 glGetProgramInfoLog(objectID, infologLength, &charsWritten, infoLog);
67 std::cerr <<
"Shader info : \n" << infoLog << std::endl;
74 GLint prg_id = glCreateProgram();
75 GLint vtx_id = glCreateShader(GL_VERTEX_SHADER);
76 GLint frg_id = glCreateShader(GL_FRAGMENT_SHADER);
79 glShaderSource(vtx_id, 1, &vtx, 0);
80 glCompileShader(vtx_id);
81 glGetShaderiv(vtx_id,GL_COMPILE_STATUS,&ok);
84 std::cerr <<
"vtx compilation failed\n";
87 glShaderSource(frg_id, 1, &frg, 0);
88 glCompileShader(frg_id);
89 glGetShaderiv(frg_id,GL_COMPILE_STATUS,&ok);
92 std::cerr <<
"frg compilation failed\n";
95 glAttachShader(prg_id, vtx_id);
96 glAttachShader(prg_id, frg_id);
97 glLinkProgram(prg_id);
98 glGetProgramiv(prg_id,GL_LINK_STATUS,&ok);
101 std::cerr <<
"linking failed\n";
105 glUseProgram(prg_id);
113 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
114 glutInitWindowPosition (0,0);
115 glutInitWindowSize(10, 10);
117 if(glutCreateWindow(
"Eigen") <= 0)
119 std::cerr <<
"Error: Unable to create GLUT Window.\n";
123 glewExperimental = GL_TRUE;
124 if(glewInit() != GLEW_OK)
126 std::cerr <<
"Warning: Failed to initialize GLEW\n";
140 Matrix4f mf44; mf44.setRandom();
143 Matrix4d md44; md44.setRandom();
181 Vector2f vf2; vf2.setRandom(); Vector3f vf23; vf23 << vf2, 0;
183 Vector2d vd2; vd2.setRandom(); Vector3d vd23; vd23 << vd2, 0;
186 Vector3f vf3; vf3.setRandom();
188 Vector3d vd3; vd3.setRandom();
200 Vector2f vf2; vf2.setRandom(); Vector3f vf23; vf23 << vf2, 1;
202 Vector2d vd2; vd2.setRandom(); Vector3d vd23; vd23 << vd2, 1;
205 Vector3f vf3; vf3.setRandom();
207 Vector3d vd3; vd3.setRandom();
219 const char* vtx =
"void main(void) { gl_Position = gl_Vertex; }\n";
223 #ifdef GL_VERSION_2_0 225 "uniform vec2 v2f;\n" 226 "uniform vec3 v3f;\n" 227 "uniform vec4 v4f;\n" 228 "uniform ivec2 v2i;\n" 229 "uniform ivec3 v3i;\n" 230 "uniform ivec4 v4i;\n" 231 "uniform mat2 m2f;\n" 232 "uniform mat3 m3f;\n" 233 "uniform mat4 m4f;\n" 234 "void main(void) { gl_FragColor = vec4(v2f[0]+v3f[0]+v4f[0])+vec4(v2i[0]+v3i[0]+v4i[0])+vec4(m2f[0][0]+m3f[0][0]+m4f[0][0]); }\n";
250 std::cerr <<
"Warning: opengl 2.0 was not tested\n";
254 #ifdef GL_VERSION_2_1 255 const char* frg =
"#version 120\n" 256 "uniform mat2x3 m23f;\n" 257 "uniform mat3x2 m32f;\n" 258 "uniform mat2x4 m24f;\n" 259 "uniform mat4x2 m42f;\n" 260 "uniform mat3x4 m34f;\n" 261 "uniform mat4x3 m43f;\n" 262 "void main(void) { gl_FragColor = vec4(m23f[0][0]+m32f[0][0]+m24f[0][0]+m42f[0][0]+m34f[0][0]+m43f[0][0]); }\n";
282 std::cerr <<
"Warning: opengl 2.1 was not tested\n";
286 #ifdef GL_VERSION_3_0 287 const char* frg =
"#version 150\n" 288 "uniform uvec2 v2ui;\n" 289 "uniform uvec3 v3ui;\n" 290 "uniform uvec4 v4ui;\n" 292 "void main(void) { data = vec4(v2ui[0]+v3ui[0]+v4ui[0]); }\n";
306 std::cerr <<
"Warning: opengl 3.0 was not tested\n";
308 #ifdef GLEW_ARB_gpu_shader_fp64 309 if(GLEW_ARB_gpu_shader_fp64)
311 #ifdef GL_ARB_gpu_shader_fp64 312 const char* frg =
"#version 150\n" 313 "uniform dvec2 v2d;\n" 314 "uniform dvec3 v3d;\n" 315 "uniform dvec4 v4d;\n" 317 "void main(void) { data = vec4(v2d[0]+v3d[0]+v4d[0]); }\n";
321 typedef Vector2d Vector2d;
322 typedef Vector3d Vector3d;
323 typedef Vector4d Vector4d;
331 std::cerr <<
"Warning: GLEW_ARB_gpu_shader_fp64 was not tested\n";
333 std::cerr <<
"Warning: GLEW_ARB_gpu_shader_fp64 was not tested\n";
Translation< double, 3 > Translation3d
EIGEN_DEVICE_FUNC const VectorType & vector() const
AngleAxis< double > AngleAxisd
#define VERIFY_UNIFORMi(NAME, TYPE)
Translation< float, 3 > Translation3f
#define VERIFY_MATRIX(CODE, REF)
UniformScaling< float > Scaling(float s)
Represents a translation transformation.
void printInfoLog(GLuint objectID)
void test_openglsupport()
#define VERIFY_UNIFORM(SUFFIX, NAME, TYPE)
AngleAxis< float > AngleAxisf
GLint createShader(const char *vtx, const char *frg)
Transform< float, 3, Projective > Projective3f
The quaternion class used to represent 3D orientations and rotations.
The matrix class, also used for vectors and row-vectors.
Derived & setRandom(Index size)
Transform< double, 3, Projective > Projective3d