View Full Version : Reading shader data
Bossa Nova
2003.04.30, 09:23 AM
Hi,
I've got a big problem. I need some way to store shaders.
Right now, I'm storing them as .txt files exported from TextEdit (tried SimpleText too). I've got a funny problem though.
After the END line (the last line of any Shader) I get a string of characters in the form of /number almost like a bunch of escape sequences. Any changes I make to the file change the numbers at the end. I had this problem before but when I changed the file, they return. Take a look:
http://homepage.mac.com/jkross/.cv/jkross/Public/error.jpg-link.jpg
kelvin
2003.05.01, 08:04 PM
those look like escape'd ascii chars. I guess textedit is appending those. My suggestion would be to open the text file in project builder and just delete them off. If that doesn't work try BBEdit lite. http://www.barebones.com
Or one of the bsd commandline tools if you're comfortable with them.
Bossa Nova
2003.05.01, 10:02 PM
those look like escape'd ascii chars. I guess textedit is appending those. My suggestion would be to open the text file in project builder and just delete them off. If that doesn't work try BBEdit lite
No such luck kelvin. Tried TextEdit, SimpleText, TextWrangler, and BBEdit. Still have problems. If it helps, here is the code I use to read the shaders:
int length;
ifstream is;
is.open(shaderName, ios::in);
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(0, ios::beg);
GLubyte shaderCode[length];
is.read((char*)shaderCode, length);
cout << shaderCode;
kelvin
2003.05.02, 08:01 AM
Hmn, don't know what's going on. I'm not too familiar with streams or C++. And as for what I said earlier, they're not escape'd characters unless they're double byte, so that kinda rules that out. "\274" They're probably just memory garbage from reading past the end of the pointer.
... ten minutes later ...
ok, I've sped myself up on streams and I've found how to fix your problem.
changeout << shaderCode;
tocout.write (shaderCode, length);
If it gets any more complex, ask somebody else in the forum cuz you've just exhausted my knowledge of C++.
Bossa Nova
2003.05.03, 11:17 AM
Well, cout-ing the shaderCode is not really the problem. Instead, the problem occurs when I pass the shaderCode to OpenGL. That said, you're absolutely right --it is a problem with the length of the variable I'm reading the shaderCode into.
Originally my program sent the shader data with this line
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(shaderData), shaderCode);
Instead I changed the strlen call to the length I pulled earlier from the stream. This fixes the problem.
Thanks a lot, kelvin, for you help.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.