Page 2 of 2 FirstFirst 12
Results 11 to 20 of 26

Thread: I need some help with 2D drawing libraries

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Lightbulb

    but both are megablurry :0
    thx for replyeis btw

  2. #2
    Quote Originally Posted by phibermon View Post
    glTranslatef(0.375, 0.375, 0.0);

    That is the most important line of code for 2D opengl. disable mipmapping/filtering on textures. All coordinates as integers.

    pixel perfect 2D. perfect for fonts and sprites
    That shouldn't be the case... There was time when different graphics cards drew with a little different coordinates but i think modern cards know better to do it from 0,0.

    If you draw a quad that fills the screen the coordinates are:
    0,0-Width,Height
    Do you see why it's not Width-1, Height-1? The same reason that if you want to draw a quad that fills 1 pixel only.
    To show a pixel at 5,5 use quad coordinates 5,5 - 6,6. (Or use GL_POINTS at 5.5, 5.5)

    But if you want to draw a GL_LINE on right edge:
    (width-0.5, 0.5) - (width-0.5, height-0.5)
    Because center of pixel is 0.5, 0.5.
    A sprite for example wants to utilize the whole pixel so it starts from 0,0.

  3. #3
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    I got it from the OpenGL red-book... And I quote :

    "An optimum compromise that allows all primitives to be specified at integer positions, while still ensuring predictable rasterization, is to translate x and y by 0.375, as shown in the following code fragment. Such a translation keeps polygon and pixel image edges safely away from the centers of pixels, while moving line vertices close enough to the pixel centers."

    But if you want to add 0.5, on the CPU, to both components of every coordinate you send, to the GPU, be my guest

    I'm no longer using immediate mode, will post if I find any problems getting unfiltered, pixel aligned fonts working under GL3 Core. (I may go down the vector font route if I can't figure out an elegant way to render bitmap fonts using shaders)
    Last edited by phibermon; 18-10-2010 at 09:36 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  4. #4

    Smile fds

    but waht is this JUI thing? ;0

  5. #5
    Quote Originally Posted by jonharkulsykkel View Post
    ok so i making a game in delphi and every frame it needs to render about 1200 16x16 images, then 1200 alpha blended pics then a dude.
    I think the problem isn't the library. You have 2401 blitting each frame, that's "too much". I'm sure you can do the same drawing less pictures.
    No signature provided yet.

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Maybe if you tell us what all these images are for we may be able to help a bit better I think. I'm guessing it's a tiled engine? That may account for the "1200 16x16 images" in which case I must ask what your game's screen resolution with 16x16 sized sprites. So what are the 1200 alpha blended images?

    It almost seems like you are trying to swallow a whale without knowing how to... well... "fish" *ahem* pardon the expression. So lets start with what type of game it is and what gameplay features are you trying to put into it?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7
    I'd go down the OpenGL path if I were you.

    So, can you provide use with a screenshot of your app. We would like to see what you are trying to do and how blurry the output actually is.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  8. #8
    What function specifically are you using in andorra? (do you mean additive blending?)
    Code:
    for i := 0 to 2400 do
    begin
       gui[1].DrawAdd(AdDraw,AdRect(0,0,16,16),1,250);
    end;
    I can do the above with an average of 300 FPS. I think it may be your computer or drivers, unless you consider 300 fps too slow...

  9. #9

    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)

Page 2 of 2 FirstFirst 12

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
  •