Jump to content
  • Advertisement

Archived

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

colinisinhere

help with draw object from a file...

This topic is 5934 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

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
Advertisement
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
Because you need to draw each quad separately...meaning you''ll need to "extrapolate" (couldnt think of a better word) 24 verts out of the 8 you have in order to form 6 quads.

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
given the fact you are only getting the corner vextex postions that is the only way you can do it, if the file format was made of triangles or something then you could have just plugged the numbers in as ya came to them

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

  • 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!