# Vertex Program help!

I am trying to do something very simple using vertex programs but some weird things are happening.

## I have the following calls:

glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,1,U.x,U.y,U.z,1);
glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB,2,V.x,V.y,V.z,1);

(…) /* glBegin, etc. */

## and I just want to do a very simple calculation: the new vertex position will be equal to ecenter.xU+ecenter.yV. This is my code:

!!ARBvp1.0
PARAM U = program.env[1];
PARAM V = program.env[2];
PARAM mvp[4] = { state.matrix.mvp };

ATTRIB pos = vertex.position;
ATTRIB color = vertex.color;
ATTRIB intexcoord = vertex.texcoord;
ATTRIB ecenter = vertex.attrib[20];

OUTPUT opos = result.position;
OUTPUT outcolor = result.color;
OUTPUT outtexcoord = result.texcoord;

TEMP tmp1,tmp2,npos;

# npos = ecenter.x * U + ecenter.y * V

MUL tmp1,ecenter.x,U;
MUL tmp2,ecenter.y,V;

DP4 opos.x, mvp[0], npos;
DP4 opos.y, mvp[1], npos;
DP4 opos.z, mvp[2], npos;
DP4 opos.w, mvp[3], npos;

MOV outcolor, color;
MOV outtexcoord,intexcoord;

## END

I am still not using vertex.position, vertex.color.secondary and other parameters because I will use them as soon as I fix this simple problem. The final computation will be much more complex.

Any ideas?

[This message has been edited by chracatoa (edited 06-03-2003).]

… and what exactly is the problem?

It just doesn’t work… the result should be a checkboard pattern, but instead it’s like a pencil of dotted lines coming from a point…

However, if I disable GL_VERTEX_PROGRAM and use this instead:

P3d newp = ecenter.xU+ecenter.yV;
glVertex3f(newp.x,newp.y,newp.z);

it works!

ATTRIB ecenter = vertex.attrib[20];

This tells a lot. Now, granted, I’m not 100% familiar with ARB_vp syntax, but, if I understand correctly, you’re asking for the 20th vertex attribute. Of course, there are only 16 per-vertex attributes avalible. I don’t know how the program is compiling.

Now, let’s assume that this isn’t the problem, and I’m simply interpreting it incorrectly. It’s still a generic attribute, that you’re using along-side non-generic attributes (glVertex, glColor, etc). So, I’ve got to ask: are you send the attribute properly? Also, are you sending it in an index that might alias with a non-generic attribute? Which attribute index are you using to send your generic data?

Originally posted by Korval:
Of course, there are only 16 per-vertex attributes avalible.

Just changed it to 10 and I still have the problem… The only attributes/parameters I am using now are those in the program and they don’t alias.

Anyway, even if I don’t use any generic attribute and send ecenter.x and ecenter.y as:

glVertex3f(ecenter.x,ecenter.y,0);

and change the vertex program:
MUL tmp1,pos.x,U;
MUL tmp2,pos.y,V;

It still doesn’t work. I could bet that the error is very simple, perhaps due to some misunderstanding of my part of how MUL works. But at this point I can’t see it.

Are you calling glGetError() after loading the vertex program? Did it come back with no error?

assert( !glGetError() ); // sprinkle liberally all over your code

Originally posted by jwatte:
Are you calling glGetError() after loading the vertex program? Did it come back with no error?

Yes, no errors after loading the program. If there is any compilation error my program halts.

## By the way, if I do this:

TEMP ex,ey;

MOV ex.x,ecenter.x;
MOV ex.y,ecenter.x;
MOV ex.z,ecenter.x;
MOV ex.w,1.0;

MOV ey.x,ecenter.y;
MOV ey.y,ecenter.y;
MOV ey.z,ecenter.y;
MOV ey.w,1.0;