Autor Beitrag
masterofswim
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Do 30.09.10 18:10 
Hallo also verzweifel hier gleich ! Wenn ich das Programm starte passiert garnichts auf dem Desktop es wird lediglich eine showmessage mit E Access Violation zugriffsverletzung angezeigt.

Mein Quelltext:

ausblenden volle Höhe Delphi-Quelltext
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:
unit UHaupt;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,OpenGL12,opengl, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);

private
procedure SetDCPixelFormat(Handle: HDC);
procedure InitOpenGL;
procedure Drawlandscape;
procedure checkkeys;
procedure drawscene;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;
h_DC: hDC;
hRC: HGLRC;
Keys: Array[0..255of Boolean;
Rotate: Single;
RealFPS: Integer = 100;
FPS: Integer;
PosX, PosZ: Single;
implementation

{$R *.dfm}

{ TForm1 }





procedure TForm1.Drawlandscape;
var
j, i: Integer;
r, wi, w, x, y: Double;
begin
wi:=360/40;
glColor3f(0.01.00.0);
glBegin(GL_LINES);
for i:=1 to 40 do begin
w:=(PI/180)*(wi*i-(wi/2));
x:=(-5/2)+(5/2+cos(w)*(5+5)/2);
y:=(5/2)+(-5/2+sin(w)*(-5-5)/2);
glVertex3f(0.0, -0.40.0);
glVertex3f(x, -0.4, y);
end;
glEnd;
r:=0;
for j:=1 to 11 do begin
glBegin(GL_LINE_LOOP);
for i:=1 to 40 do begin
w:=(PI/180)*(wi*i-(wi/2));
x:=(-r/2)+(r/2+cos(w)*(r+r)/2);
y:=(r/2)+(-r/2+sin(w)*(-r-r)/2);
glVertex3f(x, -0.4, y);
end;
glEnd;
r:=r+0.5;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
InitOpenGL;
h_DC:=GetDC(Handle);
SetDCPixelFormat(h_DC);
hRC:=wglCreateContext(h_DC);
wglMakeCurrent(h_DC,hRC);
end;

procedure TForm1.InitOpenGL;

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;
gluPerspective(45,Width/Height,1,100);
glMatrixMode(GL_MODELVIEW);
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.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Keys[Key]:=true;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Keys[Key]:=false;
end;


procedure TForm1.checkkeys;
begin
if Keys[VK_LEFT] then begin
Rotate:=Rotate - 2 * (100 / RealFPS);
if Rotate<0 then
Rotate:=Rotate + 360;
end;
if Keys[VK_RIGHT] then begin
Rotate:=Rotate + 2 * (100 / RealFPS);
if Rotate>360 then
Rotate:=Rotate - 360;
end;
if Keys[VK_UP] then begin
PosX:=PosX + Sin(-Rotate * (PI / 180)) * (0.1);
PosZ:=PosZ + Cos(-Rotate * (PI / 180)) * (0.1);
end;
if Keys[VK_DOWN] then begin
PosX:=PosX - Sin(-Rotate * (PI / 180)) * (0.1);
PosZ:=PosZ - Cos(-Rotate * (PI / 180)) * (0.1);
end;
end;
procedure TForm1.drawscene;
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
CheckKeys;
glRotated(Rotate,0,1,0);
glTranslated(1,0,2);
DrawLandscape;

SwapBuffers(h_DC);
inc(FPS)
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
RealFPS:=FPS;
FPS:=0;
Rotate:=Rotate + (0.5 * (100 / RealFPS))
end;

procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
DrawScene;
Done:=False;
end;

end.


Zuletzt bearbeitet von masterofswim am Do 30.09.10 18:51, insgesamt 1-mal bearbeitet
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Do 30.09.10 18:21 
bitte bitte delphi tags... das läst sich so nicht lesen
masterofswim Threadstarter
Hält's aus hier
Beiträge: 14



BeitragVerfasst: Do 30.09.10 18:43 
Wie geht das bin neu hier?
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 30.09.10 18:47 
Das geile hier ist: Auch das Forum hat eine Hilfe-Funktion. Rat mal was diese macht. ;)

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 30.09.10 18:51 
Ich hab die Delphi-Tags mal eingefügt.

Zum Thema kann ich nichts sagen, aber ein :welcome: in der EE ist noch drin. ;-)

_________________
We are, we were and will not be.
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Do 30.09.10 23:00 
Debugger an, Breakpoint auf erste Anweisung in dem Code und dann Zeile für Zeile durchgehen. Fehler gefunden --> Beheben

Für diesen Beitrag haben gedankt: masterofswim