Changeset 211 for GraphicTest/UDrawMethod.pas
- Timestamp:
- Mar 20, 2011, 12:23:08 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/UDrawMethod.pas
r210 r211 8 8 Classes, SysUtils, StdCtrls, ExtCtrls, UPlatform, UFastBitmap, Graphics, 9 9 LCLType, IntfGraphics, fpImage, GraphType, BGRABitmap, BGRABitmapTypes, 10 LclIntf ;10 LclIntf, GL, OpenGLContext; 11 11 12 12 type … … 27 27 FrameDuration: TDateTime; 28 28 PaintObject: TPaintObject; 29 OpenGLBitmap: Pointer; 30 OpenGLControl: TOpenGLControl; 31 TextureId: GLuint; 29 32 constructor Create; virtual; 30 33 destructor Destroy; override; … … 94 97 end; 95 98 99 { TOpenGLMethod } 100 101 TOpenGLMethod = class(TDrawMethod) 102 procedure SetBitmap(const AValue: TBitmap); override; 103 constructor Create; override; 104 destructor Destroy; override; 105 procedure DrawFrame(FastBitmap: TFastBitmap); override; 106 end; 107 108 96 109 const 97 DrawMethodClasses: array[0.. 6] of TDrawMethodClass = (110 DrawMethodClasses: array[0..7] of TDrawMethodClass = ( 98 111 TCanvasPixels, TCanvasPixelsUpdateLock, TLazIntfImageColorsCopy, 99 112 TLazIntfImageColorsNoCopy, TBitmapRawImageData, TBitmapRawImageDataPaintBox, 100 TBGRABitmapPaintBox );113 TBGRABitmapPaintBox, TOpenGLMethod); 101 114 102 115 implementation 116 117 { TOpenGLMethod } 118 119 procedure TOpenGLMethod.SetBitmap(const AValue: TBitmap); 120 begin 121 inherited SetBitmap(AValue); 122 end; 123 124 constructor TOpenGLMethod.Create; 125 begin 126 inherited Create; 127 Caption := 'OpenGL'; 128 PaintObject := poOpenGL; 129 end; 130 131 destructor TOpenGLMethod.Destroy; 132 begin 133 inherited Destroy; 134 end; 135 136 procedure TOpenGLMethod.DrawFrame(FastBitmap: TFastBitmap); 137 var 138 X, Y: Integer; 139 P: PInteger; 140 R: PInteger; 141 const 142 GL_CLAMP_TO_EDGE = $812F; 143 begin 144 (* glEnable(GL_TEXTURE_2D); // enables 2d textures 145 glClearColor(0.0,0.0,0.0,1.0); // sets background color 146 glClearDepth(1.0); 147 glDepthFunc(GL_LEQUAL); // the type of depth test to do 148 glEnable(GL_DEPTH_TEST); // enables depth testing 149 glShadeModel(GL_SMOOTH); // enables smooth color shading 150 {blending} 151 glColor4f(1.0,1.0,1.0,0.5); // Full Brightness, 50% Alpha ( NEW ) 152 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 153 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); 154 *) 155 156 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); 157 //glLoadIdentity; { clear the matrix } 158 //glTranslatef(0.0, 0.0, -3.0); // -2.5); { viewing transformation } 159 160 //glLoadIdentity; { clear the matrix } 161 162 P := OpenGLBitmap; 163 with FastBitmap do 164 for Y := 0 to Size.Y - 1 do begin 165 R := P; 166 for X := 0 to Size.X - 1 do begin 167 //R^ := Round($ff * (Y / Size.Y)) or $ff000000; 168 R^ := NoSwapBRComponent(Pixels[X, Y]) or $ff000000; 169 Inc(R); 170 end; 171 Inc(P, Size.X); 172 end; 173 174 glLoadIdentity; 175 //glRotatef(30.0, 0, 0, 1.0); 176 glTranslatef(-OpenGLControl.Width div 2, -OpenGLControl.Height div 2, 0.0); 177 178 glEnable(GL_TEXTURE_2D); 179 glBindTexture(GL_TEXTURE_2D, TextureId); 180 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 181 //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 182 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 183 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 184 glTexImage2D(GL_TEXTURE_2D, 0, 4, OpenGLControl.Width, OpenGLControl.Height, 185 0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap); 186 //glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 256, 187 //0, GL_RGBA, GL_UNSIGNED_BYTE, OpenGLBitmap); 188 189 //Define how alpha blending will work and enable alpha blending. 190 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 191 //glEnable(GL_BLEND); 192 193 glBegin(GL_QUADS); 194 //glBegin(GL_POLYGON); 195 glColor3ub(255, 255, 255); 196 glTexCoord2f(0, 0); 197 glVertex3f(0, 0, 0); 198 glTexCoord2f(OpenGLControl.Width div 2, 0); 199 glVertex3f(OpenGLControl.Width, 0, 0); 200 glTexCoord2f(OpenGLControl.Width div 2, OpenGLControl.Height div 2); 201 glVertex3f(OpenGLControl.Width, OpenGLControl.Height, 0); 202 glTexCoord2f(0, OpenGLControl.Height div 2); 203 glVertex3f(0, OpenGLControl.Height, 0); 204 glEnd(); 205 206 OpenGLControl.SwapBuffers; 207 end; 103 208 104 209 { TBGRABitmapPaintBox }
Note:
See TracChangeset
for help on using the changeset viewer.