Question

I am converting some code from HSLSL and XNA to CG and OpenGL.

The code is for rendering volume data. But volume data is not also sampled using the same distance in each dimension, for example (0.9f, 1f, 1f). So a scale factor need to be applied.

In the XNA and HLSL example, they do the following:

mul(input.Position * ScaleFactor, WorldViewProj);

Where WorldViewProj is passed into the shader.

In OpenGL, I was under the impression that glstate.matrix.mvp was ModelViewProjection, where ModelView is World * View. Clearly I am wrong as when I do the following, nothing is drawn.

output.Position = mul( input.Position * scale, glstate.matrix.mvp);

The volume is been rendered with glMatrixMode set to GL_MODELVIEW. Will I have to create my own matrices? If so, any good tutorials? :D

Was it helpful?

Solution

The volume is been rendered with glMatrixMode set to GL_MODELVIEW. Will I have to create my own matrices? If so, any good tutorials? :D

glMatrixMode is kind of like a with statement for the other matrix manipulation functions. So

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate(...);

is to be interpreted like

modelview_matrix.load_identity();
modelview_matrix.translate(...);

and so on.

Furthermore see the answer of @Tobias Schlegel. Shaders get their "constant" input in form of so called Uniforms. Older versions of OpenGL pass on the fixed function state, like the modelview matrix. Newer OpenGL versions (OpenGL-3 core and later) depreceated all the built in matrix manipulation stuff. Instead the user is expected to keep track of the transformation piple and to supply all required matrices through self defined uniforms. This also allows to emulate the DirectX behaviour.

OTHER TIPS

In the fixed function pipeline openGl and DirectX differ in the way they define spaces. OpenGl only has a Model- and a View-space, hence a ModelViewMatrix. In DX there is also a World-space. Models are translated from Model-space into World-space and then into View-space.

However, in this case i think that you can treat Model and View-space as equal. That would be the case if your model is centered in the World (making the Model->World translation a non-operation).

When using shaders you are basically free to do whatever you want and use the spaces you want.

Also DX uses row-major and openGl column-major matrix-representations. So if you copy DX examples you have to transpose the matrices and reverse the order of matrix-operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top