Watch, Follow, &
Connect with Us

David Lock

Try Delphi Cannon: A simple OpenGL game integrated with VCL

Everyone knows that the programmers greatest excuse for slacking off is compile time.  Next time your waiting for your software to build burn a few minutes playing the Delphi Cannon Demo!  It’s a simple VCL/OpenGL app I wrote in a few short afternoons.

 By hosting an OpenGL canvas on top of a standard TPanel I was able to easily integrate a simple windows app with basic OpenGL rendering.  This allowed me to create the simple game you see here, and encapsulate it in the easy to design UI of VCL.  It works for more than just games too.  A OpenGL enables TPanel is great for rendering complex graphs and data processed by your Delphi application!

 So enjoy playing the demo, and think about what other things could be done with a faster rendering system attached to VCL controls.

 Note, since this demo uses OpenGL you will need compatable video card drivers.  These can be obtained by your video card manufacturer in MOST cases.  Cirtain cards may need to search for OpenGL compatable drivers, as the manufacturers drivers are not always compliant.  Also, if anyone has any questions reguarding the TPanel hosting OpenGL, or about the game itself, feel free to reply to this post.

Posted by David Lock on November 20th, 2007 under Uncategorized |



18 Responses to “Try Delphi Cannon: A simple OpenGL game integrated with VCL”

  1. chengzha Says:

    Your tank game is very interesting! Thank you for sharing.

  2. Salvador Gomez Retamoza Says:

    3 things surprise me:

    1-It is a simple but well constructed game, so my point is: very well to be a "a few short afternoons" demo.

    2-The interface is so smooth

    3-My video card support it that well! :P

    Pretty good quick-demo David.

  3. Ajasja Says:

    "‘-0.8′ is not a valid floating point value"
    Well, some of us use ‘,’ as the default decimal separator… :)

  4. Peter Soderman Says:

    Sorry won’t start on a Swedish XP.

    My guess is the decimal separator.

    It shows up with ‘-0.8′ is not a valid floating point value.

  5. David Howes Says:

    Nice retro feel. Needs some jarring 80’s midi style polyphonic music to complete it though :-)

  6. Jim McKeeth Says:

    Can you put the code up on CodeCentral?

  7. Joliphant Says:

    Nice stuff for an application thats barely larger than the smallest of delphi apps.

    Is it possible to get the source code ? And a question The underlying panel doesn’t seem to be there ? Is there an opaque layer in there ?

  8. Ilshat Absharipov Says:

    It say " ‘-0.8′ is not a valid floating point value " and doesn’t work :( Blank application window opens but new game doesn’t start.

  9. Stephane Wierzbicki Says:

    Hi,

    I wasn’t able to run the program : I’m getting an ‘-0.8 is not a valid floating point value’ (I’m running a French winxp os)

  10. m. Th. Says:

    Thanks for the ‘game’, David. A _much_ bigger ‘game’ would be if we’ll have a VCL which will leverage the OpenGL as rendering engine. (…also having GLScene around should make things easier, isn’t?). Just a small note, the game doesn’t work if the ‘National Settings’ have other setting than ‘DecimalSeparator=.’ (Point). And at the end the classical question: Source? ;-)

  11. Ahto T. Says:

    The Cannon seems to be a bit buggy, at least I can’t run it. ;)

    I get this error message on startup:

    —————————
    Dcannon
    —————————
    ‘-0.8′ is not a valid floating point value.
    —————————
    OK
    —————————

    Seems to do with regional settings and you assume everyone uses ‘.’ as decimal symbol in numbers but not say ‘,’ that is popular in Europe and elsewere. ;)

  12. Davy Landman Says:

    Hi David,

    I just wanted to check how it looked, but because my culture settings in windows xp are set to Dutch the decimal separator char is an ‘,’. Your program assumes an ‘.’ as separator char, that’s due to the fact you use ‘,’ as data separators for the vgx files. Easiest fix would be:

    var
    CurrentSeparator: Char;
    begin
    CurrentSeparator := DecimalSeparator;
    try
    DecimalSeparator := ‘.’;
    { do the importing.. }
    finally
    DecimalSeparator := CurrentSeparator;
    end;
    end;

  13. David Lock Says:

    Joliphant: The underlying OpenGL panel is created at runtime, and yes, its actually there :).

    Intl Folks: I applied Davy Landman’s fix to the vgx file loader. Hopefully this allows you to waste as much time on this as I have :D.

    m. Th.: I have definatly been thinking about that. With Microsoft coming out with things like WPF, which support very rich UI elements its making VCL’s look and feel very antiquated. Hopefully I can convince some of the folks around here that some whiz-bang is needed in our frameworks.

  14. David Lock Says:

    Rats, forget to mention, the link in the post now points to the binary with the fixed decimal separator issue.

  15. Keld Hansen Says:

    Now it starts up, but it is tilted 90° (or, rather, my monitors are, and the game doesn’t follow) :-).

    It aint easy coding properly with all the different setups your end-users have :-).

  16. Dmitry Chuev Says:

    Dear David, game is really rock ! Fun with it much larger than size of the program :)

    Is it possible to get the source code ?

  17. Dmitry Chuev Says:

    Dear David, game is really rock ! Fun with it much larger than size of the program :)

    Is it possible to get the source code ? Thank you !

  18. Ashwin Thakur Says:

    Hey David,

    Awesome game. WOuld be interested in how you did the OpenGL stuff in Delphi.

    Are you able to provide the source to see how it all works? Are we expecting a version 2.0???



Server Response from: BLOGS1