04-11-2003, 04:06 PM

I have been trying to fined examples of the ARB_vertex_program EXT but have had very little success. I have read through the spec.txt and found the example of implement a simple ambient, specular, and diffuse infinite lighting

!!ARBvp1.0

ATTRIB iPos = vertex.position;

ATTRIB iNormal = vertex.normal;

PARAM mvinv[4] = { state.matrix.modelview.invtrans };

PARAM mvp[4] = { state.matrix.mvp };

PARAM lightDir = state.light[0].position;

PARAM halfDir = state.light[0].half;

PARAM specExp = state.material.shininess;

PARAM ambientCol = state.lightprod[0].ambient;

PARAM diffuseCol = state.lightprod[0].diffuse;

PARAM specularCol = state.lightprod[0].specular;

TEMP xfNormal, temp, dots;

OUTPUT oPos = result.position;

OUTPUT oColor = result.color;

# Transform the vertex to clip coordinates.

DP4 oPos.x, mvp[0], iPos;

DP4 oPos.y, mvp[1], iPos;

DP4 oPos.z, mvp[2], iPos;

DP4 oPos.w, mvp[3], iPos;

# Transform the normal to eye coordinates.

DP3 xfNormal.x, mvinv[0], iNormal;

DP3 xfNormal.y, mvinv[1], iNormal;

DP3 xfNormal.z, mvinv[2], iNormal;

# Compute diffuse and specular dot products and use LIT to compute

# lighting coefficients.

DP3 dots.x, xfNormal, lightDir;

DP3 dots.y, xfNormal, halfDir;

MOV dots.w, specExp.x;

LIT dots, dots;

# Accumulate color contributions.

MAD temp, dots.y, diffuseCol, ambientCol;

MAD oColor.xyz, dots.z, specularCol, temp;

MOV oColor.w, diffuseCol.w;

END

I have tried it out but it displays nothing?

I have managed to get the basic example from Nutty site to work so I think all init code is working but I am not sure how to deal with the various attributes/materials?

This is how I draw the triangle:

glEnable(GL_VERTEX_PROGRAM_ARB);

glBindProgramARB(GL_VERTEX_PROGRAM_ARB, my_program);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0f, 0.0f, -140.0f);

glBegin(GL_TRIANGLES);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(0.0f, 100.0f, 0.0f);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(-100.0f, 0.0f, 0.0f);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(100.0f, 0.0f, 0.0f);

glEnd();

glDisable(GL_VERTEX_PROGRAM_ARB);

I think I need to pass in some extra attributes but don’t know witch or how?

Any help/link would be appreciated.

FredFlint.

!!ARBvp1.0

ATTRIB iPos = vertex.position;

ATTRIB iNormal = vertex.normal;

PARAM mvinv[4] = { state.matrix.modelview.invtrans };

PARAM mvp[4] = { state.matrix.mvp };

PARAM lightDir = state.light[0].position;

PARAM halfDir = state.light[0].half;

PARAM specExp = state.material.shininess;

PARAM ambientCol = state.lightprod[0].ambient;

PARAM diffuseCol = state.lightprod[0].diffuse;

PARAM specularCol = state.lightprod[0].specular;

TEMP xfNormal, temp, dots;

OUTPUT oPos = result.position;

OUTPUT oColor = result.color;

# Transform the vertex to clip coordinates.

DP4 oPos.x, mvp[0], iPos;

DP4 oPos.y, mvp[1], iPos;

DP4 oPos.z, mvp[2], iPos;

DP4 oPos.w, mvp[3], iPos;

# Transform the normal to eye coordinates.

DP3 xfNormal.x, mvinv[0], iNormal;

DP3 xfNormal.y, mvinv[1], iNormal;

DP3 xfNormal.z, mvinv[2], iNormal;

# Compute diffuse and specular dot products and use LIT to compute

# lighting coefficients.

DP3 dots.x, xfNormal, lightDir;

DP3 dots.y, xfNormal, halfDir;

MOV dots.w, specExp.x;

LIT dots, dots;

# Accumulate color contributions.

MAD temp, dots.y, diffuseCol, ambientCol;

MAD oColor.xyz, dots.z, specularCol, temp;

MOV oColor.w, diffuseCol.w;

END

I have tried it out but it displays nothing?

I have managed to get the basic example from Nutty site to work so I think all init code is working but I am not sure how to deal with the various attributes/materials?

This is how I draw the triangle:

glEnable(GL_VERTEX_PROGRAM_ARB);

glBindProgramARB(GL_VERTEX_PROGRAM_ARB, my_program);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0f, 0.0f, -140.0f);

glBegin(GL_TRIANGLES);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(0.0f, 100.0f, 0.0f);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(-100.0f, 0.0f, 0.0f);

glNormal3f(0.0f,0.0f,1.0f);

glVertex3f(100.0f, 0.0f, 0.0f);

glEnd();

glDisable(GL_VERTEX_PROGRAM_ARB);

I think I need to pass in some extra attributes but don’t know witch or how?

Any help/link would be appreciated.

FredFlint.