source: GraphicTest/Methods/MethodOpenGL.pas

Last change on this file was 573, checked in by chronos, 5 months ago
  • Modified: Build with Lazarus 3.4.
  • Modified: Removed U prefix from unit names.
File size: 2.8 KB
Line 
1unit MethodOpenGL;
2
3interface
4
5uses
6 Classes, SysUtils, DrawMethod, FastBitmap
7 {$IFDEF OPENGL}, GL, GLExt, OpenGLContext{$ENDIF};
8
9{$IFDEF OPENGL}
10type
11 { TMethodOpenGL }
12
13 TMethodOpenGL = class(TDrawMethodOpenGL)
14 constructor Create; override;
15 destructor Destroy; override;
16 procedure DrawFrame(FastBitmap: TFastBitmap); override;
17 end;
18{$ENDIF}
19
20
21implementation
22
23{$IFDEF OPENGL}
24{ TMethodOpenGL }
25
26constructor TMethodOpenGL.Create;
27begin
28 inherited;
29 Caption := 'OpenGL';
30 PaintObject := poOpenGL;
31 Description.Add('This method use OpenGL 3D acceleration with simple one 2D orthogonal plane covering all visible area.' +
32 'Texture data is loaded from bitmap.');
33end;
34
35destructor TMethodOpenGL.Destroy;
36begin
37 inherited;
38end;
39
40procedure TMethodOpenGL.DrawFrame(FastBitmap: TFastBitmap);
41var
42 X, Y: Integer;
43 P: PCardinal;
44 R: PCardinal;
45const
46 GL_CLAMP_TO_EDGE = $812F;
47begin
48 glLoadIdentity;
49 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
50 //glLoadIdentity; { clear the matrix }
51 //glTranslatef(0.0, 0.0, -3.0); // -2.5); { viewing transformation }
52
53 P := OpenGLBitmap;
54 with FastBitmap do
55 for Y := 0 to Size.Y - 1 do begin
56 R := P;
57 for X := 0 to Size.X - 1 do begin
58 //R^ := Round($ff * (Y / Size.Y)) or $ff000000;
59 R^ := NoSwapBRComponent(Pixels[X, Y]) or $ff000000;
60 Inc(R);
61 end;
62 Inc(P, Size.X);
63 end;
64
65 //glRotatef(30.0, 0, 0, 1.0);
66 glTranslatef(-OpenGLControl.Width div 2, -OpenGLControl.Height div 2, 0.0);
67
68 glEnable(GL_TEXTURE_2D);
69 glBindTexture(GL_TEXTURE_2D, TextureId);
70 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
71 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
74 glTexImage2D(GL_TEXTURE_2D, 0, 4, OpenGLControl.Width, OpenGLControl.Height,
75 0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
76 //glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 256,
77 //0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap);
78
79 //Define how alpha blending will work and enable alpha blending.
80 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
81 //glEnable(GL_BLEND);
82
83 glBegin(GL_QUADS);
84 //glBegin(GL_POLYGON);
85 glColor3ub(255, 255, 255);
86 glTexCoord2f(0, 0);
87 glVertex3f(0, 0, 0);
88 glTexCoord2f(OpenGLControl.Width div 2, 0);
89 glVertex3f(OpenGLControl.Width, 0, 0);
90 glTexCoord2f(OpenGLControl.Width div 2, OpenGLControl.Height div 2);
91 glVertex3f(OpenGLControl.Width, OpenGLControl.Height, 0);
92 glTexCoord2f(0, OpenGLControl.Height div 2);
93 glVertex3f(0, OpenGLControl.Height, 0);
94 glEnd();
95
96 OpenGLControl.SwapBuffers;
97end;
98
99{$ENDIF}
100
101end.
102
Note: See TracBrowser for help on using the repository browser.