Autor Beitrag
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Di 01.08.06 22:20 
Ich habe trotz einer recht aufwendigen Renderprocedure in Application.onidle keine 100% CPU-Auslastung obwohl dies ja eigentlich der Fall sein sollte:

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:
procedure TForm1.Render;
begin
  i := i + 0.005;
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);
 
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  glTranslatef(positionx, positiony, positionz);

  {glBegin(GL_QUADS);
    glVertex3f(-1,-1, 0);
    glVertex3f( 1,-1, 0);
    glVertex3f( 1, 1, 0);
    glVertex3f(-1, 1, 0);
  glEnd;}


  glBegin(GL_QUADS);
    glTexCoord2f(0,1); glVertex3f(-1,-1, 0);
    glTexCoord2f(1,1); glVertex3f( 1,-1, 0);
    glTexCoord2f(1,0); glVertex3f( 1, 1, 0);
    glTexCoord2f(0,0); glVertex3f(-1, 1, 0);
  glEnd;

  glMatrixMode(GL_TEXTURE);
    glLoadIdentity;
    glTranslatef(i, 0, 0);
  glMatrixMode(GL_MODELVIEW);

  SwapBuffers(DC);
end;

procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
begin
  StartTime:= GetTickCount;
  Render;

  DrawTime:= GetTickCount - StartTime;
  Inc(TimeCount, DrawTime);
  Inc(FrameCount);
 
  if TimeCount >= 1000 then begin
    Frames:= FrameCount;
    TimeCount:= TimeCount - 1000;
    FrameCount:= 0;
    Caption:= InttoStr(Frames) + 'FPS';
    ErrorHandler;
  end;
 
  Done:= false;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormResize(Sender: TObject);
begin
  ...
  IdleHandler(Sender, tmpBool);
end;


Nach tutorial sollte da aber eine Auslastung von 100% sichtbar sein, welche bei mir bei 1,7% liegt...

Ich korrieigiere: Bei einer riesigen Textur auf Vollbild erreiche ich Maximal 46%
Und flüsseig läufts gar nicht... irgendwas mach ich doch falsch...

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
sekzero
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 57



BeitragVerfasst: Mi 02.08.06 00:11 
Ähm und wo ist das Problem?
Was hast du denn vor?
Verstehe den Sinn nicht so ganz, warum solle man zwanghaft versuchen eine 100%Cpu Auslastung hinzubekommen?
oern
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 142

Linux, Win XP
D7
BeitragVerfasst: Mi 02.08.06 08:01 
Nun mögliche urscachen könnten Duo Core? CPU sein ober deine Anwendung wird mit einer zu geringen priorität ausgeführt.

mfg, Björn

_________________
Ich hab eine Signatur
Spaceguide
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 552


(D3/D7/D8) Prof.
BeitragVerfasst: Mi 02.08.06 08:39 
Vielleicht limitiert bei OpenGl auch die Grafikkarte.
Phobeus
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1280

Linux (FC6), WinXP Pro (Box)
D6 Pers, D7 Pro, FPC 2.x
BeitragVerfasst: Mi 02.08.06 10:16 
Bei einer großen Textur bricht die Geschwindigkeit ein und es ruckelt? Entweder nutzt Du ein mächtig antiquierttes Stück Hardware oder ich würde erst einmal prüfen, ob dein System auch wirklich 3D-gestütztes OpenGL hat. Was für eine Grafikkarte besitzt Du und was gibt glGetString(GL_VENDOR); für einen String zurück. Handelt es sich hierbei um Microsoft, so ist deren Software Renderer am Werk und Du solltest alle weiteren Fehlersuchen sofort einstellen. Das grob ist gelinde gesagt Software vom Weltmarkführer ;)

Das erklärt zwar nicht dein "CPU"-Problem, allerdings sollte eine halbwegs zeitgemäße Grafikkarte (sprich ab 30€) selbst bei intensiven Einsatz von Shadern bei realistischen Einsatz kaum groß in die Knie zu zwingen sein. Probiere zudem bei DGL bitte die vorgefertigten Templates. Treten die Probleme auch dort auf, handelt es wahrscheinlich um diene Systemkonfiguration, tritt das Problem dort nicht auf, solltest Du noch einmal deinen Source Code damit vergleichen.

_________________
"Menschen sterben nicht wenn man sie zu Grabe trägt, sondern wenn sie ihre Träume verlieren..."
SnuffMaster23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Mi 02.08.06 12:18 
Hast du denn ein glBindTexture drin?
Ich kann in deinem Code nämlich keins finden.
Früher hab ichs auch ohne gemacht, das frisst verdammt Geschwindigkeit.
Aber eigentlich müsstest du trotzdem 100% Auslastung kriegen weil das Prog ja auf die Graka warten muss.

