Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: I need some help with 2D drawing libraries

  1. #1

    Unhappy I need some help with 2D drawing libraries

    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 was first using delphix which works fine, but the alpha blending is ultra slow. so i tried opengl, which didnt draw the 2D images correctly, they became all blury, tried for 5 hours to get it to work and disabeld billinear interpolation and stuff but that just made the image blocky and ugly. i also tried andorra, but that turned out to work slower than delphix (?? ? ?? ?? ? ?)

    anyone have an idea of wat library i shud use? or how to get opengl to draw 2D stuff correctly? or make andorra go faster
    or delphix

    thx

  2. #2
    Quote Originally Posted by jonharkulsykkel
    or how to get opengl to draw 2D stuff correctly?
    Can I see your code? There are many reasons why you can get this... I can enumerate next:
    - textures created with mipmap
    - wrong texture coordinates
    - position of sprites are with float values

    About Andorra - maybe you used it in wrong way... or maybe Andorra's sprite engine too slow for so much sprites

  3. #3
    here its:
    Code:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      DC := GetDC(Handle);
      if not InitOpenGL then Application.Terminate;
      RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
      ActivateRenderingContext(DC, RC);
      
      //load textures
      LoadTexture('img\char.tga', tex, false);
      Timer1.Enabled := true;
    end;
    
    procedure DrawQuad(pX, pY, pZ, pWidth, pHeight:single);
    begin
      glBegin(GL_QUADS);
        glTexCoord2f(0,1); glVertex3f(pX, pY, -pZ);
        glTexCoord2f(1,1); glVertex3f(pX+pWidth, pY, -pZ);
        glTexCoord2f(1,0); glVertex3f(pX+pWidth, pY+pHeight, -pZ);
        glTexCoord2f(0,0); glVertex3f(pX, pY+pHeight, -pZ);
      glEnd;
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      DeactivateRenderingContext;
      DestroyRenderingContext(RC);
      ReleaseDC(Handle, DC);
    end;
    
    procedure TForm1.Render;
    begin
      //clear
      //glClearColor(0.6, 0.7, 1, 0);
      glClear(GL_COLOR_BUFFER_BIT);
    
    
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity();
      glViewport(0, 0, ClientWidth, ClientHeight);
      glOrtho(0, ClientWidth, ClientHeight, 0, -1, 1);
      glDisable(GL_DEPTH_TEST);
      glMatrixMode (GL_MODELVIEW);
      glLoadIdentity();
      glTranslatef (0, 0, 0);
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, tex);
    
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    
      //sdfffdsgfhhf
      DrawQuad(x, 0, 0, 320, 32);
    
      SwapBuffers(DC);
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Render;
    end;

  4. #4
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    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
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  5. #5
    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
    i tried that too even with a fdsfgfgdfgload of diffrent numbers
    didnt make any diffrence

  6. #6
    Quote Originally Posted by phibermon
    glTranslatef(0.375, 0.375, 0.0);
    I remember "problems" only with Direct3D, when I use some offset for texture coordinates, but in OpenGL there is no problems with it. Here two screenshots:


    First one without glTranslatef, another one - with it.

  7. #7
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    oh it's only if you want a texture in orthographic mode to be pixel perfect. have a look at my screenshots for JUI and look at the fonts.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  8. #8

    Lightbulb

    but both are megablurry :0
    thx for replyeis btw

  9. #9
    jonharkulsykkel
    Can you show code inside LoadTexture? Because render code seems ok. And what size of your texture? If it 320x32, maybe problem that your videocard doesn't support NPOT textures correctly.

  10. #10
    Quote Originally Posted by phibermon
    oh it's only if you want a texture in orthographic mode to be pixel perfect.
    Those screenshots made in demo, that use glOrho
    Last edited by Andru; 17-10-2010 at 07:51 PM.

Page 1 of 3 123 LastLast

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