Title: OpenGL applications with MNOgl component collection
Question: How do i build a application which looks like OpenGL but not with a Paint method of thousands of lines?
Answer:
Nothing is easier than this!
Use the brand new component collection from minais (www.minais.at). This collection comes along with a lot of sample files which can be downloaded from www.minais.at. Build your own games with key and mouse interactions or improve and facelift your existing applications with OpenGL output. We made very good experiences with pupils who were fascinated how interesting 3D world can be.
Don't hesitate to check our site www.minais.at. MNOgl Version 1.0 is completly FREE.
Let me show you a first example:
When you use MNOgl component collection from minais you have two different ways to build such an application.
First i want to describe the easy way:
First of all be sure to install the MNOgl package file mnogl.bpl under Delphi (Component menu - Install packages - Add button - search for MNOgl.bpl and say Open). The result is you have a new component folder called MNOgl. Within you will find a lot of handy components to design an OpenGL application.
Let us start with a new project. Select a TMNOglControl component and drop it on to the form. Resize the control as you want it or let it align. Then select a TMNOglCanvas component and drop it on the form. Assign the MNOglControl1 to the property named WinControl. NOW an OpenGL rendering context will be generated (the MNOglControl changes to black backgroundcolor).
Let us now look how we can draw a box in this canvas. Pick a TMNOglScene component from the MNOgl folder and drop it on the form. Assign the MNOglCanvas1 to the property MNOglCanvas. Now let us select a TMNOglBox component and drop it on the form. Assign MNOglScene1 to the property Scene. Now you see the shape alread in design mode. Try to change the size of the box by changing the properties length, width and height. If you want to have your shape centered then set the TransformBy property to
(-length/2, -width/2, -height/2).
Attached is the delphi form:
object Form1: TForm1
Left = 248
Top = 116
Width = 780
Height = 580
Caption = 'MNOgl component collection sample [first steps]'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
PixelsPerInch = 120
TextHeight = 16
object MNOglControl1: TMNOglControl
Left = 0
Top = 0
Width = 539
Height = 553
BevelKind = bkSoft
Align = alLeft
end
object MnOglCanvas1: TMnOglCanvas
WinControl = MNOglControl1
UnitsPerCM = 30
DefaultTriangleResolution = 2
AutoCompile = True
LightModelTwoSided = False
BackgroundColor = clBlack
ZoomFactor = 1
DefaultUnitsPerCM = 30
SelectEnabled = True
TransformBy = '0/0/0'
RotationPoint = '0/0/0'
RotationLine = '0/0/0'
Left = 602
Top = 22
end
object MNOglScene1: TMNOglScene
MnOglCanvas = MnOglCanvas1
Visible = True
TransformBy = '0/0/0'
RotationPoint = '0/0/0'
RotationLine = '0/0/1'
Attributes.PolyStyle.Mode = glfill
Attributes.Material.Ambient = clWhite
Attributes.Material.Diffuse = clGray
Attributes.Material.Specular = clGray
Attributes.Material.Emission = clGray
Attributes.Material.Shininess = 0.2
Attributes.Material.Translucent = 1
Attributes.Material.DefKind = NoDefMat
Attributes.Texture.Repeating = True
Attributes.Texture.Filter = glnearest
Attributes.Texture.EnvMode = glmodulate
Attributes.Texture.Visible = False
Attributes.Texture.BaseFix = False
Attributes.Texture.WorldWidth = 1
Attributes.Texture.WorldHeight = 1
Left = 602
Top = 84
end
object MNOglBox1: TMNOglBox
Attributes.PolyStyle.Mode = glfill
Attributes.Material.Ambient = clWhite
Attributes.Material.Diffuse = clGray
Attributes.Material.Specular = clGray
Attributes.Material.Emission = clGray
Attributes.Material.Shininess = 0.2
Attributes.Material.Translucent = 1
Attributes.Material.DefKind = NoDefMat
Attributes.Texture.Repeating = True
Attributes.Texture.Filter = glnearest
Attributes.Texture.EnvMode = glmodulate
Attributes.Texture.Visible = False
Attributes.Texture.BaseFix = False
Attributes.Texture.WorldWidth = 1
Attributes.Texture.WorldHeight = 1
Scene = MNOglScene1
TransformBy = '-3/-2/0'
RotationPoint = '0/0/0'
RotationLine = '0/0/1'
Scale = 1
Visible = True
ParentAttributes = False
Nohit = False
Length = 6
Width = 4
Height = 1
Left = 602
Top = 146
end
end
type
TForm1 = class(TForm)
MNOglControl1: TMNOglControl;
MnOglCanvas1: TMnOglCanvas;
MNOglScene1: TMNOglScene;
MNOglBox1: TMNOglBox;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Second i want to describe the way when you do not want to install the MNOgl package:
Let us start with a new project. Change the uses list and add the units _mnoglcanvas, _mnogltools to your list.
e.g.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
_mnoglcanvas, _mnogltools;
Add the following private valriables to your form:
MNOglControl1:TMNOglControl;
MNOglCanvas1:TMNOglCanvas;
MNOglScene1:TMNOglScene;
MNOglBox1:TMNOglBox;
TForm1 = class(TForm)
private
{ Private declarations }
MNOglControl1:TMNOglControl;
MNOglCanvas1:TMNOglCanvas;
MNOglScene1:TMNOglScene;
MNOglBox1:TMNOglBox;
public
{ Public declarations }
end;
Then enter the FormShow method and we will create the components we will need:
procedure TForm1.FormShow(Sender: TObject);
begin
// create the WinControl for the OpenGL render context
// herein your shapes will be played
MNOglControl1 := TMNOglControl.Create(self);
MNOglControl1.Align := alClient;
MNOglControl1.Parent := self;
// create the MNOglCanvas
MNOglCanvas1 := TMNOglCanvas.Create (self);
// assign the WinControl -- and the render
// context will be created
MNOglCanvas1.WinControl := MNOglControl1;
// create the scene (OpenGL calls it DisplayList)
MNOglScene1 := TMNOglScene.Create (self);
// and tell the scene in which Canvas it will be played
MNOglScene1.MnOglCanvas := MNOglCanvas1;
// create the box
MNOglBox1 := TMNOglBox.Create (self);
// ant tell the box to which scene it will belong
MNOglBox1.Scene := MNOglScene1;
// change properties of the box
with MNOglBox1 do begin
Length := 4;
Width := 3;
Height := 2;
end;
end;
If you want the scene to rotate then just add a TMNOglNav (a navigator) to your form and set the property MNOglCanvas to MNOglCanvas1. When you start the program you can then press the left mouse button on the MNOglNav component and move the mouse. With left double click the view will be reset.
Have fun
Leopold Minikus