Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

Compiling example code #74

Closed joelcnz closed 8 years ago

joelcnz commented 8 years ago

I don't know what to put for the import thing.

import gl3n.aabb : vec3;

void main() { vec4 v4 = vec4(1.0f, vec3(2.0f, 3.0f, 4.0f)); vec4 v4_2 = vec4(1.0f, vec4(1.0f, 2.0f, 3.0f, 4.0f).xyz); // "dynamic" swizzling with opDispatch vec4 v4_3 = v4_2.xxyz; // opDispatch returns a static array which you can pass directly to the ctor of a vector!

vec3 v3 = my_3dvec.rgb;
vec3 foo = v4.xyzzzwzyyxw.xyz; // not useful but possible!

mat4 m4fv = mat4.translation(-0.5f, -0.54f, 0.42f).rotatex(PI).rotatez(PI/2);
glUniformMatrix4fv(location, 1, GL_TRUE, m4fv.value_ptr); // yes they are row major!

alias Matrix!(double, 4, 4) mat4d;
mat4d projection;
glGetDoublev(GL_PROJECTION_MATRIX, projection.value_ptr);

mat3 inv_view = view.rotation;
mat3 inv_view = mat3(view);

mat4 m4 = mat4(vec4(1.0f, 2.0f, 3.0f, 4.0f), 5.0f, 6.0f, 7.0f, 8.0f, vec4(1,2,3,4), vec4(1,2,3,4)); 

}

Dav1dde commented 8 years ago

I don't understand your question. You want to import vec3? import gl3n.linalg : vec3

joelcnz commented 8 years ago

I want to compile an example program. I was expecting a module called 'import gl3n.all' or some thing.

I tried including all the modules (not counting the ext ones) and got this:

Joels-MacBook-Pro:gl3n joelcnz$ dub Performing "debug" build using dmd for x86_64. gl3n 1.3.1: target for configuration "library" is up to date. game ~master: building configuration "application"... source/app.d(19,2): Error: undefined identifier 'glUniformMatrix4fv' source/app.d(23,2): Error: undefined identifier 'glGetDoublev' source/app.d(25,18): Error: undefined identifier 'view' source/app.d(26,23): Error: undefined identifier 'view' source/app.d(26,2): Error: declaration app.main.inv_view is already defined dmd failed with exit code 1. Joels-MacBook-Pro:gl3n joelcnz$

Here's the code:

import gl3n.linalg; import gl3n.linalg : PI; import gl3n.math; import gl3n.aabb; import gl3n.frustum; import gl3n.interpolate; import gl3n.plane; import gl3n.util;

void main() { vec4 v4 = vec4(1.0f, vec3(2.0f, 3.0f, 4.0f)); vec4 v4_2 = vec4(1.0f, vec4(1.0f, 2.0f, 3.0f, 4.0f).xyz); // "dynamic" swizzling with opDispatch vec4 v4_3 = v4_2.xxyz; // opDispatch returns a static array which you can pass directly to the ctor of a vector!

//vec3 v3 = my_3dvec.rgb;
vec3 foo = v4.xyzzzwzyyxw.xyz; // not useful but possible!

mat4 m4fv = mat4.translation(-0.5f, -0.54f, 0.42f).rotatex(PI).rotatez(PI/2);
glUniformMatrix4fv(location, 1, GL_TRUE, m4fv.value_ptr); // yes they are row major!

alias Matrix!(double, 4, 4) mat4d;
mat4d projection;
glGetDoublev(GL_PROJECTION_MATRIX, projection.value_ptr);

mat3 inv_view = view.rotation;
mat3 inv_view = mat3(view);

mat4 m4 = mat4(vec4(1.0f, 2.0f, 3.0f, 4.0f), 5.0f, 6.0f, 7.0f, 8.0f, vec4(1,2,3,4), vec4(1,2,3,4)); 

}

Dav1dde commented 8 years ago

Importing everything is a code smell that's why there is no gl3n.all module. Furthermore compiling this example doesn't really makes sense, it is just a short overview of what is possible and how you would use it (e.g. glUniformMatrix4fv is an OpenGL function which has per se nothing to do with gl3n).