summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/examples/graphics/3D/Display_List/DisplayList.pp
blob: 807268d45a287c632572a262e56241ab049a7054 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
program DisplayList;

{$mode objfpc}

uses
  ctypes, nds9;

var
  triangle: array [0..12] of cuint32;  // Display List
  rotateX: cfloat = 0.0;
  rotateY: cfloat = 0.0;
  keys: cuint16;

procedure SetDisplayList;
begin
  triangle[0]  := 12;
  triangle[1]  := FIFO_COMMAND_PACK(FIFO_BEGIN, FIFO_COLOR, FIFO_VERTEX16, FIFO_COLOR);
  triangle[2]  := GL_TRIANGLE;
  triangle[3]  := RGB15(31,0,0);
  triangle[4]  := VERTEX_PACK(inttov16(-1),inttov16(-1)); 
  triangle[5]  := VERTEX_PACK(0,0);
  triangle[6]  := RGB15(0,31,0);
  triangle[7]  := FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_COLOR, FIFO_VERTEX16, FIFO_END);
  triangle[8]  := VERTEX_PACK(inttov16(1),inttov16(-1));
  triangle[9]  := VERTEX_PACK(0,0);
  triangle[10] := RGB15(0,0,31);
  triangle[11] := VERTEX_PACK(inttov16(0),inttov16(1)); 
  triangle[12] := VERTEX_PACK(0,0);
end;

begin
  //set mode 0, enable BG0 and set it to 3D
  videoSetMode(MODE_0_3D);

  // initialize gl
  glInit();

  // enable antialiasing
  glEnable(GL_ANTIALIAS);

  // setup the rear plane
  glClearColor(0,0,0,31); // BG must be opaque for AA to work
  glClearPolyID(63); // BG must have a unique polygon ID for AA to work
  glClearDepth($7FFF);

  //this should work the same as the normal gl call
  glViewport(0,0,255,191);

  SetDisplayList;	

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70, 256.0 / 192.0, 0.1, 40);

  gluLookAt(  0.0, 0.0, 1.0,    //camera position 
              0.0, 0.0, 0.0,    //look at
              0.0, 1.0, 0.0);   //up

  while true do
  begin
    glPushMatrix();

    //move it away from the camera
    glTranslatef32(0, 0, floattof32(-1.0));

    glRotateX(rotateX);
    glRotateY(rotateY);
    
    glMatrixMode(GL_TEXTURE);

    glLoadIdentity();
    
    glMatrixMode(GL_MODELVIEW);

    //not a real gl function and will likely change
    glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
    
    scanKeys();
    
    keys := keysHeld();
    if (keys and KEY_START) <> 0 then break;
    
    if ((keys and KEY_UP)) <> 0 then rotateX := rotateX + 3;
    if ((keys and KEY_DOWN)) <> 0 then rotateX := rotateX - 3;
    if ((keys and KEY_LEFT)) <> 0 then rotateY := rotateY + 3;
    if ((keys and KEY_RIGHT)) <> 0 then rotateY := rotateY - 3;

    glCallList(@triangle);	

    glPopMatrix(1);

    glFlush(0);
  end;

end.