source: GraphicTest/Methods/UMethodOpenGL.pas

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