Idea about how to model a building using OpenGL/GLUT? - c++

I'm new to graphics, and I have to make a model of a building for an assignment using only GLUT or OpenGL.
Basically the school building's model( only the exterior portion) is to be made, and I have no clue where to start. Upto now I have drawn polygons, other shapes using GLUT, nothing in which there are multiple shapes. All the drawing upto now is using lines, or points, or polygons and mathematics.
Could you please give me an idea of how to go about it?
Update: I just want to know what steps I can follow to get it done. Some reference links would be awesome!

You could use modeling programs to create your model, and then use tools such as COLLADA to get your model into OpenGL.

The problem with hand-coding a complex object like that is that it takes a great number of lines of code just to define the vertices of the object.
People usually use 3D modeler software to build complex 3D objects, like Maya, 3DSMax or Blender and then export them in a format to be read into your OpenGL application.

Think about what you want your building to look like, and think about what kind of triangles you need to render in order to make that. You can either draw the entire thing in some sort of modelling software, and then import it into OpenGL, or you can come up with the triangles/textures yourself and do it by hand in OpenGL.
The exterior of the building will probably have a similar texture on the whole thing (brick, etc), and then there will be windows, doors, and a roof. Maybe some sort of sign that says "School Building". Take this all into account, what exactly you want your building to look like, and then think about what textures you will need to draw these things.
For example, say you're doing a brick building that is in the shape of a box, with a door and a few windows. I'd use one texture for the brick, and first draw an entire wall of brick. Then, I'd use a grey/blue looking texture for the window, and draw it over the brick wall. Then I'd do the same (different texture) for the door.
Just think about the design, and then just try things out - experiment. Good luck!

I once had a simillar homework. I did it by creating the models with Google SketchUp, then export the models to .3ds file and use my program to render it.
I choose Google SketchUp because it's the easiest to use among those tool I tried. Plus, they had a discount for students. You could also use Blender, which is free but take too much time to learn IMHO. 3dsMax is too expensive to pay for a homework.
To load the model into my program, I used Assimp library.

Related

way to have 3d animated/rigged character in Opengl

If I want a 3D animated/rigged character in OpenGL game how i would have it in OpenGL?If i make a animated/rigged character in 3Ds max is it possible to have that character in OpenGl?would be helpful if someone gives a proper way or a tutorial link to export animated model from 3d software to open GL
OpenGL is a very simple 3D framework which only offers the bare bones. OpenGL can display triangles and fill them with color and that's about it. It comes with some helper functions to manipulate point clouds but it's really very basic.
Animation and rigging are way beyond what it can do. What you need is a framework which supports animation and rigging which then uses OpenGL to display the result.
Since you don't specify any requirements, it's hard to say which one would be good for you. Blender is probably a good place to start. It's game engine runs on many platforms, supports OpenGL, animation and rigging.

What is the purpose of a graphics library such as OpenGL?

