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: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OpenGL12, AppEvnts;
type TForm1 = class(TForm) ApplicationEvents1: TApplicationEvents; procedure FormCreate(Sender: TObject); procedure InitGL; procedure DrawScene; procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); procedure FormResize(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private procedure SetBArray; public end;
procedure SetDCPixelFormat(Handle: HDC); var Form1: TForm1; h_DC: hDC; hRC: HGLRC; RotX, RotY,rot :real; MouseOld, MouseNew :TPoint; move, nLO :Boolean; BArray :Array of Array of Integer; Level :integer;
implementation
{$R *.dfm}
procedure TForm1.SetBArray; var i, r, A :integer; c,c2 :real; EoR :TPoint; begin i:=1; r:=0; A:=0; c2:=0;
Level:=0; while Level>=-16 do begin c:=0; while i<=36 do begin BArray[A,0]:=Round(sin(c)*r); BArray[A,1]:=Level; Barray[A,2]:=Round(cos(c)*r); i:=i+1; A:=A+1; c:=c+0.17453292519943295769236907684886; end; i:=1; Level:=Level+1; EoR.X:=Round(sin(c2)*18); EoR.y:=Round(cos(c2)*18); c2:=c2+0.087266463; r:=Round(sqrt(sqr(Level-EoR.y)+sqr(0-EoR.x))); end; end;
procedure TForm1.FormCreate(Sender: TObject); var x:integer; begin Level:=18; x:=0; SetLength(BArray,1286); while x<=1285 do begin SetLength(BArray[x],3); x:=x+1; end; SetBArray; InitOpenGL; h_DC:=GetDC(Handle); SetDCPixelFormat(h_DC); hRC:=wglCreateContext(h_DC); wglMakeCurrent(h_DC,hRC); end;
procedure SetDCPixelFormat(Handle: HDC); var nPixelFormat: GLUint; const pfd: PIXELFORMATDESCRIPTOR = ( nSize: sizeof( PIXELFORMATDESCRIPTOR ); nVersion: 1; dwFlags: PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER; iPixelType: PFD_TYPE_RGBA; cColorBits: 16; cRedBits: 0; cRedShift: 0; cGreenBits: 0; cBlueBits: 0; cBlueShift: 0; cAlphaBits: 0; cAlphaShift: 0; cAccumBits: 0; cAccumRedBits: 0; cAccumGreenBits: 0; cAccumBlueBits: 0; cAccumAlphaBits: 0; cDepthBits: 16; cStencilBits: 0; cAuxBuffers: 0; iLayerType: PFD_MAIN_PLANE; bReserved: 0; dwLayerMask: 0; dwVisibleMask: 0; dwDamageMask: 0 ); begin nPixelFormat:=ChoosePixelFormat(h_DC, @pfd); SetPixelFormat(h_DC,nPixelFormat,@pfd); end;
procedure TForm1.InitGL; begin glClearColor(0,0,0,0); glClearDepth(1); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST);
glViewport(0,0,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity; <span style="color: red">gluPerspective(45,Width/Height,1,100);</span> glMatrixMode(GL_MODELVIEW); end;
procedure TForm1.DrawScene; var i :integer; begin i:=0; glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity; glTranslate(0,0,-100); glRotate(rot,0,1,0); rot:=rot+0.2; glColor3f(0,1,0); while i<=1285 do begin glBegin(GL_Points); glVertex3f(BArray[i,0],BArray[i,1],BArray[i,2]); glEnd; i:=i+1; end; SwapBuffers(h_DC); end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); begin DrawScene; Done:=False; end;
procedure TForm1.FormResize(Sender: TObject); begin glViewport(0, 0, form1.clientWidth, form1.clientHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); <span style="color: red">gluPerspective(45.0, form1.clientWidth/form1.clientHeight, 1, 100.0);</span> glMatrixMode(GL_MODELVIEW); glLoadIdentity(); end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if move=True then begin GetCursorPos(MouseNew); If MouseNew.y>MouseOld.y then RotX:=Rotx+1; If MouseNew.y<MouseOld.y then RotX:=Rotx-1; If MouseNew.x>MouseOld.X then Roty:=Roty+1; If MouseNew.x<MouseOld.X then Roty:=Roty-1; MouseOld:=MouseNew; end; end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if move=false then move:=true else move:=false; end;
end. |