PDA

View Full Version : How to draw a building in 3D?

anime.igala.net
10-08-2008, 02:29 AM
Hello,

I would like to know how to draw a building in 3D using OpenGL.
A building includes a footprint and a height. A footprint is a set of point. The number of the point of footprint is not fix, some things look like this:

http://img76.imageshack.us/img76/3969/building1na1.jpg

http://img77.imageshack.us/img77/4857/buildingzt3.jpg

So what data structure I should use? And I can draw in using what function of OpenGL? I cannot use glBegin, glEnd because I'm using OpenGL ES to draw.

Thanks all,

anime.igala.net
10-08-2008, 02:58 AM
I would like to work on real data, it mean that the value may be 1000, 5000 ... Not some things like ( -1, 0, 1 ) ( -1, 2, 1 ) ...

I'm using gluPerspective.

Z-Knight
10-08-2008, 08:33 AM
You'll have to build that building one polygon at a time...basically, you would need to write code for each side of the building and using the "real" coordinates is fine, but your initial scene may be really big and you'll have to zoom out your view to see it. In your case, I'm guessing you want to use the footprint and extrude it up to the desired height...well, that's not really possibly with OpenGL. You could use the footprint to make a base polygon and a top polygon, but then the sides of the building you'd have to also create polygons for.

Here is some example code of drawing a polygon...you could do triangles, quads, etc

glColor3f(0.0f,0.0f,1.0f); //blue color

glBegin(GL_POLYGON);//begin drawing of polygon
glVertex3f(-0.5f,0.5f,0.0f);//first vertex
glVertex3f(0.5f,0.5f,0.0f);//second vertex
glVertex3f(1.0f,0.0f,0.0f);//third vertex
glVertex3f(0.5f,-0.5f,0.0f);//fourth vertex
glVertex3f(-0.5f,-0.5f,0.0f);//fifth vertex
glVertex3f(-1.0f,0.0f,0.0f);//sixth vertex
glEnd();//end drawing of polygon

Source/Examples: http://en.wikibooks.org/wiki/Programming:OpenGL:GLStart:Tut3

Note that to make a real looking building you'll probably want to map textures onto the sides so investigate that next.

anime.igala.net
10-08-2008, 08:53 AM
As I said, I cannot use glBegin, glEnd. So I think that I need to use glDrawElements or glDrawArrays. In fact, I'm using glDrawElements with the arrays for vertices and indices. But I don't know why it does not work, so I would like to have to reference code.

Z-Knight
10-08-2008, 08:56 AM
oops, sorry...did not see that....don't know what OpenGL ES is anyway, but I'm surprised there is nothing equivalent in it, otherwise why would it be called "OpenGL"

anime.igala.net
10-08-2008, 09:18 AM
OpenGL ES is a light version of OpenGL :)

dletozeun
10-08-2008, 04:07 PM
Z-Knight> Opengl ES does not contain begin/end functions because this is not efficient and it is for embedded systems. Anyway, it will be removed I think in the next opengl release.

anime.igala.net> When you extrude your footprint in vertical direction, you will always obtain quads on each edge, so is easy to build the volume sides polygons.

For the volume cap, if the footprint is always convex, it could be done using a triangle fan, for concave one, it would a bit more complicated.

trinitrotoluene
10-08-2008, 04:19 PM
For the volume cap, if the footprint is always convex, it could be done using a triangle fan, for concave one, it would a bit more complicated.
Just for information, a solution for drawing concave polygon which use stencil test is in this thread (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=47989&Number=245848)