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 Qt bits


To use OpenGL in a Qt application, subclass QGLWidget and add it to your application like any other widget. You should reimplement at least these three virtual functions:

initializeGL(), which should set up the OpenGL rendering context, define display lists, set up static lights etc. It gets called once before the first time resizeGL() or paintGL() is called.

resizeGL(), which should do the calculations regarding OpenGL viewport and projection. It gets called whenever the widget has been resized, and once when it shown for the first time.

paintGL(), which renders the OpenGL scene whenever necessary.

Inside your subclassed QGLWidget you can call all OpenGL functions as you normally would.
In my example I have placed my QGLWidget inside a QMainWindow, in order to get a normal application window with menus. A warning though: OpenGL applications on some systems using current version of Qt (2.2.3) will cause a segmentation fault on exit.


A 3D coordinate system. Z points away from you.

The concept of 3D


When working in 3D you must understand the concept of a three-dimensional coordinate system. A 3D coordinate system has 3 directions, the x, y and z directions, which describe the right, up, and forwards directions. The left, down and backwards directions are described by negative x, y and z values.

A point in three dimensional space can be described using these three values. The statement ( 2, 4, -1 ) means a point that lies 2 units to the right, 4 units up, and 1 unit towards us. All points are relative to the point (0,0,0). A point in OpenGL is called a vertex, plural vertices. A line that connects two vertices is an edge.

My first approach to generating 3D graphics with a computer was the Persistence of Vision Raytracer (POV-Ray). POV-Ray requires at least three types of elements to make up an image: One or more objects to look at, one ore more light sources, and a camera. In OpenGL the objects and light sources are roughly the same, but instead of a camera (located at a point) OpenGL uses a viewport. The viewport is like a square window through which we can look into our 3D world.


<< 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