Basically I am trying to move from OpenGL 1.0 to OpenGL 3.1.
So I need these two items to specify the coordinates of the vertices and the vertex array.
I found out that the array was not suppose to be inside the struct, just the tutorial was misleading.
I think that the tutorial is using C opposed to C++.
It contains the following line: file_contents(filename, &length);
I didn't have a library included with that command.
So I tried to replace it with a fstream command.
Here is what I have:
ifstream file (filename,ios::in);
if (file.good() ==false)
{
return 0;
}
file.seekg(0, ios::end);
int size = file.tellg();
source = new GLchar[size];
file.seekg(0,ios::beg);
file.read(source,size);
file.close();
The problem is that after reading the file it has garbage appended to the end. What am I doing wrong?
How do you print the data in source? If you just print it as a string remember that a string ends with a null character '\0'. source will probably not contain a null character.
If you want to read text out of a file, and treat it as a c-string: source = new GLchar[size + 1];//extra byte for the null terminator
...
file.read(source,size);
...
source[size] = '\0';//add the null terminator