Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Reading a 3D model from a Web server

Hi,

I will like to read a 3D model in .h (converted obj2OpenGL) stored in a Webserver to an Iphone so it can render it.

I did done a lot of search in Internet.

I'm able to connect to my Local Webserver and get the data from a text file from it as either NSData format or NSString format.

But, I'm puzzle about transform or convert the resulted data (NSData or NSString) to a GLfloat array.

Can someone can help me a bit ?

Here is a bit of my code, if I'm off track please guide me.

Note for now I did split by hand the banana.h file into smaller one which contains all the vertex, ObjVerts.txt is one of them.

Later I will try to write a parser to extract them.

NSURL *myurl = [NSURL URLWithString:@"http://localhost/ObjVerts.txt"];
NSString *mystring = [NSString stringWithContentsOfURL:myurl];
//NSData *mystring = [NSData dataWithContentsOfURL:myurl];

glVertexAttribPointer(vertexHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) mystring); <--- Does not work

glVertexAttribPointer(normalHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bananaTexCoords[0]);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 1);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
Tagged:

Replies

  • marktwomarktwo Posts: 57New Users @
    If you're trying to pass a formatted text file to glVertexAttribPointer, then that obviously won't work.
    Converting NSString to NSData doesn't "unformat" your text for you.

    It might be easier to put your text data into JSON format, so you can easily extract it
    as floats and integers.

    Otherwise, you need to write your own text parser that understands your text format.
Sign In or Register to comment.