From: Michael H. <mh...@us...> - 2000-12-03 22:57:24
|
Update of /cvsroot/pythianproject/Prototypes/GLCanvas In directory slayer.i.sourceforge.net:/tmp/cvs-serv22979 Modified Files: Arial Grid.bmp CourierNew Grid.bmp EngMain.pas MyDraw.pas QuadTextUnit.pas glCanvas.pas Added Files: 20x20grid.bmp Data.txt glcanvas.htm scene.png Removed Files: RPG.png gadgetcollage.bmp Log Message: final update --- NEW FILE --- BM6 ÿ --- NEW FILE --- GLCanvas Demo v1.0 ¯¯¯¯¯¯¯¯¯¯ Use the up and down arrow keys to scroll this text box. The GLCanvas allows you to easily program OpenGL for bitmaps and text using very fast algorithms. Bitmap drawing breaks the picture into multiple textures for speed, and bitmapped text uses textured quads (this is an example of that) The GLCanvas is also very easy to use. You can use commands like DrawText(), DrawBitmap() and SetClipping() to simplify coding. The Canvas is object oriented too, and it makes use of display lists to speed up execution of code. The GLCanvas was made for the Pythian Project, an open source effort to create a 3D realtime role playing game set in a fantasy world of our creation. It's a big project and your help is needed. So mosy on over to: http://www.pythianproject.org and check us out. Any Delphi developers are welcomed and as this demo shows, you don't have to be an expert at OpenGL programming! Credits ¯¯¯ Michael Hearn (mh...@su...) Darryl Long (d_...@sy...) Kamil Krauspe --- NEW FILE --- <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><meta name="GENERATOR" content="Microsoft FrontPage 4.0"><meta name="ProgId" content="FrontPage.Editor.Document"> <title>GLCanvas Documentation</title> </head> <body> <div align="Left"> <h4>GLCanvas v1.0 Documentation</h4> <hr align="Left" width="100%" size="2"><a href="mailto:mh...@su...">Michael Hearn</a><br> <a href="mailto:d_...@sy...">Darryl Long</a><br> <a href="mailto:kr...@gm...">Kamil Krauspe</a><br> <br> <hr align="Left" width="100%" size="2"><br> This file describes the GLCanvas objects suite and how to use it to make drawing 2D graphics onto an OpenGL canvas much easier than it would otherwise be. The algorithms used in the canvas have been designed for speed and ease of use, not necessarily simplicity. This is why some operations with it may seem a strange way of doing things. Anyway, let's go.<br> <br> <u>What it can do</u><br> <ul> <li>Images (fast)</li> <li>Bitmapped text (fast)</li> <li>Vector text (via the GLF lib)</li> <li>PNG image support</li> <li>Clipping</li> <li>Rectangle drawing<br> </li> </ul> All this is done using simple commands like Rectangle(), DrawBitmap() and DrawText().<br> <br> <u>Drawing Images</u><br> <br> Images in OpenGL are not directly supported unless you use the glDrawPixels() command which directly copies pixel data from system memory to the pixel buffer. This would be ideal but unfortunately this is a <b>very</b>slow operation, and I mean slow. Drawing a 640x480 image in this way on my machine takes almost half a second :(<br> Nevertheless, the Canvas supports this method for when performance is not the be all and end all for your app.<br> <br> However, there is a better, although significantly more complex way of doing things that results in much better framerates (ie. about 120fps on my machine for a 640x480 image :) This system breaks the image you want to draw into multiple textures and then uses polygons to display them. Because these images are hardware accellerated things move along much better. Why multiple textures? Well, most hardware cards have a limit of 256x256 pixels for textures due to the internals of their engines. So the canvas breaks an image into multiple textures when the image is loaded.<br> <br> So how do you use this then? Well, all bitmaps in the GLCanvas are represented by objects, in this case the TGLBitmap class is used. To use a bitmap it must be loaded into one of these objects, which can then be passed to the DrawBitmap() method of the GLCanvas. Here's an example:<br> <br> <code>GLC: TGLCanvas;</code><br> <code>Picture :TGLBitmap;</code><br> <br> <code>begin</code><br> <code> GLC := TGLCanvas.Create;</code><br> <code> </code><br> <code> Picture := TGLBitmap.Create;</code><br> <code> Picture.LoadFromFile("logo.png");</code><br> <br> <code> GLC.DrawBitmap(50,50,Picture);</code><br> <code>end;</code><br> <br> This example would display "logo.png"at location 50,50 from the top left of the window. As you can see, there is nothing to it. However, we can do more than this! The GLBitmap class supports transparency using a transparent colour: if we set the transparent colour to black then any black pixels in the picture will be see-through, meaning you can draw non-rectangular bitmaps. This is done by setting the <code>UseTransparency</code>property to true and setting the TransparentColor property to the colour you want (it defaults to black). Because the GLCanvas is based partly on the FastDIB library you must specify the colour as RGB data, not a Delphi colour constant. Although in some places you can use constants like clBlack or clAqua in this instance that's not allowed. You create a colour for this property using the FRGB function:<br> <br> <code>Picture := TGLBitmap.Create;<br> Picture.UseTransparency := true;<br> Picture.TransparentColor := FRGB(0,0,255); // blue is our transparent colour<br> Picture.LoadFromFile("logo.png");</code><br> <br> Notice that you <i>must</i>set the transparency properties before loading the file. If you want you can use direct drawing by using a different constructor:<br> <br> <code>Picture := TGLBitmap.Create(GLCANVAS_BMP_DIRECT);</code><br> <br> However, this isn't really supported very well - for instance transparency doesn't work with this method. Also, it's slow so it's best to avoid this.<br> <br> <u>Drawing Text</u><br> <br> Again, OpenGL has no direct support for drawing text. There are many, many different ways of drawing text (for more information on this subject check out NeHe's excellent <a href="http://nehe.gamedev.net/opengl/">tutorial pages</a>) and the Canvas offers you two which should combine the best of both worlds - bitmapped text which looks nice at small sizes, and vector text which can be resized to any area needed without losing resolution. Vector fonts are drawn using the <a href="http://romka.demonews.com">GLF library</a>written by Romka, who is a seriously cool guy. You can get more fonts from his website.<br> <br> Bitmapped fonts are drawn using my own system that uses a 256x256 bitmap with letters arranged in a grid formation. Textured polygons are drawn that use this and this means <i>fast fast fast!</i><br> <br> This also means that fonts are very easy to make, although it does take some time. You can use the included "20x20grid.bmp" file to help you create new fonts. To use the text facility you can use the TGLText object. The reason that text is represented by objects too is for performance reasons, when you use an object something called pre-caching becomes available which stores the commands for drawing the text in the hardware accellerator itself, meaning - yep, you've guessed it, faster execution! Of course, if this isn't important to you it's possible to use the DrawString() command for simplicity but it's really designed to use an object. Here's a simple example of it:<br> <br> <code>var<br> Text1 :TGLText;<br> GLC :TGLCanvas;<br> <br> begin<br> Text1 := TGLText.Create("Arial");<br> Text1.SetColor(clYellow);<br> Text1.Text := "Hello World";<br> <br> GLC.DrawText(30,30,Text1);<br> end;</code><br> <br> As you can see, this is quite easy, but you can do more :) Text objects can have multiple lines (accessed through the Lines property), and of course this can be used to load text files. The demo program shows this in action. This uses textured quads to draw bitmapped text. To use the GLF vector based text:<br> <br> <code>var Text2: TGLText;<br> <br> begin<br> Text2 := TGLText.Create("Hello World","Arial",GLCANVAS_TEXT_GLF,GLC_DEFAULT_FONT_DATA);<br> // here we have used the other overloaded constructor to select GLF text. you can ignore<br> // the last parameter, it selects a font data array, the default one will do for now.<br> Text2.Size := 20;<br> GLC.DrawText(30,30,Text2);<br> end;</code><br> <br> How you add new fonts depends on the system you use. If you're drawing vector text you can simply download more GLF fonts from Romkas website but I'm not sure how you can make your own. Then you add the entry for it to the GLC_DEFAULT_FONT_DATA array as shown below. For bitmap text it's more complex (i'm afraid the canvas only comes with Arial and Courier New) but everything can be done using Paint Shop Pro or a similar program.<br> <br> To create a new bitmapped font:<br> <ol> <li>Create a new 256x256 bitmap with a black background</li> <li>Paste the "20x20 Grid.bmp" file over the top. This will show you where to place characters. If you want you can place the grid over the fonts that come with the canvas to see how it's done.</li> <li>For each character place the letter (in white) in each square aligned to the left of each grid square.</li> <li>Once this is done for every character (well, every character that is in the font set, you can see them in the other font grids) save it and change the GLCanvas.pas file in the following way:</li> <li>Add a new entry to the GLC_DEFAULT_FONT_DATA array. The fields are fairly self-explanatory, just make sure you set FontType to be GLCANVAS_TEXT_QUADTEXT.</li> <li>You also need to add a widths array to the QuadTextUnit.pas file. This array specifies the width of each character and is how the system support variable width fonts. See the code for examples of how to do this.</li> <li>Finally, you need to add an entry to the MatchFontWidths method of the TGLText class. This just returns the array given a font name.</li> <li>That's it! I know it's long winded, some time I may automate it but for now that's the way to do it. If you want to add some sort of exotic character not already in the font set add it to the array and set the rest of the widths in the other arrays to 0.</li> </ol> <br> <u>Drawing shapes</u><br> <br> You can draw rectangles using the Rectangle() method. This takes 4 coordinates, X1, X2, Y1 and Y2. It draws a rectangle based on the:<br> <br> <i>CurrentColor</i><br> <i>Solid</i><br> and <i>FillAlpha</i><br> <br> properties. If solid is true then the rectangle will be filled with the colour and at the opacity specified with FillAlpha. If solid is false then the outline is all that is drawn.<br> <br> <hr align="Left" width="100%" size="2"><br> Phew! Hopefully that clears up how to use the object. I hope you like it!<br> <br> This object was designed and built for the <a href="http://www.pythianproject.org/">Pythian Project</a><br> </div> </body> </html> --- NEW FILE --- PNG É0ØÚ¶n[Ùu` *¾v²í ôÅË7eQ5RmÖµ(fUµ~|Ü@>p×r¾èH ÔÃ@-dÐù¢ì'«ñhö£ïÄO#-ò$Ó,f`ÑÄJúÕCp¦3· P4M2 £-Ïàö´R,Î$F2»Ü«IØ,È $þÑt Òö %¬íú®kâͧNRßs8¯/> 6ÆàeQrJ ·v&R17¡Bôþ¼ú(æ;êp·¤*LLaÅGí<åW.ît|°(SKüüdêó2Ä!V&1ûô7&Ü xøì¯±ì¿éX)5¸Wë>13Õ³DÚ7õçñ]¦R ÑS%|È <:*7c¿N¦£]3XFÐlés8À'§n·µ-ÿüG+»§0£1̼'VÒ|XtWüªÏÌÀÎá~¿áXéèI/C,QBE²37ì K7§ÓñTTUIMpò¸õùísØõãjµ®¹)"!¾AáBa.¹eØ$EPÒO.¹¨¹ÿuâdç´Fð¦<¶}3^qPÚ¥Vù¼<dÆèÁîàyÈýíö7#X³ÕéÚ(g½ø=G¬eÁHb=¬oÞ¶9°åBÛ&d;÷ à?Y§2y2A^Á\Ñ0¸õ¨õÎápüù·¦&öO½z](âv `ÆÑøûoî?¬v»óåH¬Ql,¢ÍG ¦ÆRZuÌd=Ø_ L ¬yÃõç4z(O2^ÔCÅ"ÐoúN9$êÊÀX&ɨv(§Ï3ïa)N<ÚAOIþë~ úiOû#en§½ëðÄRÊðÎ!J`ÌÞßßg<¯5þ9Ã9Lúáqmç8tÿ-" q4&VÕè=EÎÁB·%¸ÝbIæWë5VÕjEÓI=à²Óð@BtFFKiTtqÜ|GR2Ç#Ï`g½Ü;óÄd×U/Z³¡IÕAs:\pklJÙ3óö¿ºÄ!>÷NÐyNìÿûÑÚÎöV¸Þf;ô<&ß°J=¯l¡Ò&¹ì$ÎGùéjÙòZµÎRZc2âùãFÞÏéÉÐïV¥Å#ßnEGóttбN«æÑüQPcR p²Û®6·¬ëc4Ø ""!¥uÇ·~ù%Ügö?Vý§ÓÄAíýõÉÕÉ ¹¾¿ò[ýÙÇÞx?Úпp¬HVÈ/ötáÈòhu:ÙnGÖ×au0 !öí$9SÒ¨Fí°YLe(vf³°3Eq£:#m´T²ÙÎæúòòæß¾4³N»FýíÿOkÞµºnZ%¥aàExÔ(YoybM\¹/oó18!A^ROjñZ»ÖIaZòþ/Ñ^Ë»q¦eK"c<ª¼Ì¯3ûQ9í Ñûî:mø®üé 3ÑàBÁ»ÝÞ¼*onn...àòÍ7Íãåååv»5¶µ¯Sý½¨*bVÒÖª+äùÜtcçpÚpîßçÄÛßi¢.ËYU¶m+ÍJ°mÝ«h·1Õ7åªæ¶+ÑGØê2µ#(kÜÀ"̳º«9°t2"èàÌ!ó²h%ÙlëíÖåPÈAIÝUn¤´EÙW#^éëØ³W/{$®ã£×zwÓÓ1è :0¹ ð§× L÷$.ÍnIükó|²x:ö(>9jJ'ÒÓÌi(gü¸dĤHC;¨þaqºé0B¼oê?h.cºº!<(ûN5½ÈQ$ñmÛív{qqiÇ®·&Ó°^¯·¸¬gÀäWú¾0 ð_º`¿ó þü窪ÒD¾¾~ýz>¯`¼X^ÿôîÉm[C¢ù¬¸¾¾¾¹¹YRÀdt§kUÛÕ[Õph)pr¦\Üá1rÂ-ÿf+1r&DÁ`Kíº»ñqhRðj.$©Ì4¡éÍ# µ`!Ò=X5³>±!^z.µ:ê% ñí$à)É3¥:O¿'°tîLå9ó£*VëZ ®ñÆÍ¶ ÷ÂÈ~ò)iha½ ¶¯·.Ö1.ÆÂäPòã"u» #÷dÊ6ö¸!Uæ5 'ªSÈóKNÉ¿üó?%®_ëíFï¬*,¬'%B/î´Í¨Âm± ñãããÏ?¿ ã|1{qscͲ`:0@z½^¯6; ƲZcʨ·.úÙSæ=ì¥y7$ܯѦ«çUy}¹¸}yµúp§d] þó·@o_}cÖ`¼SúÍoqç; ãζ%dyòÂ{{ÇBg^PE§üõøy6Å®`ú%ÛçKÝf[ò|W¤ðÑOÕñè%|r?ÝcÃ8Ò/Ù|ñï©öbØP¡]µñW±þÝ tÍÂbú?þóa=|¨îÞÎnr±Þà´ g73gi>//Q¢ò¸(ç˺én·ír9 h?B©d:bÌF (ï øöøªý¦7fGtwiåÀ}ãrÍá´Mnúøäí&1ðr]]½øððêæáýï¾ýïííË?¾¾Y.÷÷÷ål~÷°úëÿüiÛ ©DW»ÝnµÙt];ÇN 3Ã'l®_×ÖúùÆ9<Ç0)R~f!Çï¢×ãÒnÆ×îöq½ÝåϳÂ|Q iþª~"hß¶$ýV+Þ` WjÀR°®TKw«w·¸Þl~¹½¹®w._Þ@æ0B/¯¯U¹üþïÞþôËfÛ¼¿û [...1016 lines suppressed...] ÝÐ2ÕèEo;ô9i.Z_~d²!ðyéÇQùÕÃ_Û{Ñä·OBqzÆ÷`Æþ¼Ú(Ø|¿ú ì}W«VÉÙûï*þ&ìòµºË¾GXíHg'b3ÂÖÉ1bôïµÔ#hãàOÌs?bÚj1ËO;jÜ%_½'\ Z( áý{$qU³fÁ7H"áBÚ4mNV)_ãlìÖÆÁ-U0ÈêÜ_üPuùççg,ÊþðÜXöSòÇóï¿|ù´Ù,£°ô5,1I/>ùOezqÕC5u¶¾P4®Ý°èkîKê½5\eSd¨·Ê=W ½6¨°ã¯ÏO[ sþ"[~<̬kàùëtgêJ=ÀÁÈÅxtñß}§5Î@ÞIgØ5O ¼ ÓLC&Ë@µ´ô¸ÿÙ¢%~#Æ&¾¾¾îAé"Z&<0Ì(bdé;]@ØÒaËQÇQ ;¸&«4¸>XTe*_4_1e#M߯jC bPúbN¸Í/Øßȧf+ fªÔut'½øã±FÁÛÄÒ7#xIÖG÷ú]ì{&ZYIr¾*P¤K;) j°7£%/bB/ªýÕlÉ»a}¬}É\R ½ »^@Þë}!9~µ^j}£ä¤Ë÷½ë¦q6!'% _ÄuÔ±óB+dT0 çaóÛ50аYÂÅê]xÁ½§<5¹¶8V°RPЬóWg#dÔUpb*Ñ´ÿoþ<«ùÔ(6©Æx èC¥æOþúå3ªÐ/óü#oZýöäó§²1C7íPÑG ¿Eq üº -YLTÓq: R(A¯i9ºÆQú¨ôµf'/2ã¼Öú*óiïyøÑq¼ìQ.9ÝBôÁrX »f¾©þuóßæêÖêê DXÅ}²*úpL7ÐEXû¢Gµ=NBF¥´Çü¢$-ÿÂõð ½Ô|QAà~8®ñ Ä©ø]êüéÀ#n|9ÙQÒθ^"hcxFôÙ'c:ð¹Ô¨îÓÅÔ`Ní:¿7 «"×S!n×gã<áS©K4¶ iî$röí{_d*GE¡ÇNÆ¡áQGù)wxÐáSë®»÷ÕèßìBÅ[?8I°¨h- ç»qçþµî¨.5ÕØoS;7á&çÛSÿ~ dS<8K1¨·7I§¢ÔEºwrwbø¾xm°å ËvænÂ.¦[Rýù=?Þ!×7âº6®N Ã3A:ßY¶1Ð ùus<&¬Z²îS=iÇSàòdZ);jïLZm.8qçm}!*Õ°ãÍ"<Õ)\,,Þ5ÂAr@fÀê&'wÈSGܺÚÿþéò¥~üñG_Y¨XÃÍPRâIJ[6ØjM("k®Òrå67#Z}&írÍ`D©?*9ó+Ì0s~|oàC %°¡lðuFâ¥D .!+¥S2 ÛÁQjáT¡+¡ !BÇÃSA ˨D[¬Î*SQºzIèQ4üêû3úQ·çü`üYòͱÑ%ö¥@Q^Ü2Ößã'\9ɰWGÉK6G5&ï-{9X¥ ¼ëI^B¤Æñûgà8D¢eÌBkHAÂ÷©¯Ã]½»bUÙªÓuÑ¡z Cïë¦÷0ÉL6hÔ]¼¥!& À/òRdäð âz× ®¶<Ü ¤Ïâ":Ü.ì»{ñ;Ì÷1úpA~þÕ×÷ÞûZ°$5Þi Wy°èß3Àüì÷ÂôÁ#ñ»x×ÈúÉ|è3©sIÉ¡§E«7È<O4ÕK%Mü·ú;t ¶=Ëô§O¾_ÕOr÷±ÄébOÒ§È«×h¢ YSç???ó±Ù0«µ±okqRuâxÁYg*³Ã OÛyµBG×ÊKBÎmcrz'Êø&<Æ£Ëið(À¼yµ(´¾¸ÝµI Ë«=KÖ¿ÈafrBÖ7±z|Uz=÷¯Áò{¼QN.V[ îZ´êïå*BC±¡GJeÅÛ}EÒ»j6µ|Q?ÿÍõ1U¯ >³âêÉ(üTAUR]øàl´y?-ðíÝU婯$z×·pï!Eüê»7{ÿª%Ö7ì#ÎAgõî7úï#Ýî8ãö®þó½õºóä%EµØl->à$ôÍóÛõì» õ*U¤8¿/¥ xÏüøÜs¾ ¡hø½%°ùÔù¯üãWc }YéRvÈ¿aýöòòõé)ßÉÍmm>®íÂ9Ø¥ a£ÓM¤W³2P¬ùdd6'.¾"?¬ÅÁo Ï6L±Å¨$ÐðÂõU¸Áðû°|ð%A¡óÎU0és DéV0 T¹1|Rî:dùgth/®y°W´jygÿCÀÔð³]ZQCº½W¡[£¿$|Ûµ~§÷¦T!ÖA jL`Mùmß¾}ÁÅÅ8#¨s&dÇ/%¬w q©$ÏoNÄKúöí|{§®æÝiã]í\¾â·:.ðöîîÞ>u¾^ÎooÙ+H5ÓVTa½ÛK%W¹=ÙßlU.%èmôòZÉ@Ð ¢ÚDY 9Ç"ïÏT¦ð)ãõ-t[ã¾×G^bZ¦Ùïï)MS )Í?ç#`ë#OUPQ2zÍq>õêDlVDÏ<AzÍqÒá`=×jà 7Ç2ÂÙßÝÝ6Ïo'Òâ µNÂÇ¢ó55%±nzªpMï *âÖédÔYeB0Ç~qREýÍK+f·êoMø9égMWçzpçi´pÛ±9©©VÕ°×[JY>z<óêæá£1.DÎë9Btø¢7v}ÞDx'kUòÒ@E&sIBý ***** Bogus filespec: Arial ***** Bogus filespec: CourierNew Index: EngMain.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/EngMain.pas,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** EngMain.pas 2000/11/04 22:07:47 1.1 --- EngMain.pas 2000/12/03 22:57:21 1.2 *************** *** 48,78 **** procedure CheckKeys; - - function Min(Val1,Val2: Single): Single; - begin - if (Val1 < Val2) then - Result := Val1 - else - Result := Val2; - end; - - const - BaseTurn = 10; - BaseStep = 0.1; - var - VA: TAngle3D; - Step,Turn: Single; begin - // This returns a vector pointing in the direction of the Camera - VA := Camera.AngleVector; - - // This code regulates the speed of movement such that the - // movement speed is independent of the frame rate - if TimeDiff > 0 then - Step := BaseStep * TimeDiff * 0.1 - else - Step := BaseStep; - Step := Min(Step,BaseStep*2); - Turn := BaseTurn * Step; if GetKeyState(vk_Escape) < 0 then --- 48,52 ---- *************** *** 81,100 **** end; - // These are the movements is each direction if GetKeyState(vk_Up) < 0 then // Up begin ! Camera.Move(+VA.X*Step,0,+VA.Z*Step); end; if GetKeyState(vk_Down) < 0 then // Down - begin - Camera.Move(-VA.X*Step,0,-VA.Z*Step); - end; - if GetKeyState(vk_Left) < 0 then // Left - begin - Camera.Rotate(0,-Turn,0); - end; - if GetKeyState(vk_Right) < 0 then // Right begin ! Camera.Rotate(0,+Turn,0); end; end; --- 55,67 ---- end; if GetKeyState(vk_Up) < 0 then // Up begin ! TextScroll := TextScroll - TextMovement; ! if TextScroll < 0 then TextScroll := 0; end; if GetKeyState(vk_Down) < 0 then // Down begin ! TextScroll := TextScroll + TextMovement; ! if TextScroll < 0 then TextScroll := 0; end; end; Index: MyDraw.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/MyDraw.pas,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** MyDraw.pas 2000/12/01 18:31:22 1.7 --- MyDraw.pas 2000/12/03 22:57:21 1.8 *************** *** 29,37 **** GLRC: hGLRC; GLC :TGLCanvas; ! InspectorGadget :TGLBitmap; ! SampleText :TGLText; ! QuadTextSample :TGLText; ! Text2 :TGLText; // You need to implement these three procedures procedure MyInit; --- 29,39 ---- GLRC: hGLRC; GLC :TGLCanvas; ! Scene :TGLBitmap; ! WelcomeText :TGLtext; ! VectorText :TGLText; + TextScroll :integer; + TextMovement:integer; + // You need to implement these three procedures procedure MyInit; *************** *** 48,95 **** // creates a canvas object with the width and height of the window; 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; ! ! Sampletext.Lines.Add('Long live the Project'); ! SampleText.Lines.Add('These are lines of text drawn by the GLCanvas in GLF mode'); ! ! QuadTextSample := TGLText.Create('This is a sample of QuadText drawing.','Arial',GLCANVAS_TEXT_QUADTEXT,GLC_DEFAULT_FONT_DATA); ! QuadTextSample.Lines.Add('Compare to the GLF drawing and see which is better at small sizes.'); ! QuadTextSample.SetColor(clGreen); ! ! {SampleText.Lines.Add('----------------------------'); ! SampleText.Lines.Add('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); ! SampleText.Lines.Add('1234567890'); ! SampleText.Lines.Add('-----------------------------'); ! SampleText.Lines.Add('You know, the problem with GLF is that'); ! SampleText.Lines.Add('it doesn''t display small text sizes very well'); ! SampleText.Lines.Add('Also, I have this really wierd bug - if text is'); ! SampleText.Lines.Add('drawn below 11 pixels a total lockup happens'); ! SampleText.Lines.Add('on my machine. Wierd or what?'); ! SampleText.Lines.Add('============================='); ! SampleText.Lines.Add('askldfjkasdjgkljgklfjakgljdfklgjkldfjgkldsfjgksd'); ! SampleText.Lines.Add('akdsjfkadsjfkdjg h,gmhgfopowt ajkdf asdjghrtjlkf;d'); ! SampleText.Lines.Add('i just want lots of text dwtasdgfdhfdhadfhfdafhfdh'); ! SampleText.Lines.Add('ajjjjjjfdkajskdfjdkjalksertujireooeiaudklfakjgdkas'); ! SampleText.Lines.Add('kfldqpptioreptQUITRJAKSjkdlsakjdbtathylayklt=-29'); ! SampleText.Lines.Add('askldfjkasdjgkljgklfjakgljdfklgjkldfjgkldsfjgksd'); ! SampleText.Lines.Add('akdsjfkadsjfkdjg h,gmhgfopowt ajkdf asdjghrtjlkf;d'); ! SampleText.Lines.Add('i just want lots of text dwtasdgfdhfdhadfhfdafhfdh'); ! SampleText.Lines.Add('ajjjjjjfdkajskdfjdkjalksertujireooeiaudklfakjgdkas'); ! SampleText.Lines.Add('kfldqpptioreptQUITRJAKSjkdlsakjdbtathylayklt=-29'); ! SampleText.Lines.Add('askldfjkasdjgkljgklfjakgljdfklgjkldfjgkldsfjgksd'); ! SampleText.Lines.Add('akdsjfkadsjfkdjg h,gmhgfopowt ajkdf asdjghrtjlkf;d'); ! SampleText.Lines.Add('i just want lots of text dwtasdgfdhfdhadfhfdafhfdh'); ! SampleText.Lines.Add('ajjjjjjfdkajskdfjdkjalksertujireooeiaudklfakjgdkas'); ! SampleText.Lines.Add('kfldqpptioreptQUITRJAKSjkdlsakjdbtathylayklt=-29');} ! ! SampleText.SetColor(clYellow); ! SampleText.Size := 10.0; ! Text2 := TGLText.Create('Test2','Arial',GLCANVAS_TEXT_QUADTEXT,GLC_DEFAULT_FONT_DATA); end; --- 50,67 ---- // creates a canvas object with the width and height of the window; GLC := TGLCanvas.Create(Width,Height); ! Scene := TGLBitmap.Create(GLCANVAS_BMP_TEXTURED); ! Scene.UseTransparency := true; ! Scene.LoadFromBitmap('Scene.png'); ! ! WelcomeText := TGLText.Create('','Arial',GLCANVAS_TEXT_QUADTEXT,GLC_DEFAULT_FONT_DATA); ! WelcomeText.Precache := true; ! WelcomeText.Lines.LoadFromFile('data.txt'); ! ! VectorText := TGLText.Create('GLCanvas Demo','Arial',GLCANVAS_TEXT_GLF,GLC_DEFAULT_FONT_DATA); ! VectorText.SetColor(clBlack); ! VectorText.Size := 30; ! TextScroll := 0; ! TextMovement := 2; end; *************** *** 97,104 **** begin // Free all your objects here ! InspectorGadget.Free; ! SampleText.Free; ! QuadTextSample.Free; ! Text2.Free; GLC.Free; end; --- 69,73 ---- begin // Free all your objects here ! Scene.Free; GLC.Free; end; *************** *** 124,144 **** // this draws the GL bitmap object at these coordinates ! // draw the RPG system part of the bmp ! //GLC.DrawBitmapEx(20,80,256,44,55,272,InspectorGadget); ! GLC.DrawBitmap(100,250,InspectorGadget); ! 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; --- 93,114 ---- // this draws the GL bitmap object at these coordinates ! // draw the pretty scene here ! GLC.DrawBitmap(0,26,Scene); // this draws a rectangle ! GLC.CurrentColor := clBlue; ! GLC.FillAlpha := 0.3; // we want 30% opacity ! GLC.Solid := true; // we want it solid ! GLC.Rectangle(350,240,620,460); // now draw it here! ! // now draw its border ! GLC.Solid := false; ! GLC.Rectangle(350,240,620,460); ! ! GLC.SetClipping(350,240,620,455); // set the clipping rect to the blue box ! GLC.DrawText(355,245-TextScroll,WelcomeText); ! GLC.CancelClipping; ! ! // now draw the logo text ! GLC.DrawText(200,70,VectorText); end; Index: QuadTextUnit.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/QuadTextUnit.pas,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** QuadTextUnit.pas 2000/11/26 20:30:04 1.2 --- QuadTextUnit.pas 2000/12/03 22:57:21 1.3 *************** *** 15,19 **** const ! NUMCHARS = 69; type --- 15,19 ---- const ! NUMCHARS = 85; type *************** *** 27,31 **** 'k','l','m','n','o','p','q','r','s','t','u','v', 'w','x','y','z','1','2','3','4','5','6','7','8', ! '9','0','!','"','?','.','''','(',')'); COURIERNEW_WIDTHS :TQuadTextWidthsArray = ( --- 27,33 ---- 'k','l','m','n','o','p','q','r','s','t','u','v', 'w','x','y','z','1','2','3','4','5','6','7','8', ! '9','0','!','"','?','.','''','(',')',',','£','$', ! '&','=','+','-','<','>',':',';','/','\','#','@', ! '¯'); COURIERNEW_WIDTHS :TQuadTextWidthsArray = ( *************** *** 35,39 **** 8, 3, 12, 8, 8, 8, 8, 5, 8, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ! 8, 8, 4, 6, 7, 2, 2, 3, 3); ARIAL_WIDTHS :TQuadTextWidthsArray = ( 9, 10, 10, 10, 10, 9, 10, 10, 2, 9, 10, 9, --- 37,43 ---- 8, 3, 12, 8, 8, 8, 8, 5, 8, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ! 8, 8, 4, 6, 7, 2, 2, 3, 3, 3, 6, 6, ! 6, 8, 7, 7, 8, 8, 2, 3, 6, 6, 8, 7, ! 20); ARIAL_WIDTHS :TQuadTextWidthsArray = ( 9, 10, 10, 10, 10, 9, 10, 10, 2, 9, 10, 9, *************** *** 42,46 **** 8, 2, 12, 8, 8, 8, 8, 5, 8, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ! 12, 8, 4, 6, 7, 2, 2, 3, 3); type TQuadText = record --- 46,52 ---- 8, 2, 12, 8, 8, 8, 8, 5, 8, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ! 12, 8, 4, 6, 7, 2, 2, 3, 3, 2, 13, 14, ! 12, 5, 7, 2, 8, 8, 2, 2, 4, 4, 12, 15, ! 15); type TQuadText = record Index: glCanvas.pas =================================================================== RCS file: /cvsroot/pythianproject/Prototypes/GLCanvas/glCanvas.pas,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** glCanvas.pas 2000/12/01 18:31:22 1.7 --- glCanvas.pas 2000/12/03 22:57:21 1.8 *************** *** 155,159 **** property TexData :TTexBMPData read FTexData; ! constructor Create(aType:integer); destructor Destroy; override ; function BitmapToPixData(B :TFastDIB):pointer; --- 155,160 ---- property TexData :TTexBMPData read FTexData; ! constructor Create(aType:integer); overload ; ! constructor Create; overload; destructor Destroy; override ; function BitmapToPixData(B :TFastDIB):pointer; *************** *** 197,200 **** --- 198,202 ---- function MatchFontWidths(f:TGLCanvasFontData):TQuadTextWidthsArray; + procedure LinesOnChange(Sender:TObject); public *************** *** 219,223 **** property DisplayList :integer read FDisplayList; ! constructor Create(aText, aFontName:string; aPreferredTextType:integer; FontData:TArrayOfGLCanvasFontData); destructor Destroy; override ; procedure Draw; virtual ; --- 221,226 ---- property DisplayList :integer read FDisplayList; ! constructor Create(aText, aFontName:string; aPreferredTextType:integer; FontData:TArrayOfGLCanvasFontData); overload; ! constructor Create(aFontName:string); overload; // auto creates with no text, and quadtext selected destructor Destroy; override ; procedure Draw; virtual ; *************** *** 256,259 **** --- 259,265 ---- procedure DrawBitmap(X,Y:integer; bmp:TGLBitmap); virtual ; + // other + procedure SetClipping(Left,Top,Right,Bottom:integer); + procedure CancelClipping; // text routines here *************** *** 263,267 **** // shape routines here - will standardise on the american spelling of colo(u)r - procedure Rectangle(Left, Top, Right, Bottom:integer); virtual ; end; --- 269,272 ---- *************** *** 377,387 **** function TGLBitmap.LoadFromBitmap(B: TBitmap): integer; - type - TBArray = array[Word] of byte; - PBarray = ^TBArray; var tmpdib:TFastDIB; ! x,y:integer; ! scanline :PBarray; begin // load into a TFastDIB --- 382,388 ---- function TGLBitmap.LoadFromBitmap(B: TBitmap): integer; var tmpdib:TFastDIB; ! y:integer; begin // load into a TFastDIB *************** *** 397,400 **** --- 398,407 ---- LoadFromBitmap(tmpDib); tmpDib.Free; + Result := 0; + end; + + constructor TGLBitmap.Create; + begin + Create(GLCANVAS_BMP_TEXTURED); end; *************** *** 551,554 **** --- 558,572 ---- end; + procedure TGLCanvas.CancelClipping; + begin + glDisable(GL_SCISSOR_TEST); + end; + + procedure TGLCanvas.SetClipping(Left, Top, Right, Bottom: integer); + begin + glEnable(GL_SCISSOR_TEST); + glScissor(Left,Height-Bottom,Right-Left,Bottom-Top); + end; + { TGLText } *************** *** 561,564 **** --- 579,583 ---- FLines.Text := aText; FDisplayList := -1; + Lines.OnChange := LinesOnChange; TextType := aPreferredTextType; FFontName := aFontName; *************** *** 571,574 **** --- 590,598 ---- end; + constructor TGLText.Create(aFontName: string); + begin + Create('',aFontName,GLCANVAS_TEXT_QUADTEXT,GLC_DEFAULT_FONT_DATA); + end; + destructor TGLText.Destroy; begin *************** *** 622,625 **** --- 646,654 ---- end; + procedure TGLText.LinesOnChange(Sender: TObject); + begin + if Precache then UpdateDisplayList; + end; + procedure TGLText.LoadFont; var f:TGLCanvasFontData; *************** *** 745,749 **** x,y:integer; r:TRect; - id:Cardinal; t:TTexture; ac:TByteColor; --- 774,777 ---- *************** *** 753,758 **** buffer := nil; - t := nil; - Result.cellsWidth := cellsX; Result.cellsHeight := cellsY; --- 781,784 ---- --- RPG.png DELETED --- --- gadgetcollage.bmp DELETED --- |