PDA

View Full Version : problems with cg:texture lookup


k.arts
06-26-2005, 11:42 AM
Hi there!
I have searched the forum for my problem but did not found any solution, so here I am:
I try a texture lookup with cg in this way:

OUT.color = tex2D(UsedTex, float2(texCoord.x + 1.0f/128.0f, texCoord.y - 10.0f/128.0f));

(I have got a texture with size 128,128 applied to a rectangle with 128,128, applied with opengl like this:
glBegin(GL_QUADS);
glTexCoord2i(0,0);
glVertex2i(0,0);
glTexCoord2i(1,0);
glVertex2i(128,0);
glTexCoord2i(1,1);
glVertex2i(128,128);
glTexCoord2i(0,1);
glVertex2i(0,128);
glEnd();

This works fine.
But when I try something like this:
int OwnPos = int(texCoord.x * 128.0f);
for (int i = 0; i < 10; i++)
if (i == OwnPos)
OUT.color = tex2D(UsedTex, float2((float)i/128.0f+ 1.0f/128.0f, texCoord.y - 10.0f/128.0f));
return OUT;
it does not work. I get back pixels, but they are not read from the appropriate position.
I checked OwnPos, it is the right value..
By the way
tex2D(UsedTex, float2((float)OwnPos/128.0f+ 1.0f/128.0f, texCoord.y - 10.0f/128.0f));
did not work, (Compiler Error) I think because the Compiler could not determine if OwnPos is correct
Am I missing something? I think the problem for cg is that it is not possible to use variables in tex2D... hope that is not true
I tried with CG_PROFILE_FP40 and CG_PROFILE_ARBFP1.

Any help would be fine!
Thanx
PS: I know that this example is a little bit stupid...

k.arts
07-05-2005, 09:23 AM
Ok I have found that error. Perhaps someone encountered the same, thus I am posting my solution. Very easy thing of course (if you know how...)
I have not initialized the textures the right way (OpenGL).
It has to be this:
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST );
and I had it like this:
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );

So I read out the right posiition but the values were linearly adjusted. This did not happen, when I used the given coordinates. Don't know why, but now it works.

That's ist :banghead:

CGTalk Moderation
07-05-2005, 09:23 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.