summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/ptc/examples/ptcgl2.pp
blob: 9e7fe7d3aabdd9baccad291c1cc0aaa7f3d73f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
 PTC OpenGL example for PTCPas
 Copyright (c) Nikolay Nikolov (nickysn@users.sourceforge.net)
 This source code is in the public domain
}

program PtcGL2Example;

{$MODE objfpc}

uses
  ptc, gl, SysUtils;

var
  Console: IPTCConsole;
  Event: IPTCEvent;
  Done: Boolean = False;
begin
  try
    try
      { create console }
      Console := TPTCConsoleFactory.CreateNew;

      { tell PTC we want OpenGL }
      Console.OpenGL_Enabled := True;

      { use OpenGL single buffering }
      Console.OpenGL_Attributes.DoubleBuffer := False;

      { open the console }
      Console.Open('PTC OpenGL single buffering example');

      glClearColor(0.0, 0.0, 0.0, 0.0);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity;
      glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

      { loop until the key 'q' is pressed }
      repeat
        { draw scene }
        glClear(GL_COLOR_BUFFER_BIT);

        glBegin(GL_POLYGON);
          glColor3f(1.0, 0.0, 0.0);
          glVertex3f(0.25, 0.25, 0.0);
          glColor3f(1.0, 1.0, 0.0);
          glVertex3f(0.75, 0.25, 0.0);
          glColor3f(0.5, 0.0, 1.0);
          glVertex3f(0.75, 0.75, 0.0);
          glColor3f(0.0, 1.0, 0.0);
          glVertex3f(0.25, 0.75, 0.0);
        glEnd;

        glFlush;

        { check for events }
        if Console.NextEvent(Event, False, PTCAnyEvent) then
        begin
          { handle keyboard events }
          if Supports(event, IPTCKeyEvent) and (event as IPTCKeyEvent).Press then
          begin
            case (event as IPTCKeyEvent).Code of
              PTCKEY_Q: Done := True;
            end;
          end;
        end;
      until Done;
    finally
      if Assigned(Console) then
        Console.Close;
    end;
  except
    on Error: TPTCError do
      { report error }
      Error.Report;
  end;
end.