Jump to content
  • Advertisement
Sign in to follow this  
Chicki

OpenGL cg Vertex shader - texture problem

This topic is 4757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!