Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmawigator

Posted 30 September 2013 - 02:19 AM

Let's better start with OpenGL and then try to load file. A good point is the xcode opengl game template (look at it for details). Basically you will need to load all triangles from the file into a float array. This will be quite easy as the file is pure text. The array should contain vertices of the triangles, it will look like that: x00,y00,z00,nx0,ny0,nz0, x01,y01,z01,nx0,ny0,nz0, x02,y02,z02,nx0,ny0,nz0, x10,y10,... - where x,y,z are position points of each triangle and nx,ny,nz are normal vectors (at each point). Look that in STL normal is per triangle but in OpenGL it is per vertex (you need to duplicate it). Then you need to go to opengl. Create and bind Vertex Object Array (glGenVertexArraysOES, glBindVertexArrayOES) in which you generate OpenGL buffer (glGenBuffers), bind it  (glBindBuffer), copy all data to GPU (glBufferData), setup the vertex attributes (glEnableVertexAttribArray, glVertexAttribPointer) to match the format in the array. On the end close array (glBindVertexArrayOES(0)). Then you may bind it again (glBindVertexArrayOES) and draw all (glDrawArrays).


#2mawigator

Posted 30 September 2013 - 02:17 AM

Let's better start with OpenGL and then try to load file. A good point is the xcode opengl game template (look at it for details). Basically you will need to load all triangles from the file into a float array. This will be quite easy as the file is pure text. The array should contain vertices of the triangles, it will look like that: x00,y00,z00,nx0,ny0,nz0, x01,y01,z01,nx0,ny0,nz0, x02,y02,z02,nx0,ny0,nz0, x10,y10,... - where x,y,z are position points of each triangle and nx,ny,nz are normal vectors (at each point). Look that in STL normal is per triangle but in OpenGL it is per vertex (you need to duplicate it). Then you need to go to opengl. Create and bind Vertex Object Array (glGenVertexArraysOES, glBindVertexArrayOES) in which you generate OpenGL buffer (glGenBuffers), bind it  (glBindBuffer), copy all data to GPU (glBufferData), setup the vertex attributes (glEnableVertexAttribArray, glVertexAttribPointer) to match the format in the array. On the end close array (glBindVertexArrayOES(0)). Then you may draw all with glDrawArrays.


#1mawigator

Posted 30 September 2013 - 02:15 AM

Let's better start with OpenGL and then try to load file. A good point is the xcode opengl game template (look at it for details). Basically you will need to load all triangles from the file into a float array. This will be quite easy as the file is pure text. The array should contain vertices of the triangles, it will look like that: x00,y00,z00,nx0,ny0,nz0,x01,y01,z01,nx0,ny0,nz0,x02,y02,z02,nx0,ny0,nz0,x10,y10,... - where x,y,z are position points of each triangle and nx,ny,nz are normal vectors (at each point). Look that in STL normal is per triangle but in OpenGL it is per vertex (you need to duplicate it). Then you need to go to opengl. Create and bind Vertex Object Array (glGenVertexArraysOES, glBindVertexArrayOES) in which you generate OpenGL buffer (glGenBuffers), bind it  (glBindBuffer), copy all data to GPU (glBufferData), setup the vertex attributes (glEnableVertexAttribArray, glVertexAttribPointer) to match the format in the array. On the end close array (glBindVertexArrayOES(0)). Then you may draw all with glDrawArrays.


PARTNERS