Archived

This topic is now archived and is closed to further replies.

colinisinhere

help with draw object from a file...

Recommended Posts

Im trying to read a file format (a metaseq file) and i made a simple cube in meta... it shows the vertices like this -4.1796 4.1796 -4.1796 4.1796 4.1796 -4.1796 -4.1796 4.1796 4.1796 4.1796 4.1796 4.1796 -4.1796 -4.1796 4.1796 4.1796 -4.1796 4.1796 -4.1796 -4.1796 -4.1796 4.1796 -4.1796 -4.1796 But it displays it all messed up cuz they are not in order like opengl requires... is there a way to draw vertices in any order and draw it the right way? (hope you understand what i mean)

Share this post


Link to post
Share on other sites
in simpler words... i have a file format and it has the coords of the vertices like this
-4.1796 4.1796 -4.1796
4.1796 4.1796 -4.1796
-4.1796 4.1796 4.1796
4.1796 4.1796 4.1796
-4.1796 -4.1796 4.1796
4.1796 -4.1796 4.1796
-4.1796 -4.1796 -4.1796
4.1796 -4.1796 -4.1796
(it is a cube)
but when i try to draw that it is messed up...
why? and how do i fix it?

Share this post


Link to post
Share on other sites
yes.. i konw that.. but that isnt how the file format works... the file format shows:
-4.1796 4.1796 -4.1796
4.1796 4.1796 -4.1796
-4.1796 4.1796 4.1796
4.1796 4.1796 4.1796
-4.1796 -4.1796 4.1796
4.1796 -4.1796 4.1796
-4.1796 -4.1796 -4.1796
4.1796 -4.1796 -4.1796
and i want to draw that without changing it...
thanks anyway

Share this post


Link to post
Share on other sites
You will have to load that into your program, and convert it into 6 sets of 4 vertices, or 4 verts per 1 side of the cube. Thats pretty much the only way to render it.

Using glVertex, it will take 24 glVertex commands to draw one cube. Does that explain the fact that you cannot tell ogl to draw a cube with 8 commands? Just order it properly and you will end up calling glVertex 24 times. Jeez...

Share this post


Link to post
Share on other sites
(assuming Z+ is coming out of the screen) those postions give you the corners of the cube

-4.1796 4.1796 -4.1796 - [1]top left back corner
4.1796 4.1796 -4.1796 - [2]top right back corner
-4.1796 4.1796 4.1796 - [3]top left front corner
4.1796 4.1796 4.1796 - [4]top right front corner
-4.1796 -4.1796 4.1796 - [5]bottom left front corner
4.1796 -4.1796 4.1796 - [6]bottom right front corner
-4.1796 -4.1796 -4.1796 - [7]bottom left back corner
4.1796 -4.1796 -4.1796 - [8]bottom right back corner

so, to draw the back of the cube you select verts. 1,2, 7 and 8, feed ''em to OGL in the correct order and it will draw the back quad, repeat for all sides.

I dont know how you would make this more general perpose, but your a programmer, you work it out



Share this post


Link to post
Share on other sites
The problem is that you have the verticies declared, but not the primitives to be drawn. What you need to do is set the values you have into a vertex array, then create another array of the verticies to be used with glDrawElements by array index.

Set the vertex array using glVertexArray.
Make an array ordering the verticies as they should be given.
Use glDrawElements.

Got that?
Try the Red Book (pgs 67-81) in regards to OGL arrays. Useful stuff, and it''d make some code I''ve seen easier to read and use.

-Sta7ic

Share this post


Link to post
Share on other sites
Load and bind a texture, make an array for texture coordinates, enable texture arrays, set the appropriate array, and use glDrawElements as above. glDrawElements will submit, as enabled, verticies, normals, colors, and/or texture coordinates. Good stuff.

-Sta7ic

Share this post


Link to post
Share on other sites