- //Initialisierung der Textur
- function TMain.InitializeTexture(const aTexture: TByte1dArray): integer;
- begin
- glGenTextures(1,@result);
- glBindTexture(GL_TEXTURE_2D,result);
- // set the texture parameters
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- 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,GL_RGB,FTextureWidth,FTextureHeight,0,GL_RGB,GL_UNSIGNED_BYTE,@atexture[0]);
- end;
- //Quad zeichnen
- procedure DrawQuad(pX, pY, pZ, pWidth, pHeight : Single);
- begin
- glBegin(GL_QUADS);
- glTexCoord2f(0,0); glVertex3f(pX-pWidth/2, pY-pHeight/2, -pZ);
- glTexCoord2f(1,0); glVertex3f(pX+pWidth/2, pY-pHeight/2, -pZ);
- glTexCoord2f(1,1); glVertex3f(pX+pWidth/2, pY+pHeight/2, -pZ);
- glTexCoord2f(0,1); glVertex3f(pX-pWidth/2, pY+pHeight/2, -pZ);
- glEnd;
- end;
- //Textur laden
- procedure TMain.LoadTexture(aGraphic:TGraphic);
- var Size : integer;
- i,k,ix,iy,iz : integer;
- tmpcounter : integer;
- aTexture:TByte1dArray;
- begin
- FTextureWidth:=aGraphic.Width;
- FTextureHeight:=aGraphic.Height;
- setlength(aTexture,aGraphic.Width*aGraphic.Height*3);
- tmpcounter := 0;
- i:=0;
- for iy := 0 to aGraphic.Height-1 do
- for ix:=0 to aGraphic.Width-1 do
- begin
- aTexture[i]:=GetRValue(aGraphic.Pixels[ix,iy]);
- inc(i);
- aTexture[i]:=GetGValue(aGraphic.Pixels[ix,iy]);
- inc(i);
- aTexture[i]:=GetBValue(aGraphic.Pixels[ix,iy]);
- inc(i);
- end;
- FTextureID:=InitializeTexture(aTexture);
- end;
- //Und meine Renderfunktion
- procedure Main.Render;
- begin
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity();
- glViewport(0,0,Fwidth,Fheight);
- glOrtho (0, Fwidth, 0, FHeight, 0, 1);
- glMatrixMode(GL_MODELVIEW);
- glBindTexture(GL_TEXTURE_2D,FTextureId);
- glBegin(GL_Quads);
- glTexCoord2f(0,0);glVertex2f(0,FTextureHeight);
- glTexCoord2f(1,0);glVertex2f(FtextureWidth,FTextureHeight);
- glTexCoord2f(1,1);glVertex2f(FTextureWidth,0);
- glTexCoord2f(0,1);glVertex2f(0,0);
- glEnd;
- SwapBuffers(FDC);
- end;