Results 1 to 8 of 8

Thread: Quick image display

  1. #1
    Guest

    Quick image display

    I program a 2D game in which I need to copy many images of various sizes, going from 48x48 to 1024x768 pixels.

    Everything works fine using glDrawPixels, but it is terribly slow (typically 30 fps on a XP2000+ and GF4, worse than UT2003...). I presume it is caused by the bandwidth limitation between the GPU and the processor memory (maybe I'm wrong, but I've tried to change everything - pixel format, pixel transfers are set to default, UNPACK_ALIGNEMENT that I have set to 1 since my images are 24 or 32 bits, and so on -, and it was still too slow.

    So, what I would like is to be able to load in the video memory pictures of any size, like in Direct3D, but if I'm right it has to be powers of 2 in OpenGL...

    I suppose there must be simple solutions to this problem, but I've been through many tutorials and faqs without finding an answer (for example, NeHe always uses small textures, which is not a problem) ? Does anybody have an idea ?

    And sorry for my poor English...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Fort Collins, Colorado
    Posts
    446

    Re: Quick image display

    Unless I'm confused about what you're tring to do, perhaps glTexSubImage would help?
    http://msdn.microsoft.com/library/de...unc03_2bqc.asp

  3. #3

    Re: Quick image display

    Raster graphics are too slow indeed. Do NOT use glDrawPixels, but use textured quads. Bind the texture you need and then render the quad. It is so simple. Oh. Dont forget to enter ortho2d mode. I guess you know that though.

  4. #4
    Guest

    Re: Quick image display

    >kaysoft : indeed, glDrawPixel IS too slow, and I should use textures. But I think the regular size for textures is 64, 128 or 256, and I have pictures from completely different sizes, that is the problem...

    >yakusa : thanks for the link, but I don't understand : glTexSubImage2D is for modifying a part of an existent texture, which still has to have a special size !

    By the way, after looking closely, my textures don't look right, the transparent parts kinda 'slaver', ask for a screenshot if this isn't clear...
    After reducing my code to the bare minimum, it looks like, with a standard Ortho2D projection :

    glGenTextures(1, &texture[0]) ;
    glBindTexture(GL_TEXTURE_2D, texture[0]) ;
    glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP[18].sizeX, BMP[18].sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, BMP[18].imageData) ;
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR) ;

    ...

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex2i(0, 0);
    glTexCoord2f(1.0f, 0.0f); glVertex2i(BMP[18].sizeX, 0);
    glTexCoord2f(1.0f, 1.0f); glVertex2i(BMP[18].sizeX, BMP[18].sizeY);
    glTexCoord2f(0.0f, 1.0f); glVertex2i(0, BMP[18].sizeY);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    See anything wrong ?

  5. #5
    Guest

    Re: Quick image display

    Let's be more simple : I have for example a 600x300 pix image, what is the fastest way to display it (not using glDrawPixels I mean) ?

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    4

    Re: Quick image display

    Make texture with size of power of two but bigger than yours, in your case 1024x512, now map only the part you want to display on quad. If you think you lost too much space pack some other, smaller images to that texture in unused space.

  7. #7
    Guest

    Re: Quick image display

    You're right, I will do that, even if I don't find it very satisfactory. Direct3D can load textures from any size, but I guess it just hides the fact that it stocks them in bigger textures...

    By the way, I found the mistake in my texture loading, so don't bother : the third argument of glTexImage2D must be 4 or GL_RGBA in rgba mode...

  8. #8
    Guest

    Re: Quick image display

    And thanks for your help !

Similar Threads

  1. Quick Question ? about image display
    By herba in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-15-2012, 04:30 AM
  2. Display Image
    By tafazolisina in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-21-2009, 03:17 AM
  3. image display
    By y2kjester in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-26-2005, 08:52 PM
  4. Replies: 1
    Last Post: 01-31-2005, 11:01 AM
  5. How delete a display list quick and clean?
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-21-2003, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean