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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, openGL12;
type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure SetDCPixelFormat(Handle: HDC); Procedure InitGL; procedure DrawScene; procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); private { Private-Deklarationen } public { Public-Deklarationen } end;
var Form1: TForm1; h_DC:hDC; HRC:HGLRC; x:real=1; y:real=1; vx:real=0.01; vy:real=0.01; rotateX:single; implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin initopenGL; h_DC:=GetDC(handle); SetDCPixelFormat(h_DC); hrc:=wglCreateContext(h_DC); wglmakecurrent(h_DC,hRC); initgl; Application.OnIdle:=ApplicationEvents1Idle; end;
procedure Tform1.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(-100,-111,Width,Height); glMatrixMode(GL_PROJECTION); glLoadIdentity; gluPerspective(100,width/height,1,1000); glMatrixMode(GL_MODELVIEW); end;
procedure TForm1.DrawScene; var i:integer;
begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity; gltranslate(0,0,-20); {glrotate(rotateX,0,0,1);} glbegin(GL_polygon); glcolor3f(0.1,0.2,0.3); glvertex3f(-1+x,-3+Y,0); glcolor3f(0.8,0.2,0.1); glvertex3f(-1+x,1+y,0); glcolor3f(0.5,0.1,0); glvertex3f(1+x,1+y,0); glcolor3f(0.1,0.7,0); glvertex3f(1+x,-1+y,0); glcolor3f(1,0.5,0.1); glvertex3f(1+x,5+y,-25); glvertex3f(5+x,1+y,-15); glend; SwapBuffers(h_DC); RotateX:=RotateX + 0.1; if RotateX>360 then RotateX:=RotateX - 360;
y:=y+vy; x:=x+vx; if y>=40 then vy:=vy*-1; if x>=45 then vx:=vx*-1; if y<=-16 then vy:=vy*-1; if x<=-20 then vx:=vx*-1;
end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); begin DrawScene; Done:=False; end;
end. |