I realize this is probably a ridiculous question, but before trying to figure out what libraries to use for which projects, I think it makes sense to really understand the purpose of such libraries first.
A lot of video games use libraries like OpenGL. All the tutorials I've seen of such libraries demonstrate how to write code that tells the computer to draw something. Thing is, in games these days everything is modeled using software such as Zbrush, Maya, or 3ds Max. The models are textured and are good to go. It seems like all you'd need to do is write an animation loop that draws the models and updates repeatedly rather than actually program the code to draw every little thing. That would be both extremely time consuming and would make the models useless. So where does OpenGL or Direct 3D come in in relation to video games and 3d art? What is so crucial about them when all the graphics are already created and just need to be loaded and drawn? Are they used mainly for shaders and effects?
This question may just prove how new I am to this, but it's one I've never heard asked. I'm just starting to learn programming and I'm understanding the code and logic fairly well, but I don't understand graphics libraries or certain frameworks at all and tutorials are not helping.
It seems like all you'd need to do is write an animation loop that draws the models and updates repeatedly rather than actually program the code to draw every little thing.
Everything that happens in a computer does so because a program of some form tells it exactly what to do. The letters that this message is composed of only appear because your web-browser of choice downloaded this file via TCP/IP over an HTTP protocol, decoded its UTF-8-encoded text, interpreted that text as defined by the XML, HTML, JavaScript, and so forth standards, and then displayed the visible portion as defined by the Unicode standard for text layout and in accord with HTML et al, using the displaying and windowing abilities of your OS or window manager or whatever.
Every single part of that operation, from the downloading of the file to its display, is governed by a piece of code. Every pixel you are looking at on the screen is where it is because some code put it there.
HTML alone doesn't mean anything. You cannot just take an HTML file and blast it to the screen. Some code must interpret it. You can interpret HTML as a text file, but if you do, it loses all formatting, and you get to see all of the tags. A web browsers can interpret it as proper HTML, in which case you get to see the formatting. But in every case, the meaning of the HTML file is determined by how it is used.
The "draws the model" part of your proposed algorithm must be done by someone. If you don't write that code, then you must be using a library or some other system that will cause the model to appear. And what does that library do? How does it cause the model to appear?
A model, like an HTML web page, is meaningless by itself. Or to put it another way, your algorithm can be boiled down to this:
Animate the model.
????
Profit!
You're missing a key component: how to actually interpret the model and cause it to appear on the screen. OpenGL/D3D/a software rasterizer/etc is vital for that task.
A lot of video games use libraries like OpenGL.
First and foremost: OpenGL is not a library per-se, but an API (specification). The OpenGL API may be implemented in form as a software library, but these days is much more common to implement OpenGL in form of a driver that turns OpenGL function calls into control commands to a graphics processor sitting on a graphics card (GPU).
All the tutorials I've seen of such libraries demonstrate how to write code that tells the computer to draw something.
Yes. This is because things need to be drawn to make any use of them.
Thing is, in games these days everything is modeled using software such as Zbrush, Maya, or 3ds Max.
At this point the models just consist of a large list of numbers, and further numbers that tell, how the other numbers form some sort of geometry. Those numbers are not some sort of ready to use image.
The models are textured and are good to go.
They are a bunch of numbers, and what they have is some additional numbers controlling texturing. The textures themself are in turn just numbers.
It seems like all you'd need to do is write an animation loop that draws the models
And how do you think this drawing is going to happen? There's no magic "here you have a model, display it" function. Because for one the way in which the numbers making up a model may have any kind of meaning. So some program must give meaning to those numbers. And that is a renderer.
and updates repeatedly rather than actually program the code to draw every little thing.
Again, there is no magic "draw it" function. Drawing a model involves going through each of its numbers, it consists of, and turning those into drawing commands to the GPU.
That would be both extremely time consuming and would make the models useless.
How are the models useless, when they are what is controlling the issuing of commands to OpenGL. Or do you think OpenGL is used to actually "create" models?
So where does OpenGL or Direct 3D come in in relation to video games and 3d art?
It is used to turn the numbers a 3D model, as it is saved away from a modeller, into something pleasant to look at.
What is so crucial about them when all the graphics are already created
The graphics is not yet created, when the model is done. What's created is a model, and some auxilliary data in form of textures and shaders, which are then turned into graphics in realtime, at the execution time of the program.
and just need to be loaded and drawn?
Again, after being loaded, a model is just a bunch of numbers. And drawing means, turning those numbers into something to look at, which requires sending drawing commands to the graphics processor (GPU), which happens using a API like OpenGL or Direct3D
Are they used mainly for shaders and effects?
They are used to turn the numbers generated by a 3D modelling program (Blender, Maya, ZBrush) into an actual picture.
You have data. Like a model, with vertices, normals, and textures. As #datenwolf stated above, those are all just numbers sitting on the hard drive or in RAM, not colors on the screen.
Your CPU (which is where the program you write runs) can't talk to the screen directly. Instead, you send the data you want to draw to the GPU. The GPU then draws the data. Graphics APIs like OpenGL and Direct3D allow programs running on the CPU to send data to the GPU and customize how the GPU draws it. This is a gross simplification, but it sounds like you just need an overview.
Ultimately, every graphics program must go through a graphics API. When you draw an image, for example, you send the GPU the image, and the GPU draws it on the screen. Draw some text? Send the data to the GPU. The GPU draws it. Remember, your code can't talk to the screen. It CAN talk to the GPU through OpenGL or Direct3D, and the GPU then draws the data.
Before OpenGL and DirectX, the games had to use special instructions depending on what graphics card you had. When you bought a new game, you had to check carefully if your card was supported, or you couldn't use the game.
OpenGL and DirectX is a standardized API to the grapics cards. A library is delivered by the manufacturer of the card. If they follow the specification, you are guaranteed that games will work (if they also follow the same specification).
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.

how to draw pool table pockets opengl c++

