Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Do I need a graphics engine?

  1. #1

    Do I need a graphics engine?

    For the last couple months I've slowly been working on a game, written using the latest version of Lazarus.
    It's a turn-based deep simulation/strategy game, so I don't haven't really seen the need for advanced animations or particle effects. The map is grid-based, and most information is simply displayed through different menu's.
    The contents of every tile on the grid is stored in a simple two dimensional Array that points to different Records I have defined.

    I've used Delphi to develop parts of different commercial programs at my job, but I don't really have any experience doing anything that requires graphics, so forgive me complete lack of knowledge in these matters.

    So far I've only been using the basic TImage object that comes with Lazarus. I simply print whatever graphics I need onto a TBitmap, either using things like Canvas.FillRect, or copying things from a spritemap using Canvas.CopyRect.
    Then I simply use TImage.Canvas.Draw to update the main image whenever the player opens a menu or builds on/modifies a tile.

    At the moment this works great, but I'm still worried this will come back to bite me later on during development. Especially if I want to add simple animations later on.
    Is this a horrible way of doing things?

    Is there a free graphics engine I could use that would allow me to handle my game's graphics in a more efficient manner?
    I don't really need anything advanced, since I'm just using 2d sprites, and at the moment the screen doesn't need to update except on player input.

    I have a lot more questions, since my understanding of graphics is so low, but I figured I'd start here.
    Let me know what you think.


    Also, does anyone have any good *simple* tutorials on how to do graphics in pascal(or video games in general), I'd appreciate them. At the moment everything is so new to me I just end up feeling overwhelmed.

    Thanks in advance!

  2. #2
    Do you need to use graphics engine? Not necessarily.

    Should you use graphics engine? Yes I think you should.

    Why? There are actually multiple reasons.
    1. As you are being afraid using of standard LCL (Lazarus) or VCL (Delphi) components could become a problem in the future due to them not being able to render fast enough. Especially if you are planning on adding animations into your game. So by using graphical engine you can mostly avoid these problems. That is if you use it correctly. Even the best graphical engine can be brought to a crawl if not used properly.
    2. By using of graphical engine you get access to some additional features that are not available with plain LCL or VCL. Most notable features that could come in handy for you are fast and smooth image scaling's, image rotations and fast multilayered rendering For instance you render background in one layer and then your units or buildings in another layer. Finally you combine these two layers together which can be very fast if they are both stored in video memory.
    3. Since many graphical engines support multiple platforms using of such graphical engine means that you will have much easier job of porting your game to other platforms if you chose to do so. By using of LCL or VCL you are basically limited only on Windows.
    4. Learning of working with graphical engine would help you in the long run, because I somehow doubt that this will be the only game you are going to try to make.

    Now there are some drawbacks of moving to the usage of graphics engine.
    1. Most notable drawback would be the fact that because many graphical engines does not work well in combination with LCL or VCL (could cause serious lags) you might be forced to recreate your whole UI with graphical engine instead of using LCL or VCL components.
    But since you are making a turn based game where you don't need to continuously update game screen the chances for that are small.
    2. Since rendering of images using graphical engine uses a different approach than using of LCL or VCL component is it might be a bit difficult to start as you also need to slightly adjust your thinking process regarding image rendering and scene building.

    Any way I recommend you decide quick whether you will be using graphical engine or LCL/VCL. The main reason for this is that now when your game still isn't so complex the transition to usage of graphical engine would be much easier that later on when your game would become much more complex.

    Now you are probably asking yourself: "If I chose to use a graphical engine which one should I use?"
    I myself am interested in usage of Platform eXtended Library (http://asphyre.net/products/pxl) which is a very powerful graphical library but still fairly easy to use. I have used it predecessor (http://asphyre.net/products/legacy/9-asphyresphinx3) in the past and I must say that I have been very satisfied with it.
    And thing that would probably make you most happy is that it is free to use even in a commercial product (it is distributed under Mozilla Public License (MPL) version 2 license).

  3. #3
    Thanks for the great reply. This helps a lot!
    My weekend got really busy, so I wasn't really able to do anything programming related until yesterday evening.

    What you said makes a lot of sense, so I'm definitely going to try and learn how to do this.
    As you said, graphics is something I'm going to have to learn sooner or later, so I might as well try and learn it now.

    What you said about being able to render the background separately sounds really good. I've already experimented with making a animated non-interactive background to the main game screen(basically just a view of space, with stars passing by in the background), but couldn't figure out any way to do it efficiently, using only lazarus.


    I downloaded PXL yesterday. It took me way too long time to get it to work(turned out I had a old version of Lazarus), but as far as I can tell, it looks really good.
    Is there any guide to how I can get started using the library? Or any general guide to graphics programming, that might help me? The documentation of the specific parts is pretty good, but it still all assumes I actually know what I'm doing!
    From just looking at it, I can understand(or at least guess) how most parts of it works, and I could probably get by just copying code from the examples, but I don't like writing code that I don't understand. Plus it seems like it could very well become inefficient in the long run.
    I'm a little worried since you said most graphics engines could grind to a halt if I don't know what I'm doing...

    Any further help would be appreciated!

  4. #4
    Quote Originally Posted by ajol View Post
    I downloaded PXL yesterday. It took me way too long time to get it to work(turned out I had a old version of Lazarus), but as far as I can tell, it looks really good.
    I must say that I'm a bit surprised by hearing that. I guess that large difference between older stable version of FPC/Lazarus and newest might be the cause for this. Besides since FPC/Lazarus is completely free PXL author is probably expecting that everyone is using latest version which could not be said for Delphi developers since they have to be paying yearly subscription in order to keeping their development environment up to date.

    Quote Originally Posted by ajol View Post
    Is there any guide to how I can get started using the library? Or any general guide to graphics programming, that might help me? The documentation of the specific parts is pretty good, but it still all assumes I actually know what I'm doing!
    I'm afraid there is no specific guide on starting out with PXL. I think there was a guide for one of its predecessors so you might want to do some searching through http://www.pascalgamedevelopment.com...erly-PowerDraw) part of our form which contains lots of information for working with PXL predecessors. Also check the forums at PXL official site.
    But checking and studying the demos might also be enough. It was for me but I must admit that I had at least some basic knowledge on working with graphics before from short time usage of few other graphical engines before their development was canceled. For some reason I mostly started using of these graphical engines just before they got canceled so I never even got learn to use them properly as I did with Asphyre Sphinx 2 and later Asphyre Sphinx 3.
    Any way I recommend you start fiddling with demos and if you run in to some questions ask them here on PGD and we will try to help.

    As for general guides about working with graphics. I'm afraid I can't give you any suggestion on them because I myself never read any of them.
    I learned most about how graphics in games are done by close observation from a lots of games that I have played in my life. This also included of extracting and checking of game resources like textures, animations, etc. You won't believe of how much you can learn only by checking of these.
    I also learned a lot about working on graphics by communicating with other game developers many of which are not even here on PGD nor they use Object Pascal for creation of their games.

    Quote Originally Posted by ajol View Post
    I'm a little worried since you said most graphics engines could grind to a halt if I don't know what I'm doing...
    I didn't mean to scare you but merely say that there is no graphical which would be so much better than the others because it does not allow you to screw up.
    Any way if you do happen to screw things so badly to bring the graphical engine to a halt do post your problems here and we will solve them together.
    And yes many times you can learn most by screwing up first That is how I learned most about computers.
    Back in the days I used to purposely delete or rename various windows files to see what would stop working
    And I even fried few computer components but this was not on purpose

    Any way we are here to lend you a hand when you will need it. I myself didn't had this luxury or didn't know where to get help when I started fiddling with graphics myself. So I had to learn it the hard way.

  5. #5
    Let's SPAM a bit.

    I'm working on the next release of Allegro.pas, the wrapper that allows to use the Allegro game library with Free Pascal, and soon Delphi too. I want to release it before TINS 2016, so I can use it.

    Allegro isn't a "graphic engine". It is much like SDL (graphics, controls, mouse, sound...) but different. I didn't use SDL a lot, but Allegro looks more "low level", and I like that. Also, you can use it along with OpenGL or Direct3D, but since 5.2 you can do 3D just using Allegro (much like branch 4).

    End of spam.
    No signature provided yet.

  6. #6
    Quote Originally Posted by Ñuño Martínez View Post
    Let's SPAM a bit.
    ...
    End of spam.
    Haha, yeah I might check out Allegro later.

    Quote Originally Posted by SilverWarior View Post
    I must say that I'm a bit surprised by hearing that. I guess that large difference between older stable version of FPC/Lazarus and newest might be the cause for this. Besides since FPC/Lazarus is completely free PXL author is probably expecting that everyone is using latest version which could not be said for Delphi developers since they have to be paying yearly subscription in order to keeping their development environment up to date.
    Yeah, I guess the PXL site is a little confusing. It claims you need at least Lazarus 1.4 and FreePascal 3.0. I had Lazarus 1.4.4, so I figured I'd be fine, but I guess Lazarus 1.6 is the only version that uses FreePascal 3.0, so you pretty much have to use that one

    Quote Originally Posted by SilverWarior View Post
    But checking and studying the demos might also be enough. It was for me but I must admit that I had at least some basic knowledge on working with graphics before from short time usage of few other graphical engines before their development was canceled. For some reason I mostly started using of these graphical engines just before they got canceled so I never even got learn to use them properly as I did with Asphyre Sphinx 2 and later Asphyre Sphinx 3.
    Any way I recommend you start fiddling with demos and if you run in to some questions ask them here on PGD and we will try to help.
    So I've spent some time looking at the samples, and trying to replicate some parts of them. It took me some time to get anything to work, since the FreePascal samples apperently were written using "delphi syntax mode"(in the project options). This meant that even when I copied code directly from a sample it still wouldn't work until I switched that.
    I'm sure that if I knew proper FreePascal syntax I probably could have written things differently, and made them work anyways. But that's pretty hard when I have no idea how things are supposed to look.
    It's extra confusing since several samples are old and have been ported several times between different versions of the engine.


    So far I've only been looking at the timer that came with the library(TMultimediaTimer). I've been looking for a new timer for some time, since the Lazarus TTimer has felt kinda unstable to me.
    I got it working, but I'm not sure if I'm really using it right.
    Maybe I've misunderstood something, but from what I see from the samples, all it seems to do is trigger constatly on the Application.OnIdle event.
    This means that as soon as the program does something different, the timer stops counting.
    Is there a way to avoid this? I'd rather not have all graphics stop updating just because the game has to run a heavy calculation.
    If not, is there a better timer out there that I could use? Or is this just how timers work in general? Should I just make sure I make my code so effective it doesn't noticably interrupt the timer?


    Quote Originally Posted by SilverWarior View Post
    I didn't mean to scare you but merely say that there is no graphical which would be so much better than the others because it does not allow you to screw up.
    Any way if you do happen to screw things so badly to bring the graphical engine to a halt do post your problems here and we will solve them together.
    And yes many times you can learn most by screwing up first That is how I learned most about computers.
    Back in the days I used to purposely delete or rename various windows files to see what would stop working
    And I even fried few computer components but this was not on purpose

    Any way we are here to lend you a hand when you will need it. I myself didn't had this luxury or didn't know where to get help when I started fiddling with graphics myself. So I had to learn it the hard way.
    haha, yeah I understand!

    I really do appreciate the help you're giving. I really respect people who went through the process of learning things completely on their own! Although I'm not sure I'd ever have the time(or dedication) to figure all this out myself!

  7. #7
    Ñuño Martinez that is not spamming. All you did was present an alternative.

    I might have done his myself if I would have more experience with it but I just tried it once some time ago.

    Any way Allegro game library is quite powerful. And I know this by the fact that I keep tracking the development of a very good game made with it. The game in question is of course Factorio.

    And since we are already talking about alternatives we might as well mention the Castle game engine which I'm afraid I also haven't tested out yet.

  8. #8
    Quote Originally Posted by ajol View Post
    Yeah, I guess the PXL site is a little confusing. It claims you need at least Lazarus 1.4 and FreePascal 3.0. I had Lazarus 1.4.4, so I figured I'd be fine, but I guess Lazarus 1.6 is the only version that uses FreePascal 3.0, so you pretty much have to use that one
    It is not the PPXL sithe what is confusing you but the sheer lack of proper knowledge about what FreePascal and Lazarus are. You See FreePascal and Lazarus are actually two separate projects (programs) where:
    - FreePascal is actually a combination of Compiler, Debugger and Linker
    - Lazarus is just a development IDE which makes use of FreePascal much easier and also allows some other features similar to the ones found in Delphi like visual UI design using LCL component suite.

    Quote Originally Posted by ajol View Post
    It took me some time to get anything to work, since the FreePascal samples apperently were written using "delphi syntax mode"(in the project options). This meant that even when I copied code directly from a sample it still wouldn't work until I switched that.
    I believe author of PXL decided to go that way in order to make maintaing support for both FreePascal and Delphi much easier as they can share same codebase.

    Quote Originally Posted by ajol View Post
    It's extra confusing since several samples are old and have been ported several times between different versions of the engine.
    I haven't checked the PXL yet but I assume some of these samples might be still left from its predecessors (Asphyre Sphinx).

    Quote Originally Posted by ajol View Post
    So far I've only been looking at the timer that came with the library(TMultimediaTimer). I've been looking for a new timer for some time, since the Lazarus TTimer has felt kinda unstable to me.
    I got it working, but I'm not sure if I'm really using it right.
    The TMultimediaTimer is a lot different than the regular TTimer that ships with Lazarus or Delphi for that matter. If you look at it in object inspector you will notice that it has two events. One is OnProcess and one OnTimer.
    OnProcess event should contain all in-game logic code like character movmements, simulation processing etc.
    While OnTimer event is actually used only for rendering.
    You can control when each of these events is fired by using Speed and MaxFPS properties. Where Speed property defines how often is game simulation being updated and MaxFPS defines what is desired screen refresh rate.
    Now the TMultimediaTimer also contains special mechanism which is able to detect if your rendering call had take too much time so that game simulation should already been updated before rendering was done. In that case OnProcess event will be fired twice in a row to allow your simulation to catch up the lost time.
    I strongly recommend reading the official documentation as I don't remember seeing any proper example of fully using these features.

    Quote Originally Posted by ajol View Post
    Maybe I've misunderstood something, but from what I see from the samples, all it seems to do is trigger constatly on the Application.OnIdle event.
    As I mentioned above that is not the case. Unlike regular TTimer the TMultimediaTimer is much more complex. And the reason why it is using Application.OnIdle event is to gain maximum possible resolution without interfering with standard application messaging system.

    Quote Originally Posted by ajol View Post
    I'd rather not have all graphics stop updating just because the game has to run a heavy calculation.
    There are only two way of doing this.
    One is avoiding any lengthy heavy calculation or at least having ability to split that lengthy calculation into multiple steps.
    Second one is implementing multithreading support where you can move such calculation to secondary thread/s. I haven't tried implementing multithreading in combination with TMultimediaTimer but I'm sure it can be done to some degree (no true asynchronous processing of graphics and game simulation). But if you really do need something like you can find Multithreaded Timer on the web.

    Quote Originally Posted by ajol View Post
    Should I just make sure I make my code so effective it doesn't noticably interrupt the timer?
    As a game developer you will have to learn on how to make an efficient code. While in business applications it is perfectly acceptable for some lengthy processing to take up to 5 seconds or even more if you show a nice looking progress bar
    in game development any such lengthy processing is already considered as serious game lag. That is in case of turn based games while in case of real-time paced games this is already considered as game hang.
    So yes in a way game development is much harder than business development. But don't let that discourage you. Instead take it as a personal challenge as it will make you a better programmer in the end. At least that is my opinion.

    Quote Originally Posted by ajol View Post
    I really respect people who went through the process of learning things completely on their own! Although I'm not sure I'd ever have the time(or dedication) to figure all this out myself!
    You just have to believe in yourself. You would be surprised of how much you can achieve.
    And BTW I'm only 6 years older than you. So we both have still lots of time for learning even thou sometimes learning speed can be a bit slow due to not having much free time to be used for programming.
    I'm sticking with this for 15 years already (last 7 years more or less focusing on learning about game development) even thou sometimes it seems I'm not making any progress.

    Just remember that there will be days where you would be as we programmers like to call it "in the zone" when you will do a lot of progress. And there would be days where you would just spend whole day banging your head around a single problem without any success.
    You see programming is not like any other work it is more like art. During good days you will make huge progress and during bad days you won't. You just have to accept that and live with it. And most importantly don't quit even when it seems that there are no good days coming.

  9. #9
    Quote Originally Posted by SilverWarior View Post
    It is not the PPXL sithe what is confusing you but the sheer lack of proper knowledge about what FreePascal and Lazarus are. You See FreePascal and Lazarus are actually two separate projects (programs) where:
    - FreePascal is actually a combination of Compiler, Debugger and Linker
    - Lazarus is just a development IDE which makes use of FreePascal much easier and also allows some other features similar to the ones found in Delphi like visual UI design using LCL component suite.
    Oh I understand the difference between Lazarus and FreePascal, I think haha.
    From my understanding Lazarus uses FreePascal, and Lazarus version 1.4.4(which I was using before) was built using FreePascal 2.6.4.
    Lazarus 1.6, which is the latest version, is the first one to use FreePascal 3.0.
    Therefore I found it kinda confusing that the PXL site says they support Lazarus 1.4+.

    But it's no big deal. The only important thing is that everything has been working perfectly fine ever since I switched to Lazarus 1.6.

    Quote Originally Posted by SilverWarior View Post
    I believe author of PXL decided to go that way in order to make maintaing support for both FreePascal and Delphi much easier as they can share same codebase.
    Yeah, that makes a lot of sense.


    Quote Originally Posted by SilverWarior View Post
    As I mentioned above that is not the case. Unlike regular TTimer the TMultimediaTimer is much more complex. And the reason why it is using Application.OnIdle event is to gain maximum possible resolution without interfering with standard application messaging system.
    Ok, thanks. I've spent more time looking at the timer, and I think I understand how it works now.

    Quote Originally Posted by SilverWarior View Post
    There are only two way of doing this.
    One is avoiding any lengthy heavy calculation or at least having ability to split that lengthy calculation into multiple steps.
    Second one is implementing multithreading support where you can move such calculation to secondary thread/s. I haven't tried implementing multithreading in combination with TMultimediaTimer but I'm sure it can be done to some degree (no true asynchronous processing of graphics and game simulation). But if you really do need something like you can find Multithreaded Timer on the web.
    Quote Originally Posted by SilverWarior View Post
    As a game developer you will have to learn on how to make an efficient code.
    Yeah, I understand. I'm trying to limit the amount of advanced stuff I have to learn at once, so I'm hoping I won't have to learn multithreading too.
    It shouldn't be a problem simply using the TMultimediaTimer. I just have to become a lot better at actually writing efficient code.

    Yeah I noticed even small bits of lag in the graphics make a huge difference! That's actually what made me decide to look into using a graphics engine in the first place.
    I tried to add an animated background, which I simply updated using a TTimer, but I noticed it was a bit inconsistent in it's updating. Probably because the code that created and updated the background only relied on my limited knowledge of basic LCL stuff.
    Still, it ran smoothly enough, until I started adding more and more user interactivity. Right now my OnClick code is so inefficient that every time the player clicks somewhere, the background stops updating for 0.1 seconds.
    It's really not much, but it's still very noticeable, and it's definitely something I can't have in the finished version of my game!
    Once I've figured out how to use PXL correctly, I'll have to spend more time learning how to handle user input a lot better.


    Quote Originally Posted by SilverWarior View Post
    You just have to believe in yourself. You would be surprised of how much you can achieve.
    And BTW I'm only 6 years older than you. So we both have still lots of time for learning even thou sometimes learning speed can be a bit slow due to not having much free time to be used for programming.
    I'm sticking with this for 15 years already (last 7 years more or less focusing on learning about game development) even thou sometimes it seems I'm not making any progress.

    Just remember that there will be days where you would be as we programmers like to call it "in the zone" when you will do a lot of progress. And there would be days where you would just spend whole day banging your head around a single problem without any success.
    You see programming is not like any other work it is more like art. During good days you will make huge progress and during bad days you won't. You just have to accept that and live with it. And most importantly don't quit even when it seems that there are no good days coming.
    Thanks for the feedback! Like I've said, I really appreciate the help

    ---

    All in all, I feel like I'm progressing well. There's still a lot of stuff I don't understand, but it still makes enough sense that I haven't had much problems learning it, so far.

    My only problem right now is I can't find a good way to use sprites.
    In my old code, the main game screen is split into a grid, where all squares are 24*24 pixels. And I have the pictures of everything that could appear on the screen, saved in a single large image.
    Then, depending on what was supposed to be in a certain square, I simply used CopyRect to copy the appropriate(24*24) parts from a single large image I created.

    However, I can't seem to find any way to copy a part of an image using PXL. There's a lot of different functions for deciding what(whole) image to use, and a lot of parameters to decide how to copy it, but I can't seem to find a way to simply use a small part of a large image.
    Have I missed something, or do I have to save the graphics for every single thing in the game as a separate image?

    ---

    Also, do you happen to know any open source games created using PXL, or one of it's similar predecessors? The samples that came with the library are pretty good, but they're all very simple, and none of them feature any sort of user interactivity.
    I think I could learn a lot from simply seeing how someone else has used the graphics engine to create a playable game.

  10. #10
    Quote Originally Posted by ajol View Post
    My only problem right now is I can't find a good way to use sprites.
    In my old code, the main game screen is split into a grid, where all squares are 24*24 pixels. And I have the pictures of everything that could appear on the screen, saved in a single large image.
    Then, depending on what was supposed to be in a certain square, I simply used CopyRect to copy the appropriate(24*24) parts from a single large image I created.

    However, I can't seem to find any way to copy a part of an image using PXL. There's a lot of different functions for deciding what(whole) image to use, and a lot of parameters to decide how to copy it, but I can't seem to find a way to simply use a small part of a large image.
    Have I missed something, or do I have to save the graphics for every single thing in the game as a separate image?
    So you were creating and using Atlas Image manually by yourself when using LCL. You don't need to do this in PXL.
    That is al already being handled by TAtlasImages class. So when you are rendering certain image you can only specify its name and all the rest is being done by PXL.

    And while it is still possible to copy part of the image (at least it was possible in PXL predecessors) I would not recommend you doing that because by doing so you will just end up by moving lots of data from Video Memory to System Memory and then back to Video Memory. And as you can guess this can affect the performance a lot.
    You se in PXL all textures are stored in Video Memory directly so graphics card can render them much quicker. And while in PXL predecessors all textures were loaded in one big Image Atlas PXL allows you to load and unload multiple Image Atlases. This can then be even used for dynamic asset loading and unloading.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL