How to draw a building in 3D?

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:

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,

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.

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

Other: http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx

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

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.

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”

OpenGL ES is a light version of OpenGL :slight_smile:

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.

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