From: Michael H. <mh...@us...> - 2000-12-01 18:31:25
|
Update of /cvsroot/pythianproject/Prototypes/GLCanvas In directory slayer.i.sourceforge.net:/tmp/cvs-serv6993 Modified Files: GLCanvasDemo.cfg GLCanvasDemo.dof MyDraw.pas glCanvas.pas Log Message: updated to have shapes code, thanks to kamil for that, also uses rearranged TTexture objects now instead of doing things directly -mike Index: GLCanvasDemo.cfg =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/GLCanvasDemo.cfg,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** GLCanvasDemo.cfg 2000/11/26 20:30:04 1.2 --- GLCanvasDemo.cfg 2000/12/01 18:31:22 1.3 *************** *** 32,37 **** -$M16384,1048576 -K$00400000 ! -U"..\..\PythianProject\Source\Units\;..\..\PNG\" ! -O"..\..\PythianProject\Source\Units\;..\..\PNG\" ! -I"..\..\PythianProject\Source\Units\;..\..\PNG\" ! -R"..\..\PythianProject\Source\Units\;..\..\PNG\" --- 32,37 ---- -$M16384,1048576 -K$00400000 ! -U"..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\" ! -O"..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\" ! -I"..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\" ! -R"..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\" Index: GLCanvasDemo.dof =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/GLCanvasDemo.dof,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** GLCanvasDemo.dof 2000/11/26 20:30:04 1.2 --- GLCanvasDemo.dof 2000/12/01 18:31:22 1.3 *************** *** 46,50 **** PackageDLLOutputDir= PackageDCPOutputDir= ! SearchPath=..\..\PythianProject\Source\Units\;..\..\PNG\ Packages=VCL40;VCLX40;VCLDB40;VCLDBX40;VCLSMP40;QRPT40;TEEUI40;TEEDB40;TEE40;ibevnt40;nmfast40;Python_d4;PythonVCL_d4;NtfyIcon;glPanelPkg;INDY40 Conditionals= --- 46,50 ---- PackageDLLOutputDir= PackageDCPOutputDir= ! SearchPath=..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\ Packages=VCL40;VCLX40;VCLDB40;VCLDBX40;VCLSMP40;QRPT40;TEEUI40;TEEDB40;TEE40;ibevnt40;nmfast40;Python_d4;PythonVCL_d4;NtfyIcon;glPanelPkg;INDY40 Conditionals= *************** *** 84,87 **** --- 84,88 ---- [Excluded Packages] + E:\cvsroot\PythianRoot\PNG\PNGPackage.bpl=PNG Image reader $(DELPHI)\Components\Indy\dclIndy40.bpl=Internet Direct "Indy" for D4 Property and Component Editors *************** *** 91,95 **** [HistoryLists\hlSearchPath] ! Count=2 ! Item0=..\..\PythianProject\Source\Units\;..\..\PNG\ ! Item1=..\..\PythianProject\Source\Units\ --- 92,97 ---- [HistoryLists\hlSearchPath] ! Count=3 ! Item0=..\..\PythianProject\Source\Units\;..\..\PythianProject\Source\PNG\ ! Item1=..\..\PythianProject\Source\Units\;..\..\PNG\ ! Item2=..\..\PythianProject\Source\Units\ Index: MyDraw.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/MyDraw.pas,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** MyDraw.pas 2000/11/26 20:30:04 1.6 --- MyDraw.pas 2000/12/01 18:31:22 1.7 *************** *** 32,35 **** --- 32,36 ---- SampleText :TGLText; QuadTextSample :TGLText; + Text2 :TGLText; // You need to implement these three procedures *************** *** 48,52 **** --- 49,55 ---- GLC := TGLCanvas.Create(Width,Height); InspectorGadget := TGLBitmap.Create(GLCANVAS_BMP_TEXTURED); + InspectorGadget.UseTransparency := true; InspectorGadget.LoadFromBitmap('rpg.png'); + SampleText := TGLText.Create('Hello World', 'Arial', GLCANVAS_TEXT_GLF, GLC_DEFAULT_FONT_DATA); SampleText.Precache := true; *************** *** 87,90 **** --- 90,95 ---- SampleText.SetColor(clYellow); SampleText.Size := 10.0; + + Text2 := TGLText.Create('Test2','Arial',GLCANVAS_TEXT_QUADTEXT,GLC_DEFAULT_FONT_DATA); end; *************** *** 95,98 **** --- 100,104 ---- SampleText.Free; QuadTextSample.Free; + Text2.Free; GLC.Free; end; *************** *** 113,116 **** --- 119,125 ---- glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT); + // now we switch off depth testing, this is to ensure that + // things are drawn in order + glDisable(GL_DEPTH_TEST); // this draws the GL bitmap object at these coordinates *************** *** 120,129 **** GLC.DrawBitmap(20,80,InspectorGadget); // this draws the text objects GLC.DrawText(25,400,QuadTextSample); ! GLC.DrawText(25,100,SampleText); // this draws a rectangle ! //GLC.Rectangle(20,300,100,400); end; --- 129,144 ---- GLC.DrawBitmap(20,80,InspectorGadget); + GLC.DrawText(100,100,Text2); // this draws the text objects GLC.DrawText(25,400,QuadTextSample); ! GLC.DrawText(25,100,SampleText); // this draws a rectangle ! GLC.CurrentRed := 1; ! GLC.CurrentBlue := 1; ! GLC.CurrentGreen := 1; ! GLC.FillAlpha := 0.5; ! GLC.Solid := true; ! GLC.Rectangle(300,40,400,100); end; Index: glCanvas.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/glCanvas.pas,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** glCanvas.pas 2000/11/26 20:30:04 1.6 --- glCanvas.pas 2000/12/01 18:31:22 1.7 *************** *** 57,65 **** by this operation so if you use scissor rects independantly we need to fix this. } interface uses OpenGL, Windows, SysUtils, Graphics, glfD, Classes, QuadTextUnit, ! Textures, FastDIB, FastFiles, PNGImage; const --- 57,73 ---- by this operation so if you use scissor rects independantly we need to fix this. + + * WARNING: This may be just my dodgy drivers, but in windowed + mode 0,0 does not appear to be the top left of the screen + because of the borders. In fact, if you specify anything + less that 25 for the Y coord of a rectangle my machine locks + up, where 22 is the height of a titlebar. I have no idea why + this should be so, probably a bug in Microsofts code, but + you have been warned. } interface uses OpenGL, Windows, SysUtils, Graphics, glfD, Classes, QuadTextUnit, ! Textures, FastDIB, FastFiles, PNGImage, Points; const *************** *** 77,81 **** TTexBMPData = record DisplayList :integer; ! TexIDs :array[1..GLC_MAXTEXIDS] of Cardinal; cellsWidth, cellsHeight :integer; Width,Height:integer; --- 85,90 ---- TTexBMPData = record DisplayList :integer; ! //TexIDs :array[1..GLC_MAXTEXIDS] of Cardinal; ! Textures :array[1..GLC_MAXTEXIDS] of TTexture; cellsWidth, cellsHeight :integer; Width,Height:integer; *************** *** 148,152 **** constructor Create(aType:integer); destructor Destroy; override ; - // @@todo - alpha transparency support function BitmapToPixData(B :TFastDIB):pointer; function LoadFromBitmap(B:TFastDIB):integer; overload; --- 157,160 ---- *************** *** 225,228 **** --- 233,237 ---- procedure SetColor(const Value: TColor); public + Solid :boolean; property Width:integer read FWidth; property Height:integer read FHeight; *************** *** 255,264 **** // shape routines here - will standardise on the american spelling of colo(u)r ! procedure Rectangle(Top,Left,Bottom,Right:integer); virtual ; end; function MakeTexturesFromBmp(var aBMP:TFastDIB; useTransparency:boolean; transparentColor:TFColor):TTexBMPData; // returns display list procedure DeleteTexBMP(bmp:TTexBMPData); - procedure GenTexFromBMP(BMP:TFastDIB; tx:integer; useTransparency:boolean; transparentColor:TFColor); // ox = origin x (ie draws part of the bitmap) // oy = origin y --- 264,272 ---- // shape routines here - will standardise on the american spelling of colo(u)r ! procedure Rectangle(Left, Top, Right, Bottom:integer); virtual ; end; function MakeTexturesFromBmp(var aBMP:TFastDIB; useTransparency:boolean; transparentColor:TFColor):TTexBMPData; // returns display list procedure DeleteTexBMP(bmp:TTexBMPData); // ox = origin x (ie draws part of the bitmap) // oy = origin y *************** *** 490,496 **** end; ! procedure TGLCanvas.Rectangle(Top, Left, Bottom, Right: integer); begin ! glColor4f(FFillR,FFillG,FFillB,FFillAlpha); glMatrixMode(GL_MODELVIEW); glLoadIdentity; --- 498,504 ---- end; ! procedure TGLCanvas.Rectangle(Left, Top, Right, Bottom: integer); begin ! (* glColor4f(FFillR,FFillG,FFillB,FFillAlpha); glMatrixMode(GL_MODELVIEW); glLoadIdentity; *************** *** 507,510 **** --- 515,539 ---- glVertex2i(Right,Bottom); glVertex2i(Right,Top); + glEnd; *) + + glDisable(GL_TEXTURE_2D); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(FFillR, FFillG, FFillB, FFillAlpha); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity; + + glScalef(2.0 / Width, 2.0 / Height, 1.0); + glTranslatef(-(Width/2),(Height/2),0); + //glScalef(1.0,-1.0,1.0); + + if Solid then + glBegin(GL_TRIANGLE_FAN) + else + glBegin(GL_LINE_LOOP); + + glVertex2i(Left, -Top); + glVertex2i(Left, -Bottom); + glVertex2i(Right, -Bottom); + glVertex2i(Right, -Top); glEnd; end; *************** *** 539,542 **** --- 568,572 ---- if Precache then UpdateDisplayList; + SetColor(clWhite); end; *************** *** 716,719 **** --- 746,751 ---- r:TRect; id:Cardinal; + t:TTexture; + ac:TByteColor; begin cellsX := (aBMP.Width div 256) + 1; *************** *** 721,724 **** --- 753,757 ---- buffer := nil; + t := nil; Result.cellsWidth := cellsX; *************** *** 727,731 **** result.Height := aBMP.Height; for x := 1 to GLC_MAXTEXIDS do ! result.TexIDs[x] := 0; for y := 1 to cellsY do begin --- 760,764 ---- result.Height := aBMP.Height; for x := 1 to GLC_MAXTEXIDS do ! result.Textures[x] := nil; for y := 1 to cellsY do begin *************** *** 752,759 **** // todo // so go generate the texture from the fast DIB ! glGenTextures(1,@id); ! Result.TexIDS[x+((y-1)*result.cellsWidth)] := id; ! GenTexFromBMP(buffer,id,useTransparency,transparentColor); ! end; end; --- 785,796 ---- // todo // so go generate the texture from the fast DIB ! t := TTexture.Create; ! ac[0] := transparentColor.r; ! ac[1] := transparentColor.g; ! ac[2] := transparentColor.b; ! t.Alphacolor := ac; ! t.UseAlpha := useTransparency; ! t.LoadFromBitmap(buffer); ! Result.Textures[x+((y-1)*result.cellsWidth)] := t; end; end; *************** *** 839,843 **** begin for a := 1 to bmp.cellsWidth*bmp.cellsHeight do ! glDeleteTextures(1,@bmp.TexIDs[a]); end; --- 876,880 ---- begin for a := 1 to bmp.cellsWidth*bmp.cellsHeight do ! bmp.Textures[a].Free; end; *************** *** 848,852 **** tr,vr:TRect; begin ! glEnable(GL_BLEND); // @@todo - alpha blending of bmps // change texture co-ordinate system glMatrixMode(GL_TEXTURE); --- 885,891 ---- tr,vr:TRect; begin ! glEnable(GL_TEXTURE_2d); ! glEnable(GL_BLEND); ! glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // change texture co-ordinate system glMatrixMode(GL_TEXTURE); *************** *** 864,868 **** for x := 1 to cw do begin ! glBindTexture(GL_TEXTURE_2D,bmp.TexIDs[x+((y-1)*bmp.cellsWidth)]); // how many pixels to subtract (ie end of grid) --- 903,907 ---- for x := 1 to cw do begin ! glBindTexture(GL_TEXTURE_2D,bmp.Textures[x+((y-1)*bmp.cellsWidth)].TexID); // how many pixels to subtract (ie end of grid) |