# Opengl shader matrix computation problem

Hi everybody, i am having hard times converting some code into opengl shaders since i am about to convert a big bulk of previous code into glsl.
My problem is the following:
when i pass the matrices ( sp?? ) in the vertex shader and do the computation like this :

gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position ;

everything works fine

so my idea is to move the matrix calculation away from the vertex shader and perform the computation entirely on the cpu since the matrix doesn’ changes trhough all the vertices sent to the graphics card

so i do something like this :

gl_Position = (ProjViewModelMatrix) * in_Position ;

the ProjViewModelMatrix is computed entirely on the CPU and i pass it trhough an uniform , the problem is that i get a blank screen if i use the simplest matrix possibile like this :

float s=1.0f

p[ 0]=s; p[ 1]=0; p[ 2]=0; p[ 3]=0;
p[ 4]=0; p[ 5]=s; p[ 6]=0; p[ 7]=0;
p[ 8]=0; p[ 9]=0; p=s; p=0;
p=0; p=0; p=0; p=1;

the model is drawn correctly but without a projection of course, but let’s
perform a simple translation, this means that p=x, p=y,p= z;
now, if i put a value different from 1 in the p entry i get a blank screen
since the model is drawn away from the observer
how can i solve this problem ?
But better yet, how can i correctly perform computation to match the built in glsl matrix computations ?
i have looked around for tutorial but they always use the built in glsl matrix computations , i haven’t seen anyone doing the computation on the cpu , at least not in a public forum or site.
Thanks for any suggestion i am driving nuts.

You can use glm math library to aid in matrix stuff. Details here. http://glm.g-truc.net/

For tutorials using this library and how to do all that math in a custom matrix library, check these tutorials esp the opengl3.3 versions.
http://www.spacesimulator.net/wiki/index.php/3d_Engine_Programming_Tutorials

These are my favourite replies : use a library
i’d like to know where is my mystake, using a library doesn’t solve the problem in my opinion, unless you want to copy and paste code and tell you have done it.
Do you have some consistent advice or do you want to propose another library ?

If you are not happy with the answer it’s one thing but being harsh with others is another thing.

If you don’t want to use a library, refresh your linear algebra skills. Also, double-check your matrix representation (tip: you may confuse column- and row major order).

If u had read my post completely u would have seen the link to the tutorials. These tutorials go in great depth to tell u how u make these routines both using glm library and a custom written matrix library. Check the code given there for details.

AS for your code, could be a lot of issues as aqnuep pointed out, handedness might be one of them. Another thing might be that the order of multiplication is wrong but not much can be said unless some more info is given.