hey
i am creating a pool table simulator in opengl written in c++
i have the basic table drawn but now i need to add some pockets
i want the pockets to be a basic curve like a C shape
im not quite sure how to do this
i have experimented with trianglefan but iv had no luck
can anyone help please?
also i must add this is part of a university project therefore i will only be using the core opengl and c++....no other tools
thanks in advance
When I use OpenGL, I usually build the models in something like Blender.
Blender is free and allows export to WaveFront obj - an easy format to read in to your program. Or you can use the simple text WaveFront obj with a little scripted editing will produce a list of vertices that you can use in arrays for vertex buffer objects.
I couldn't imagine trying to build objects for a 3D scene using only discrete values and discrete math like (I think?) you're describing.
Do you have access to glu.lib?
http://en.wikipedia.org/wiki/OpenGL_Utility_Library
http://www.opengl.org/resources/faq/technical/glu.htm
That would easily make cylinders or NURBS curves for the pockets. Sample use of it is here: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=18
There is also lots of code from the "Graphics Gems" series available - you can dig through the early books for something suitable if GLU isn't an option.
http://www.graphicsgems.org/
Start with a cube and slice off the bottom corners. Refine as necessary.

Playing with OpenGL

Just learning the basics of OpenGL for a class and was looking for something challenging and interesting to try and draw. Any suggestions?
Aiming to photorealism (just plain models, lights, materials, textures, etc.) is one thing, but what is even more interesting in my opinion is demoscene and all kinds of non-photorealistic effects. The idea of a demo is to program some nice animated graphics that automatically change from one effect to another or tell some sort of a story, and have a background music. Here you can find some videos. Just take a look at what some others have done and use your imagination. That's the funniest part of 3D programming in my opinion. Of course what you'll first program would be something extremely simple when compared to those videos on youtube, but everyone has to start from somewhere. Simple also doesn't need to be ugly. Some random suggestions:
mathematical shapes with sin(), cos(), etc.
alpha blending, especially addition blending (glBlendFunc(GL_ONE, GL_ONE);)
terrain rendering
read 3d model data from a file. (Wavefront .OBJ is a relatively simple one)
feedback effects with glCopyTexImage2D, which copies pixels from screen to a texture (in real life you shouldn't use this because it's too slow, but when learning the basics it's ok)
etc...
You might consider building an OBJ viewer. You will get the experience you're looking for, and it's a pretty good project for a beginning 3D graphics programmer, in terms of difficulty.
I believe opengl has built in shapes such as a teapot that you can call and have it draw. For starters, I'd stick with easy shapes like squares, circles, and cones. Try drawing a wireframe model first since that's the easiest, by using either quadstrips ,triangles or just poly lines. After you've gotten that down, learn to set up lighting and materials so you can draw a solid model.
At school we had a very interesting assignement to get started with OpenGL that I will share. The long term goal was to modelize a living room so you basically have to draw:
A table.
Two chairs.
A carpet.
A sofa
Some stuff that you might find interesting to add on the table for
instance a TV!
When you have all the things done, try to polish the scene a little bit by adding some lighting effects!
Hint: for all the objects you simply need to start with a basic rectangle. Then you can construct your scene step by step using translations/rotations.

Importing 3D objects and its animation to iphone openGL

I am trying to develop a 3D game in openGL and i need to create many 3D objects.. I am a begginner in openGL.. I have tried with many 3D softwares like Blender , MODO, Unity 3D and Cheetah.
I am easily able to create my objects with these and exporting as Wavefront .OBJ, and converting it to a header file using a perl script. This header file is added to my openGL project..
The 3D objects are seen, but its not perfect. The script i used is to convert the .OBJ to .h using TRIANGLES.. And the object is seen with triangles. Its not full.. No way when i used TRIANGLE STRIP,FAN..? Problems with the vertices..
Is the problem with my Script or is it the wrong way i have gone..?? Or is there any other best ways to directly import 3D objects to openGL..??
The below link is the best one which you can get for 3D objects to openGL.. i got the scripts from these..
http://www.heikobehrens.net/2009/08/27/obj2opengl/
please help..
You don't want to go that way. Direct drawing mode (using TRIANGLE and friends) is extremely slow in OpenGL.
Instead, you should pick a decent format and write a loader for it (or use one found on the web). Good formats would be 3ds, obj if gzipped, collada.
Here's an example tutorial on loading from Milkshape files.
Once you load your objects programatically, you can use Vertex Arrays, or even better VBO's to display them. This is waaay faster.
Google for a mesh loader for your favorite format, or write one yourself.
I have written a reader/renderer for AC3D files that works fine on the iPhone (OpenGL ES)
Feel free to have a look at it here.
There is also an obj loader by Jeff Lamarche at google code.
AC3D can reduce the triangle count pretty good and as an alternative I ported QVis to the mac. My reader/renderer also tries to build tri-strips.
About VBO's. I have not seen any gained performance when using them in the iPhone. I'm not the only one.