help with draw object from a file...

Started by
9 comments, last by colinisinhere 21 years, 9 months ago
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)
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?
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.
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
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...
(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



ok... i understand what you are telling me... but i thought there might be a way around it... thanksanyway
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
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
ok thanks... but i still cant find out how to texture objects for free and what is the best format to use... thanks anyway

This topic is closed to new replies.

Advertisement