1 program SimpleLoadFromFile;
6 {$IFDEF UNIX}{$IFDEF UseCThreads}
9 Classes, Windows, SysUtils, dglOpenGL, glBitmap, Helper;
12 oglWindow: TOpenGLWindow;
13 running: Boolean = true;
16 function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
23 result := DefWindowProc(hWnd, Msg, wParam, lParam);
29 glColor4f(1, 1, 1, 1);
31 glTexCoord2f(0, 0); glVertex2f(100, 100);
32 glTexCoord2f(1, 0); glVertex2f(700, 100);
33 glTexCoord2f(1, 1); glVertex2f(700, 500);
34 glTexCoord2f(0, 1); glVertex2f(100, 500);
39 { function to generate texture data }
40 procedure GenerateTextureFunc1(var FuncRec: TglBitmapFunctionRec);
42 g1, g2, g3, g4: Single;
44 g1 := (sin(FuncRec.Position.X / 25) + 1) / 2; // generator function 1: large sinus on x position (0.0 to 1.0)
45 g2 := (sin(FuncRec.Position.Y / 25) + 1) / 2; // generator function 2: large sinus on y position (0.0 to 1.0)
46 g3 := FuncRec.Position.X / FuncRec.Size.X; // generator function 3: linear fade on x position (0.0 to 1.0)
47 g4 := FuncRec.Position.Y / FuncRec.Size.Y; // generator function 4: linear fade on y position (0.0 to 1.0)
49 FuncRec.Dest.Data.r := Trunc(g1 * FuncRec.Dest.Range.r);
50 FuncRec.Dest.Data.g := Trunc(g2 * FuncRec.Dest.Range.g);
51 FuncRec.Dest.Data.b := Trunc(g3 * FuncRec.Dest.Range.b);
52 FuncRec.Dest.Data.a := Trunc(g4 * FuncRec.Dest.Range.a);
55 { function to generate texture data }
56 procedure GenerateTextureFunc2(var FuncRec: TglBitmapFunctionRec);
60 x := FuncRec.Position.X / FuncRec.Size.X;
61 y := FuncRec.Position.Y / FuncRec.Size.Y;
62 if (x < 0.05) or (x > 0.95) or (y < 0.05) or (y > 0.95) then
64 FuncRec.Dest.Data := FuncRec.Dest.Range;
65 end else if (y < 0.333) then begin
66 FuncRec.Dest.Data := glBitmapRec4ui(0, 0, 0, 0);
67 end else if (y < 0.666) then begin
68 FuncRec.Dest.Data := glBitmapRec4ui(FuncRec.Dest.Range.r, 0, 0, 0);
70 FuncRec.Dest.Data := glBitmapRec4ui(FuncRec.Dest.Range.r, FuncRec.Dest.Range.g, 0, 0);
75 oglWindow := CreateOpenGLWindow('TextureFromFunction', 800, 600, @WindowProc);
77 // create texture use either GenerateTextureFunc1 or GenerateTextureFunc2
78 tex := TglBitmap2D.Create(
79 glBitmapSize(512, 512),
82 //@GenerateTextureFunc2
86 while running and ProgressMesages do begin
88 SwapBuffers(oglWindow.DC);
92 DestroyOpenGLWindow(oglWindow);