Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


Building 3D worlds with OpenGL



The OpenGL way of doing things


OpenGL is a low-level API. In POV-Ray you can describe complex objects by declaring primitives (basic, built-in objects) such as 'sphere' and 'box', and add or subtract them from each other. In OpenGL you have to build everything from the ground and up. You start with vertices, and connect them to make triangles, which in turn can be combined to build e.g. a sphere. The OpenGL primitives are more basic, such as 'triangles' and 'triangle-strips'.
GLU, the OpenGL Utilities, adds some higher-level functionality, such as 'sphere' and 'cylinder' primitives, but it is still a lot of work to build complex shapes.

Note: OpenGL can be useful for 2D graphics, too. By specifying that objects far away should not look smaller than close objects, you'll get a flat 2D world. This is used in some 2D games.

OpenGL is a state machine. This means that when you set any properties, they will stay that way, independent of scopes and function calls, until the program stops or you change them. If you are not aware of this, you will, like I did, experience some weird bugs.


Rotating landscape with building

A red house on a red island in a red sea


While this does sound kind of poetic, it does not show much of what you can do with OpenGL. It has no textures, and only one light source. But for a newbie OpenGL program, it does look kind of cool, doesn't it?

Basically, what I wanted to do was to build a landscape from a height field. The height field is just a 2D array in map.hpp. (In a real world application you would of course use an image instead.) Each point in the height field corresponds to the height of a vertex in my landscape, and four points make up a square. To make my landscape more detailed, I split the squares into triangles when necessary. I actually use a second 2D array to determine how to split each square, upper-left-to-lower-right or upper-right-to-lower-left. Then I make the whole scene rotate, with an option to pause the rotation.

If you think this is a somewhat cumbersome and ineffective way of doing things, you are completely right. One example of this is that all my triangles are evenly distributed. The world would be both faster to render and better looking if I had used large triangles for flat surfaces, and small triangles for uneven surfaces. But I am, as I must have pointed out a few times by now, just a newbie.


<< Previous page | 1 | 2 | < 3 > | 4 | 5 | 6 | Next page >> | Printer-friendly page |

Comment List


Topic: Author:
Time:
Beginner's tutorials Johann Fuchs 13.02.2001 17:04

if you want to learn opengl programming from the scratch
to high level you should look at

http://nehe.gamedev.net

which is quite an excellent site IMHO.




Forgot your password?

Register a new user

Results

Polls