PDA

View Full Version : saple code



tasmehmet
04-19-2001, 02:04 AM
hi, i will not ask any question about coding.
i heard that there a few programs in which you change the properties (like color, position,light...)of the objects from a txt document. If u know such programs please give me the address, thanks..

Deiussum
04-19-2001, 05:24 AM
Why not ask questions about coding? This is a coding forum, is it not? http://www.opengl.org/discussion_boards/ubb/smile.gif

What you want is really pretty simple. Just store your data in a text file and read that in for use in OpenGL... I don't quite understand what the problem you are having is. Here's a quick example of a display function that reads the data from a file. Just color and vertex data for this example... the text file would be stored like so

r1 g1 b1
x1 y1 z1
r2 g2 b2
x2 y2 b2
etc...




void display()
{
ifstream fin("somefile.txt");
float r,g,b;
float x,y,z;

glBegin(GL_TRIANGLES);
while(!fin.eof())
{
if (fin >> r >> g >> b)
{
glColor3f(r,g,b);
}

if (fin >> x >> y >> z)
{
glVertex3f(x,y,z);
}
}
glEnd();
}

05-03-2001, 09:36 AM
Thank's Deiussum. I suppose I would have typed a thousands fingermiles more of code with the standard i/o library before I would have seen the easy-of-use of these filestreams.

Maybe I should not only use my C++ Book as a paperweight, writing-pad, toilet-paper or doorstopper.