- unit textur;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs,GL, GLU, ExtCtrls, GLAUX;
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- private
- hrc : HGLRC;
- Procedure SetDCPixelFormat(Handle: HDC);
- Procedure DrawScene;
- { Private-Deklarationen}
- public
- { Public-Deklarationen}
- end;
- var
- Form1: TForm1;
- tex : gluInt;
- implementation
- PROCEDURE glGenTextures(n: GLsizei; VAR textures: GLuint); STDCALL; EXTERNAL opengl32;
- PROCEDURE glBindTexture(target: GLenum; texture: GLuint); STDCALL; EXTERNAL opengl32;
- {$R *.DFM}
- procedure InitTextures;
- var
- texture1: PTAUX_RGBImageRec;
- begin
- texture1 := auxDIBImageLoadA('./texture/wall.bmp');
- if not Assigned( texture1 ) then begin
- MessageBox(0,'Texturenpfad oder Dateiname falsch!'+#13+' Bitte den Pfad überprüfen!','Fehler beim Laden der Textur!',MB_OK or MB_ICONERROR);
- end;
- glGenTextures(1, tex);
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1^.sizeX, texture1^.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1^.data);
- end;
- // ------------------------------------------------------------
- procedure TForm1.SetDCPixelFormat(Handle: HDC);
- var
- pfd: TPixelFormatDescriptor;
- nPixelFormat : Integer;
- begin
- FillChar(pfd,SizeOf(pfd),0);
- with pfd do
- begin
- nSize := SizeOf(pfd);
- nVersion := 1;
- dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
- iPixelType := PFD_TYPE_RGBA;
- cColorBits := 24;
- cDepthBits := 32;
- iLayerType := PFD_MAIN_PLANE;
- end;
- nPixelFormat := ChoosePixelFormat(Handle,@pfd);
- SetPixelFormat(Handle, nPixelFormat,@pfd);
- end;
- // ------------------------------------------------------------
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- SetDCPixelFormat(Canvas.Handle);
- hrc := wglCreateContext(Canvas.Handle);
- InitTextures;
- end;
- // ------------------------------------------------------------
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- wglDeleteContext(hrc);
- end;
- // ------------------------------------------------------------
- procedure TForm1.DrawScene;
- begin
- glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT);
- glLoadIdentity;
- gltranslateF(0,0,-0.5);
- glBindTexture(GL_TEXTURE_2D,tex);
- glBegin(GL_QUADS);
- glTexCoord2f(0,0); glVertex3f(-0.5,-0.5,0);
- glTexCoord2f(0,1); glVertex3f(-0.5,0.5,0);
- glTexCoord2f(1,1); glVertex3f(0.5,0.5,0);
- glTexCoord2f(1,0); glVertex3f(0.5,-0.5,0);
- glEnd;
- end;
- // ------------------------------------------------------------
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- wglMakeCurrent(Canvas.Handle, hrc);
- DrawScene;
- wglMakeCurrent(0,0);
- end;
- end.