cg Vertex shader - texture problem

Started by
2 comments, last by Chicki 18 years, 7 months ago
hi, i am very new to cg shaders, and have some problems: i tried to write a simple vertex shader, who does nearly the same as if there was no own shader activ... here what i did : struct input { float4 pos : POSITION; float4 color : COLOR0; float4 tex : TEXCOORD0; }; struct output { float4 pos : POSITION; float4 color : COLOR0; float4 tex : TEXCOORD0; }; output main(input IN,uniform float4x4 ModelViewProj) { output OUT; OUT.pos = mul(ModelViewProj, IN.pos); OUT.color = IN.color; OUT.tex = IN.tex; return OUT; } now the problem is, that i got a grey object without any texture... i am setting the texturecoords with standard opengl commands: "glTexCoord2f(u,v);" etc. doesnt that mean, that i get them in IN.tex? or must i used special CG commands to set the texturecoords? cause i get the vertex position, also without using special CG commands, only by "glVertex3f", so i thought it would be the same with texturecoords and color... p.s. i am not using an own fragment shader... p.p.s. the only parameter i am setting from "outside" the vertex shader is "ModelViewProj" thx for help
Advertisement
It might be because your using float4 when your only using 2d texture coordinates. also same goes for the position (though 3d)

try...

struct input {
float3 pos : POSITION;
float4 color : COLOR0;
float2 tex : TEXCOORD0;
};

struct output {
float4 pos : POSITION;
float4 color : COLOR0;
float2 tex : TEXCOORD0;
};

output main(input IN,uniform float4x4 ModelViewProj)
{
output OUT;

OUT.pos = mul(ModelViewProj, float4( IN.pos.xyz, 1.0 ));

OUT.color = IN.color;
OUT.tex = IN.tex;

return OUT;
}
Quote:Original post by wrathfilledhate
It might be because your using float4 when your only using 2d texture coordinates. also same goes for the position (though 3d)
That shouldn't matter, but I suppose it's worth a shot if nothing else works.

Are you sure your texture is being created correctly? You can see the texture fine if you don't enable the vertex shader?
ok i tried that one with the floats, but didnt change anything
(so float3 for position wont work at all , cause i am multiplying with a 4x4 matrix)

and yes it does work , if i disable the shader...
tested it with different textures and object...

and here are my opengl calls:


//INIT

cgContext = cgCreateContext();

cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);

cgGLSetOptimalOptions(cgVertexProfile);

cgProgram = cgCreateProgramFromFile(cgContext, CG_SOURCE, "shader.cg", cgVertexProfile, "main", 0);

cgGLLoadProgram(cgProgram);

ModelViewProjParam = cgGetNamedParameter(cgProgram, "ModelViewProj");




//DRAW function

cgGLBindProgram(cgProgram);

cgGLSetStateMatrixParameter(ModelViewProjParam,CG_GL_MODELVIEW_PROJECTION_MATRIX,CG_GL_MATRIX_IDENTITY);

cgGLEnableProfile(cgVertexProfile);


//object...

cgGLDisableProfile(cgVertexProfile);



so the vertexes are shown correct i think initialiazing worked...

This topic is closed to new replies.

Advertisement