PDA

View Full Version : Vertex Program (NV) problems



bakery2k
05-03-2002, 11:38 AM
I have a simple program i am using to try and use vertex programs. With vertex programming disabled, a torus is displayed, however with it enabled, nothing appears. What am I doing wrong?

My vertex program is stored in a .txt file:



!!VP1.0
# c[0]-c[3] modelviewProjection matrix

# compute position
DP4 o[HPOS].x, c[0], v[OPOS];
DP4 o[HPOS].y, c[1], v[OPOS];
DP4 o[HPOS].z, c[2], v[OPOS];
DP4 o[HPOS].w, c[3], v[OPOS];

MOV o[COL0], c[1];

END


And is loaded in with:




//generate a vertex program
glGenProgramsNV(1, &vp);
if(!vp)
{
printf("Unable to create a vertex program object");
return false;
}
glBindProgramNV(GL_VERTEX_PROGRAM_NV, vp);

//load from file
ifstream vpFile("vp.txt", ios::in | ios::nocreate);
if(vpFile.fail())
{
printf("Unable to open vertex program");
return false;
}

//calculate the size of the file
vpFile.seekg(0, ios::end);
int vpSize=vpFile.tellg();
vpFile.seekg(0, ios::beg);

//allocate memory
unsigned char * vpText=new unsigned char[vpSize];
if(!vpText)
{
printf("Unable to allocate space for vertex program text");
return false;
}

//read file
memset(vpText, 0, vpSize);
vpFile.read(vpText, vpSize);
vpFile.close();

printf("Vertex Program:\n\n%s\n\n", vpText);

//load program
glLoadProgramNV(GL_VERTEX_PROGRAM_NV, vp, vpSize, vpText);
glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV);
glEnable(GL_VERTEX_PROGRAM_NV);


I simply then use gluLookAt and glutSolidTorus.

Thanks

knackered
05-03-2002, 11:51 AM
You're moving the second row of the projection*modelview matrix into your output colour? Why?

V-man
05-03-2002, 03:23 PM
Originally posted by knackered:
You're moving the second row of the projection*modelview matrix into your output colour? Why?

I dont see a problem, unless the alpha is zero and blending is on...

V-man

SirKnight
05-03-2002, 05:15 PM
MOV o[COL0], c[1];

That is the problem. Like what was said, your moving part of the modelview/projection matrix into the color register. Change that line to this:

MOV o[COL0], v[COL0];

That should do it.

-SirKnight

bakery2k
05-04-2002, 08:34 AM
I've fixed it. The "problem" you mentioned was not a problem at all. I was moving the matrix value to the color register to prevent the primitives appearing black, and hence causing me to think they are not displayed.
The real problem was:




vpFile.seekg(0, ios::end);
int vpSize=vpFile.tellg();
vpFile.seekg(0, ios::beg);


since the file was opened in text mode, the size vpSize was incorrect. I added ios::binary to the flags for "ifstream vpFile(..." and it works fine.

Thanks for your help

knackered
05-04-2002, 11:53 AM
Oh, I would have thought you'd have checked you were reading the text file in *before* asking this question on an opengl forum...
Odd thing to use for a colour, btw.