_________________
Nichts ist wahr - Alles ist erlaubt
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 04.08.06 10:11 
So, hab mal das ganze Prog hinzugefügt damit ihr euch ein Bild machen könnt.

glBindTexture is drin und wenn jemand das ganze mal testen will, die Pfeiltasten L und R sind für Links und Rechts, die Tasten Oben und Unten sind für die Z-Achse und wenn man shift gedrückt hält kann man das Ding drehen, je näher man jetzt dran'zoomt' destso langsamer gehts.

Meine GraKa is ne Geforce FX 5600 SE und ich hab einen Pentium 4 (2,8 Ghz) Prozessor.

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:
206:
207:
208:
209:
210:
211:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dglOpenGL, ExtCtrls, SDL, SDL_Image;

type
TForm1 = class(TForm)
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure IdleHandler(Sender: TObject; var Done: Boolean);
    procedure FormResize(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private    { Private-Deklarationen }
    StartTime, TimeCount, FrameCount  : Cardinal; //FrameCounter
    Frames, DrawTime                  : Cardinal; //& Timebased Movement
    procedure SetupGL;
    procedure Init;
    procedure Render;
    procedure ErrorHandler;
    procedure InitTextures;
  public    { Public-Deklarationen }
    DC                                : HDC;  //Handle auf Zeichenfläche
    RC                                : HGLRC;//Rendering Context
  end;

const
  NearClipping = 1;
  FarClipping  = 1000;

var
  Form1: TForm1;
  positionx, positiony, positionz, rotateaxis: real;
  texID: gluInt;
  i, j: real;
  oldX, oldY: integer;
  middle: boolean;

implementation

{$R *.dfm}

procedure TForm1.InitTextures;
var
  tex : PSDL_Surface;
begin
  tex := IMG_Load('textur.jpg');
  if assigned(tex) then
  begin
    glGenTextures(1, @TexID);
    glBindTexture(GL_TEXTURE_2D, TexID);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Achtung! Einige Bildformate erwarten statt GL_RGB, GL_BGR. Diese Konstante fehlt in den Standard-Headern
    glTexImage2D(GL_TEXTURE_2D, 0, 3, tex^.w, tex^.h,0, GL_RGB, GL_UNSIGNED_BYTE, tex^.pixels);

    SDL_FreeSurface(tex);
    glEnable(GL_TEXTURE_2D);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DC:= GetDC(Handle);
  if not InitOpenGL then Application.Terminate;
  RC:= CreateRenderingContext( DC,
                               [opDoubleBuffered],
                               32,
                               24,
                               0,0,0,
                               0);
  ActivateRenderingContext(DC, RC);
  SetupGL;
  Init;
  InitTextures;
  Application.OnIdle := IdleHandler;
end;

procedure TForm1.Init;
begin
  positionx := 0;
  positiony := 0;
  positionz := -5;
  rotateaxis := 0;
end;

procedure TForm1.SetupGL;
begin
  glClearColor(0.0, 0.0, 0.0, 0.0); //Hintergrundfarbe
  glEnable(GL_DEPTH_TEST);          //Tiefentest aktivieren
  glEnable(GL_CULL_FACE);           //Backface Culling aktivieren
end;

procedure TForm1.FormResize(Sender: TObject);
var tmpBool : Boolean;
begin
  glViewport(0, 0, ClientWidth, ClientHeight);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);
 
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;
  IdleHandler(Sender, tmpBool);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DeactivateRenderingContext;
  DestroyRenderingContext(RC);
  ReleaseDC(Handle, DC);
end;

procedure TForm1.Render;
begin
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  glTranslatef(positionx, positiony, positionz);
  glRotatef(rotateaxis, 0, 1, 0);


  glPushMatrix();
    glBegin(GL_QUADS);
      glTexCoord2f(0, 1); glVertex3f(-1,-1, 0);
      glTexCoord2f(1, 1); glVertex3f( 1,-1, 0);
      glTexCoord2f(1, 0); glVertex3f( 1, 1, 0);
      glTexCoord2f(0, 0); glVertex3f(-1, 1, 0);
    glEnd;
  glPopMatrix();

  glMatrixMode(GL_TEXTURE);
    glLoadIdentity;
    glTranslatef(i, j, 0);
  glMatrixMode(GL_MODELVIEW);

  SwapBuffers(DC);
end;


procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
begin
  StartTime:= GetTickCount;
  Render;

  DrawTime:= GetTickCount - StartTime;
  Inc(TimeCount, DrawTime);
  Inc(FrameCount);
 
  if TimeCount >= 1000 then begin
    Frames:= FrameCount;
    TimeCount:= TimeCount - 1000;
    FrameCount:= 0;
    Caption:= InttoStr(Frames) + 'FPS';
    ErrorHandler;
  end;
 
  Done:= false;
end;

procedure TForm1.ErrorHandler;
begin
  Form1.Caption := gluErrorString(glGetError);
end;



procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Shift = [ssShift] then begin
   if key = VK_LEFT then begin
      rotateaxis := rotateaxis - 1;
      glRotatef(rotateaxis, 0, 1, 0);
    end;
    if key = VK_RIGHT then begin
      rotateaxis := rotateaxis + 1;
      glRotatef(rotateaxis, 0, 1, 0);
    end;
  end else begin
   if key = VK_DOWN then begin
      positionz := positionz - 1;
      glTranslatef(0, 0, positionz);
    end;
    if key = VK_UP then begin
      positionz := positionz + 1;
      glTranslatef(0, 0, positionz);
    end;
   if key = VK_LEFT then begin
      positionx := positionx - 0.1;
      glTranslatef(0, 0, positionx);
    end;
    if key = VK_RIGHT then begin
      positionx := positionx + 0.1;
      glTranslatef(0, 0, positionx);
    end;
  end;
end;


end.
SnuffMaster23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Fr 04.08.06 10:44 
Also ich würde da einiges ändern (ich hab mir nur Render angeschaut):
  1. Vieport einstellen nicht in jedem Renderdurchgang sondern im Form.Resize.
  2. Für was Pop- und PushMatrix? Ist imho überflüssig.
  3. Das mit der Texturmatrix vor die Vertexdefinitionen.


Also ich könnte mir gut vorstellen dass 1. die ganze Geschwindigkeit frisst.
Und wenn du nicht die maximalen Frames brauchst: Mach doch ein Sleep mit ca. 10-20 ms rein, geht die CPU-Last rapide runter.

_________________
Nichts ist wahr - Alles ist erlaubt
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 04.08.06 10:50 
1.) Ich finde in Render kein 'Viewport'
2.) Hatte mehrere Objekte drin deshalb war das noch drin. Is in der Form überflüssig ;)
3.) Macht keinen Unterschied...
SnuffMaster23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Fr 04.08.06 10:57 
  1. Mit gluPerspective stellst du den Viewport ein. Das muss wirklich nicht in jedem Renderdurchgang sein ;).
  2. Ok.
  3. Doch, es wirkt sich erst im nächsten Frame aus da dein Quad zu dem Zeitpunkt schon gezeichnet ist ;). Für die Performance natürlich egal.

_________________
Nichts ist wahr - Alles ist erlaubt
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 04.08.06 11:14 
wenn ich aus Render gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping); die Zeile auskomentier dann krieg ich GAR NIX mehr angezeigt...

schwarz, nada, nix. Auch nach einem Resize. Nada, Nix:

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:
procedure TForm1.Render;
begin
  //i := i + 0.005;
  //j := j + 0.005;
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  //gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  glTranslatef(positionx, positiony, positionz);
  glRotatef(rotateaxis, 0, 1, 0);

  glMatrixMode(GL_TEXTURE);
    glLoadIdentity;
    glTranslatef(i, j, 0);
  glMatrixMode(GL_MODELVIEW);

  glPushMatrix();
    glBegin(GL_QUADS);
      glTexCoord2f(0, 1); glVertex3f(-1,-1, 0);
      glTexCoord2f(1, 1); glVertex3f( 1,-1, 0);
      glTexCoord2f(1, 0); glVertex3f( 1, 1, 0);
      glTexCoord2f(0, 0); glVertex3f(-1, 1, 0);
    glEnd;
  glPopMatrix();

  SwapBuffers(DC);
end;
SnuffMaster23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Fr 04.08.06 11:20 
Du musst natürlich das alles ins Resize reintun ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

_________________
Nichts ist wahr - Alles ist erlaubt
Green Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Fr 04.08.06 11:45 
So, hab jetzt alles in Resize drin und auch aus Render rausgenommen, trotzdem laggt das ganze wie ab wenn ich das ding nah ranbring.

Aber kann es sein das das mit der Textur zu tun hat? weil ohne selbige läuft das einwand frei.


Zuletzt bearbeitet von Green am Fr 04.08.06 11:59, insgesamt 1-mal bearbeitet