Still image (single frame) or how to stop opengl? lazarus / 39-Graphics ---------------------------------------------------------------------- Peiman · 2011-07-13 20:57 Hi, Opengl refreshes the scene automatically by a certain FPS. I wonder if it is possible to render just one frame. Is there any function to stop its working? I even used destroy destructor. though rendering stopped but the cpu usage remained high until I stopped the main application. ---------------------------------------------------------------------- Leledumbo · 2011-07-14 04:44 QuoteOpengl refreshes the scene automatically by a certain FPSAre you sure? Coz in my app, the main loop does it. And without, the scene doesn't get refreshed at all. Would you mind showing some code? ---------------------------------------------------------------------- Peiman · 2011-07-14 06:01 This is the code, TT and C are depth-sorted arrays of triangles and their respective colors. I used the bool variable Q to assure only once the paint is done and on the second time it destroys the openglcontrol1. After calling the destroy method, it does not render any more, but the cpu core #4 keeps its 40% performance. urender, geotypes and geofunc are my units for geometrical calculations Code: [Select]uses   Classes, Windows,SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs,   OpenGLContext, GL, GLU, urender, geotypes, geofunc; type   { TForm1 }   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);     procedure OpenGLControl1Paint(Sender: TObject);   private   public     OpenGLControl1: TOpenGLControl;   end; var   Form1: TForm1;   Q : boolean = true; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); begin   OpenGLControl1:=TOpenGLControl.Create(form1);   with OpenGLControl1 do begin     Name:='OpenGLControl1';     Align:=alClient;     Parent:=Self;     OnPaint:=@OpenGLControl1Paint;     AutoResizeViewport:=true;   end; end; procedure TForm1.OpenGLControl1Paint(Sender: TObject); var   i,j,N : integer;   r : single; begin if Q then   begin   glClearColor(1.0, 1.0, 1.0, 1.0);   glClear(GL_COLOR_BUFFER_BIT);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   gluPerspective(45.0, double(width) / height, 0.1, 100.0);   glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   gluLookAt(5,5,5,0,0,0,0,1,0);   glEnable(GL_BLEND);   glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // opengl geometry   n := 10;   for i := 0 to n-1 do     begin     glBegin(GL_TRIANGLES);     glColor4f(C[i].x,C[i].y,C[i].z,0.15);       for j := 0 to 2 do         glVertex3f( TT[i,j].x, TT[i,j].y, TT[i,j].z);      glEnd();     end;   OpenGLControl1.SwapBuffers;   Q := not(Q);   end else   OpenGLControl1.destroy; end; end. ---------------------------------------------------------------------- User137 · 2011-07-15 00:52 You shouldn't need to call .Destroy at all. TForm frees all its child components automatically when program ends, such as TButton, TPanel... and TOpenGLControl, one of which you assigned to form1. Anyway, it also looks weird code for 2 reasons: 1) You are calling OpenGLControl1.destroy instead of OpenGLControl1.free (or rather better FreeAndNil(OpenGLControl1) ). You should never call .Destroy directly... I do not know the difference exactly but that is basic. 2) Also destroying an object from within the object itself. Imagine this kind of internal code flow: Code: [Select]procedure TOpenGLControl.HandleEvents begin   ...   case Event of     event_Paint:       DoPaint(self); // <-- Here would be called OpenGLControl1Paint()         // from which you are destroying this object, and propably this whole code block that calls it     ...   end;   ...   DoSomethingElse; // Now if the object is destroyed, everything happening here     // would be undefined and prone to Access violation end; ---------------------------------------------------------------------- Leledumbo · 2011-07-15 04:36 Instead of having Q, you can simple assign nil to OnPaint of OpenGLControl1. I have no idea which code takes 40% cpu, I'll try debugging your code tonight.