I need to access the OpenGL state variables (such as the MVP matrices) in my Cg shader program. I'm passing these values to my Cg shader program manually using calls such as cgGLSetStateMatrixParameter() in my C/C++ code. Is there an easier way to do this?
+2
A:
If you are on any fairly recent Cg profile (arbvp1 and later), your Cg shader programs can in fact access the OpenGL state (MVP matrices, material and light settings) directly. This makes writing those programs less painful.
Here are some of the state variables which can be accessed:
MVP matrices of all types:
state.matrix.mvp
state.matrix.inverse.mvp
state.matrix.modelview
state.matrix.inverse.modelview
state.matrix.modelview.invtrans
state.matrix.projection
state.matrix.inverse.projection
Light and material properties:
state.material.ambient
state.material.diffuse
state.material.specular
state.light[0].ambient
For the full list of state variables, refer to the section Accessing OpenGL State, OpenGL ARB Vertex Program Profile (arbvp1) in the Cg Users Manual.
Note:
- All the OpenGL state variables are of uniform type when accessed in Cg.
- For light variables, the index is mandatory. (Eg: 1 in state.light[1].ambient)
- Lighting or light(s) need not be enabled to use those corresponding light values inside Cg. But, they need to be set using glLight() functions.
Ashwin
2008-08-18 09:11:13