GLfloat vertices from txt file

Started by
14 comments, last by m_power_hax 13 years, 4 months ago
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
Advertisement
Quote:
but it didnt work.

Can you be more specific?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
10*10*10 = 10000 floats, why do you have 2999? Is 1/3 of the model showing?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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.

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?

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.
Signature go here.
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?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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.

This topic is closed to new replies.

Advertisement