* split TglBitmap into TglBitmap and TglBitmapData to be able to handle load, save...
[glBitmap.git] / examples / TextureFromFunction / TextureFromFunction.lpr
index f960c25..7c60833 100644 (file)
@@ -11,6 +11,7 @@ uses
 var
   oglWindow: TOpenGLWindow;
   running: Boolean = true;
+  data: TglBitmapData;
   tex: TglBitmap2D;
 
 function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
@@ -74,14 +75,19 @@ end;
 begin
   oglWindow := CreateOpenGLWindow('TextureFromFunction', 800, 600, @WindowProc);
   try
-    // create texture use either GenerateTextureFunc1 or GenerateTextureFunc2
-    tex := TglBitmap2D.Create(
-      glBitmapSize(512, 512),
-      tfRGBA8ub4,
-      @GenerateTextureFunc1
-      //@GenerateTextureFunc2
-    );
-    tex.GenTexture;
+    tex  := TglBitmap2D.Create;       // create texture object
+    data := TglBitmapData.Create;     // create texture data object
+    try
+      data.LoadFromFunc(              // generate texture data using either GenerateTextureFunc1 or GenerateTextureFunc2
+        glBitmapSize(512, 512),
+        tfRGBA8ub4,
+        @GenerateTextureFunc1
+        //@GenerateTextureFunc2
+      );
+      tex.UploadData(data);           // upload data to video card
+    finally
+      FreeAndNil(data);               // after upload is done, the data object could be freed to save memory
+    end;
 
     while running and ProgressMesages do begin
       RenderLoop;