today i tried to create a simple vertex shader … and although i finally got around compiling some glsl code with nvidias cg compiler i’m not quite happy with the results
first: nvidias compiler creates wrong ‘machine code’ (or however those compiled shaders are called)
i found a very simple example on wikipedia.com:
void main(void)
{
gl_Position = ftransform();
}
which should be the simplest vertex program around … using the cg compiler ( with -oglsl -profile arbvp1 parameters ) i get this:
!!ARBvp1.0
# cgc version 1.4.0000, build date Sep 26 2005 22:13:28
# command line args: -v -oglsl -profile arbvp1
# source file: wave.cg
#vendor NVIDIA Corporation
#version 1.0.02
#profile arbvp1
#program main
#semantic gl_ModelViewProjectionMatrixTranspose
#var float4 gl_Vertex : $vin.POSITION : POSITION : -1 : 1
#var float4 gl_Position : $vout.POSITION : HPOS : -1 : 1
#var float4x4 gl_ModelViewProjectionMatrixTranspose : : c[1], 4 : -1 : 1
PARAM c[5] = { program.local[0..4] };
DP4 result.position.w, vertex.position, c[4];
DP4 result.position.z, vertex.position, c[3];
DP4 result.position.y, vertex.position, c[2];
DP4 result.position.x, vertex.position, c[1];
END
# 4 instructions, 0 R-regs
which doesn’t contain any error … but isn’t the correct result
the correct version (and the one that is displaying stuff onscreen) would be:
!!ARBvp1.0
PARAM c[4] = { state.matrix.mvp };
DP4 result.position.w, vertex.position, c[3];
DP4 result.position.z, vertex.position, c[2];
DP4 result.position.y, vertex.position, c[1];
DP4 result.position.x, vertex.position, c[0];
END
any idea if i just have to change some parameters of cgc ?
second: why do i even have to compile the glsl stuff myself?
i searched the web and found some pages that tell the user to let opengl compile the glsl source directly using the method void glCompileShaderARB(GLhandleARB program);
last: i have used this shader stuff for the first time today … so if i have made a capital fault in my approach … please point me at it :-\
Golly