summaryrefslogtreecommitdiff
path: root/packages/libndsfpc/examples/graphics/3D/nehe/lesson05/lesson05.pp
blob: d8e770ef156c12be816d6e6e231f28fdf3e4faa3 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(****************************************
 * 		NDS NeHe Lesson 05    			*
 * 		Author: Dovoto					*
 ****************************************)

program Lesson05;

{$mode objfpc}

uses
  ctypes, nds9;

var
  rtri: cfloat = 0.0;
  rquad: cfloat = 0.0;


function DrawGLScene(): boolean;
begin
	glLoadIdentity();									// Reset The Current Modelview Matrix
	glTranslatef(-1.5,0.0,-6.0);						// Move Left 1.5 Units And Into The Screen 6.0
	glRotatef(rtri,0.0,1.0,0.0);						// Rotate The Triangle On The Y axis ( NEW )
	glBegin(GL_TRIANGLES);								// Start Drawing A Triangle
		glColor3f(1.0,0.0,0.0);						// Red
		glVertex3f( 0.0, 1.0, 0.0);					// Top Of Triangle (Front)
		glColor3f(0.0,1.0,0.0);						// Green
		glVertex3f(-1.0,-1.0, 1.0);					// Left Of Triangle (Front)
		glColor3f(0.0,0.0,1.0);						// Blue
		glVertex3f( 1.0,-1.0, 1.0);					// Right Of Triangle (Front)
		glColor3f(1.0,0.0,0.0);						// Red
		glVertex3f( 0.0, 1.0, 0.0);					// Top Of Triangle (Right)
		glColor3f(0.0,0.0,1.0);						// Blue
		glVertex3f( 1.0,-1.0, 1.0);					// Left Of Triangle (Right)
		glColor3f(0.0,1.0,0.0);						// Green
		glVertex3f( 1.0,-1.0, -1.0);					// Right Of Triangle (Right)
		glColor3f(1.0,0.0,0.0);						// Red
		glVertex3f( 0.0, 1.0, 0.0);					// Top Of Triangle (Back)
		glColor3f(0.0,1.0,0.0);						// Green
		glVertex3f( 1.0,-1.0, -1.0);					// Left Of Triangle (Back)
		glColor3f(0.0,0.0,1.0);						// Blue
		glVertex3f(-1.0,-1.0, -1.0);					// Right Of Triangle (Back)
		glColor3f(1.0,0.0,0.0);						// Red
		glVertex3f( 0.0, 1.0, 0.0);					// Top Of Triangle (Left)
		glColor3f(0.0,0.0,1.0);						// Blue
		glVertex3f(-1.0,-1.0,-1.0);					// Left Of Triangle (Left)
		glColor3f(0.0,1.0,0.0);						// Green
		glVertex3f(-1.0,-1.0, 1.0);					// Right Of Triangle (Left)
	glEnd();											// Done Drawing The Pyramid

	glLoadIdentity();									// Reset The Current Modelview Matrix
	glTranslatef(1.5,0.0,-7.0);						// Move Right 1.5 Units And Into The Screen 7.0
	glRotatef(rquad,1.0,1.0,1.0);					// Rotate The Quad On The X axis ( NEW )
	glBegin(GL_QUADS);									// Draw A Quad
		glColor3f(0.0,1.0,0.0);						// Set The Color To Green
		glVertex3f( 1.0, 1.0,-1.0);					// Top Right Of The Quad (Top)
		glVertex3f(-1.0, 1.0,-1.0);					// Top Left Of The Quad (Top)
		glVertex3f(-1.0, 1.0, 1.0);					// Bottom Left Of The Quad (Top)
		glVertex3f( 1.0, 1.0, 1.0);					// Bottom Right Of The Quad (Top)
		glColor3f(1.0,0.5,0.0); 					// Set The Color To Orange
		glVertex3f( 1.0,-1.0, 1.0);					// Top Right Of The Quad (Bottom)
		glVertex3f(-1.0,-1.0, 1.0);					// Top Left Of The Quad (Bottom)
		glVertex3f(-1.0,-1.0,-1.0);					// Bottom Left Of The Quad (Bottom)
		glVertex3f( 1.0,-1.0,-1.0);					// Bottom Right Of The Quad (Bottom)
		glColor3f(1.0,0.0,0.0);						// Set The Color To Red
		glVertex3f( 1.0, 1.0, 1.0);					// Top Right Of The Quad (Front)
		glVertex3f(-1.0, 1.0, 1.0);					// Top Left Of The Quad (Front)
		glVertex3f(-1.0,-1.0, 1.0);					// Bottom Left Of The Quad (Front)
		glVertex3f( 1.0,-1.0, 1.0);					// Bottom Right Of The Quad (Front)
		glColor3f(1.0,1.0,0.0);						// Set The Color To Yellow
		glVertex3f( 1.0,-1.0,-1.0);					// Top Right Of The Quad (Back)
		glVertex3f(-1.0,-1.0,-1.0);					// Top Left Of The Quad (Back)
		glVertex3f(-1.0, 1.0,-1.0);					// Bottom Left Of The Quad (Back)
		glVertex3f( 1.0, 1.0,-1.0);					// Bottom Right Of The Quad (Back)
		glColor3f(0.0,0.0,1.0);						// Set The Color To Blue
		glVertex3f(-1.0, 1.0, 1.0);					// Top Right Of The Quad (Left)
		glVertex3f(-1.0, 1.0,-1.0);					// Top Left Of The Quad (Left)
		glVertex3f(-1.0,-1.0,-1.0);					// Bottom Left Of The Quad (Left)
		glVertex3f(-1.0,-1.0, 1.0);					// Bottom Right Of The Quad (Left)
		glColor3f(1.0,0.0,1.0);						// Set The Color To Violet
		glVertex3f( 1.0, 1.0,-1.0);					// Top Right Of The Quad (Right)
		glVertex3f( 1.0, 1.0, 1.0);					// Top Left Of The Quad (Right)
		glVertex3f( 1.0,-1.0, 1.0);					// Bottom Left Of The Quad (Right)
		glVertex3f( 1.0,-1.0,-1.0);					// Bottom Right Of The Quad (Right)
	glEnd();											// Done Drawing The Quad

	rtri:=rtri+0.2;											// Increase The Rotation Variable For The Triangle ( NEW )
	rquad:=rquad-0.15;										// Decrease The Rotation Variable For The Quad ( NEW )
	result := true;										// Keep Going
end;


begin	
	// Setup the Main screen for 3D 
	videoSetMode(MODE_0_3D);
	
	// initialize the geometry engine
	glInit();
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// Specify the Clear Color and Depth 
	glClearColor(0,0,0,31);
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth($7FFF);
	
		// Set our viewport to be the same size as the screen
	glViewPort(0,0,255,191);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();	
	gluPerspective(70, 256.0 / 192.0, 0.1, 100);
	
	//ds specific, several attributes can be set here	
	glPolyFmt(POLY_ALPHA(31) or POLY_CULL_NONE);
		
  while true do
	begin
		// Set the current matrix to be the model matrix
		glMatrixMode(GL_MODELVIEW);
		
		//Push our original Matrix onto the stack (save state)
		glPushMatrix();	

		DrawGLScene();
		
		// Pop our Matrix from the stack (restore state)
		glPopMatrix(1);

		// flush to screen	
		glFlush(0);
    
    swiWaitForVBlank();	
	end;
end.