PDA

View Full Version : vertex program ARB.....



white_cat
06-21-2003, 08:22 AM
FILE* fp = fopen("shader.txt","r");
fseek(fp,0,SEEK_END);
DWORD filesize = ftell(fp);
fseek(fp,0,SEEK_SET);
vertex_program = new char[filesize];
fread(vertex_program,1,filesize,fp);

glEnable(GL_VERTEX_PROGRAM_ARB);
glGenProgramsARB(1,&progid);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB,progid);

glProgramStringARB(GL_VERTEX_PROGRAM_ARB,GL_PROGRA M_FORMAT_ASCII_ARB,filesize,vertex_program);

if(GL_INVALID_OPERATION == glGetError())
{
unsigned char *errString;

errString = (unsigned char*)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
return false;
}
-----------------------------------------
I returned a string, "Invalid character", from glGetString-function. what that mean?
I cannot find syntax or etc error..
-------------------------------------
!!ARBvp1.0
ATTRIB iPos = vertex.postion;
ATTRIB iColor = vertex.color;

OUTPUT oPos = result.position;
OUTPUT oColor = result.color;
#no calculation
MOV oPos,iPos;
MOV iColor,oColor;
END
-------------------------------------
very simple!
because only test!

jwatte
06-21-2003, 10:00 AM
You're forgetting to 0-terminate the program string. You need to allocate one more byte, and then set that (final) byte to 0.

justPhil
06-21-2003, 10:02 AM
Hi ,
what about position instead of postion !
and also MOV oColor ,iColor;
then it should "work" ,although you won´t
see anything until you transform your vertex
to clip space I think.

white_cat
06-21-2003, 11:34 AM
You're forgetting to 0-terminate the program string. You need to allocate one more byte, and then set that (final) byte to 0.

Hmm... I did it. but the result isn't a different.


Hi ,
what about position instead of postion !
and also MOV oColor ,iColor;
then it should "work" ,although you won´t
see anything until you transform your vertex
to clip space I think.

well,I think that the vertex program is not work because glProgramStringARB-function occur error(you know it,"Invalid charater").

[This message has been edited by white_cat (edited 06-21-2003).]

secnuop
06-21-2003, 01:36 PM
The program string doesn't have to be null terminated as long as you're passing in the length correctly, though of course it never hurts either.

I had a problem similar to this when I first started experimenting with vertex programs. I was either reading in too many or too few characters from the file, I forget which. In any case, opening the file in binary mode seemed to fix things right up. Give it a try...



fp = fopen(filename.c_str(), "rb");

fseek(fp, 0, SEEK_END);
stringLength = ftell(fp);
fseek(fp, 0, SEEK_SET);

programString = (char*)malloc(stringLength + 1);
fread(programString, 1, stringLength, fp);
programString[stringLength] = 0;
fclose(fp);

glGenProgramsARB(1, &programObject);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, programObject);
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, stringLength, programString);


[This message has been edited by secnuop (edited 06-21-2003).]

white_cat
06-21-2003, 02:40 PM
+_+ Ho~ good!
I know!
must read to binary type..
A factor of problem was New-line code,usually enter code in ascii, add from read file.
thx for your reply.


[This message has been edited by white_cat (edited 06-21-2003).]