Jump to content
  • Advertisement
Sign in to follow this  
m_power_hax

GLfloat vertices from txt file

This topic is 2785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

Here the code for loading data from a txt file to a normal array. What i'm trying to do now, is to load that data to a GLfloat vertice[].

#include <iostream>
#include <fstream>
using namespace std;

float vertices[2999];

void CreateDataFile()
{
ofstream out("testfile.txt");
for (float x=0;x<10;x++)
for (float y=0;y<10;y++)
for (float z=0;z<10;z++)
{
if ((x == 9) && (y == 9) && (z == 9))
{
out << x*0.123456 << " " << y*0.123456 << " " << z*0.123456;
}
else
out << x*0.123456 << " " << y*0.123456 << " " << z*0.123456 << "\n";
}
}

int main()
{
CreateDataFile();

ifstream loadData("testfile.txt");

if (!loadData)
{
cout<< "Can't open file!\n";
return 1;
}
else
{
int j = 0;
cout.precision(2);
while (loadData >> vertices[j])
{
//cout << vertices[j] << ",";
++j;
}
//cout << j;
cout << vertices[1];
}
loadData.close();
return 0;
}


I tried it for a GLfloat vertices array, but it didnt work. Could someone help find the best way to upload data in a GLfloat vertice[]?
Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by dpadam450
10*10*10 = 10000 floats, why do you have 2999? Is 1/3 of the model showing?


because there are x,y,z, each going from 0 to 9, which make 1000 points, since there are 3 coordinates per point, that make an array of 2999 (0 count for 1). There is only a few vertices showing, i didnt count them but, only one plane is draw, maybe 20 points total.

Share this post


Link to post
Share on other sites
Quote:
Original post by karwosts
Quote:

but it didnt work.

Can you be more specific?


well i think specifying the GLfloat like this : GLfloat vertices[] = {0.5,0.5,0.5 , 0.5,1.0,0.5 , 0.5,0.5,1.0 , ...} is different than what my code is doing when loading the data from the txt file. The GLfloat def know what value are x, y ,z.

So what should i change in the code?

Share this post


Link to post
Share on other sites
What kind of "it doesn't work"? Compiler error? Linker error? Runtime error? Running but not producing the correct output?

Offtopic gripe: Also, why do I keep seeing/hearing people who think the singular of 'vertices' is 'vertice'? It's 'vertex'. Plurals for words ending in -ex end in -ices.

Share this post


Link to post
Share on other sites
Right about the size of the array. But you really need to show us a pic or something of what is going on. What is your drawing code?

Share this post


Link to post
Share on other sites
Quote:
Original post by m_power_hax
Quote:
Original post by dpadam450
10*10*10 = 10000 floats, why do you have 2999? Is 1/3 of the model showing?


because there are x,y,z, each going from 0 to 9, which make 1000 points, since there are 3 coordinates per point, that make an array of 2999 (0 count for 1). There is only a few vertices showing, i didnt count them but, only one plane is draw, maybe 20 points total.


the last index in a float foo[2999] array is 2998 so you still only have room for 2999 elements.

using glfloat instead of float shouldn't change anything, for most OpenGL implementations glfloat and float will be the exact same thing.

The code you have fills the array properly but one element is written out of bounds, chainging float vertices[2999] to float vertices[3000] should solve that, but using a dynamic container (such as a vector) would be preferable)

If correcting the array size doesn't work your problem lies in code you havn't posted yet.

Share this post


Link to post
Share on other sites
If you don't know a programming language, then you should learn that first. Learn to use its IO features. Learn all the basics of that language. Then learn about GL. Also, your question isn't about GL.

Share this post


Link to post
Share on other sites
Quote:
Original post by Aken H Bosch
What kind of "it doesn't work"? Compiler error? Linker error? Runtime error? Running but not producing the correct output?

Offtopic gripe: Also, why do I keep seeing/hearing people who think the singular of 'vertices' is 'vertice'? It's 'vertex'. Plurals for words ending in -ex end in -ices.


Running but not producing the correct output. When using the normal GLfloat call in my program, it can draw correctly a number x number x number point sprites. When using the vertices array from the text file, only one plane is draw (number x number) and that plane is not of the right dimension, alot of point sprites are missing in that plane. I hope it's more clear now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!