master2k's picture

3Dobject to 2D Space Flatshading

hi there, i've some random objects like mousecursor or text aligned to the Z axis (correct direction), now i want flatshade it into my 2d orthographic projection

i set it up like:

Matrix4.CreateOrthographic(ClientRectangle.Width,ClientRectangle.Height, 0, 1, out projectionMatrix2D);
then i uniform bind that matrix as projection matrix to the shader, (+ translate , rotate and scale)

my vertexshader out :

gl_Position = projection_matrix* vec4(in_position.x,in_position.y,1,1).xyzw;

the problem is it doenst work at all (i see nothing), but i get no errors also,

if i set the orthographic to znear 0, zfar 3500, rotate my object a little bit this shader starts working, translation is correct with my mousecursor, color working fine, .. but the object output doenst euqal my 3d object (flatshaded).
but if i set it up with (correct?) zn0,zf1 i get nothing (not even a little bit on my screen) ...

I had this same code working in ogl 2-, but now i need it with the vertexshader, i've still no clue what i'm doing wrong.

The objects and texture is loaded up correctly because if i render it in 3d space all is fine.

add 27.04.2011:

i know there's a rotation problem, but i tried all rotations and nothing is displayed like it should be, if i use the orthogonal projection matrix together with my modelview matrix (instead the usual projection matrix) the orthogonal matrix work, my objects (front) is pointing in the positive Z direction, could that be wrong? ( i added a pic with x,y viel, front is +z and back is -z , it seems like it won't render all i want to display, the usual things like disabling zbuffer etc. dont work

;can be closed, i've done a solution but still not the best, i created a new standard modelview matrix, and used together modelview2d and orthogonal projection2d matrix, the result is exactly what i needed, some rotation issue / invertion, but i'll get that to work, so thx anyways for reading this post.

result is in the third screenshot below. (that the z rotation will be wrong is what i expected), nothing to not getting fixed,

regards M2k

Inline Images
flatshading to 2D