Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26

Thread: I need some help with 2D drawing libraries

  1. #21

    Smile

    heres the code i tested with andorra
    Code:
        //cam stuff
        cx := camx div 16;
        cy := camy div 16;
        cxl := cx+blockw;
        cyl := cy+blockh;
    
        //update grass
        updGrass := updGrass+1;
        if updGrass > 60*2 then begin
          updGrass := 0;
          updateGrass(false);
        end;
    
        //draw blocks
        for y := cy to cyl do begin
          for x := cx to cxl do begin
            if not(blocks[x,y,0] = 0) then begin
              images.Items[1].Draw(dxdraw, (x*16)-camx, (y*16)-camy, blocks[x,y,0]-1);
    
              blockRect.Left := (x*16)-camx;
              blockRect.Top := (y*16)-camy;
              blockRect.Right := blockRect.Left+16;
              blockRect.Bottom := blockRect.Top+16;
              images.Items[5].DrawAlpha(dxdraw, blockRect, 0, blocks[x,y,1]);
            end;
          end;
        end;
    its a tile based game yes, and it draws first all the tiles, then bllack boxes with various alpha levels to create shadows
    i got a solution to some of my problems, i kinda cached all the blocks in an array with 15 diffrent light values instead of drawing alpha blended images over them. but i still need to alpha blend the sky, becus the dude will be walking there and i want him to be dark and also there will be water so i definatly need it
    and here screenshot of my game (this is done in delphix)

  2. #22
    so i tried opengl, which didnt draw the 2D images correctly, they became all blury
    The screenshot you posted looks good. What is the blurryness your talking about?

    I don't really know delphix well. There might be a simple option you have to set to make it alot faster. Also, you should use the latest version of UnDelphiX, not the old DelphiX by hiroyuki hori which is not hardware accellerated and therefore horribly slow.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #23
    blurriness is when i try to draw with opengl, on this screen i used latest verison of undelphix

  4. #24
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,108
    Blog Entries
    25
    Quote Originally Posted by jonharkulsykkel View Post
    its a tile based game yes, and it draws first all the tiles, then bllack boxes with various alpha levels to create shadows
    i got a solution to some of my problems, i kinda cached all the blocks in an array with 15 diffrent light values instead of drawing alpha blended images over them. but i still need to alpha blend the sky, becus the dude will be walking there and i want him to be dark and also there will be water so i definatly need it
    and here screenshot of my game (this is done in delphix)
    Thanks for providing this for us, this helps us a whole lot when knowing what kind of advice we can give. Scrolling platform game it is then.

    First thing I can say is that I know why your rendering (this term applies for 2D as well as 3D really) is so slow. It seems you are trying to alpha blend every single 16x16 square pixel of your entire screen. This is a really really slow and painful thing to do to your game. I think if you optimize this a little bit you'll be happier with the speed and performance of your game's code.

    A good tip: The less "drawing" you do for the basic stuff in your game, ie. level tiles, character display, and so on, the more stuff you can draw to enhance your game as you polish it up. Less is more in this case.

    First thing you need to do is eliminate the drawing of the biggest portion of your tiles. Usually you'd want to make your sky a single color or image (like a gradient or a long background that you can scroll gradually as you progress through the game's level) Since you have a single color for your sky I'll just assume that you can use a single color which would be faster anyways.

    So in your game loop where you perform all your graphics functions you will want to do the following:

    Code:
    // --- graphics control start ---
    
    ClearScreen; // beginning the next frame by clearing out the old
    // <-- here is where you want to use the same color as your sky so to save
    //       a lot of time just color it the sky color instead of clearing to black first.
    
    // draw your tiles, but none of your sky tiles! (NO Alpha)
    
    // Now Draw only your tiles that need alpha.
    
    // draw your hero character
    
    //draw your enemies
    
    //draw your pickups
    
    // draw the rest...
    
    // --- graphics control end ---
    by doing this alone, you've saved a whole lot of unnecessary processing that will help you later on.

    Now you mentioned something that flagged my attention. You said that you were drawing your tiles using alpha. I have to ask you aren't drawing ALL your tiles with alpha are you? Because thats not good for your game's speed either. You should try to restrict that you draw with alpha as much as you can. So I'd either separate what tiles you need to alpha blend (that actually SHOW as blended) and those you don't and only draw with alpha what you need. Just defaulting to draw everything with alpha is such a waste of processing power and keep your game running slow as ever.

    One last thing you mentioned that I am curious about, you said something about making your character look darker using alpha blending for the sky? I would recommend if you aren't using some kind of effect on your character, fog or shadow effect, to just modify your character sprite. However if you insist you need to change the character's appearance during game time, just do it to your character not the whole screen. It's so wasteful to alpha draw up near the top left corner where nothing is being effected by it where all you need is to change your character's pixels only.

    Also one last thing to keep in mind, the more pixels you manipulate per graphics function the more processing it takes and the slower your game overall. Also the more drawing functions you use, the more processing is required and the slower your game is. This also goes for effects. If you use alpha, rotate and scaling in a single draw function, it will be much slower than if you just draw without alpha, rotate or scaling.

    Try to restrict as much unnecessary drawing functions as possible and ONLY use effects if they make a difference and this will allow you MORE speed in your games. This will help a lot.

    Try this approach to your game, modify it accordingly and you should be able to achieve the same effect and get more performance out of your game. And please, let us know how it goes.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  5. #25
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,205
    Blog Entries
    2
    I'll just throw into the mix... if you need to use alpha blending, I would step away from UnDelphiX... I tried it for our competition entry way back in 2006 (IIRC). With no alpha, UnDelphiX was acceptable (note... I only said acceptable). With alpha, it practically ground to a halt.

    I wrote a proof of concept piece to test out OpenGL and alpha blending... on the same hardware it was significantly faster (UnDelphiX managed single figure frame rates, whilst OpenGL managed triple digit frame rates).
    :: AthenaOfDelphi :: My Blog :: My Software ::

  6. #26
    i have optimsized it to the max, and it doesnt alpha blend anything right now, but i will need to later :U it woud be nice if anywone cuold post a simpel opengl aplication that works without bluring the images, ive tryed everything in this thred and nothing works(

Page 3 of 3 FirstFirst 123

Tags for this Thread

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