Results 1 to 6 of 6

Thread: Drawing multiple images from a single image

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    Drawing multiple images from a single image

    I have an image that contains multiple images within. What is the best approach for "cutting" up this image and drawing different parts of it? Would I use glTexCoord2f() and just setup different coordinates, or would glTexSubImage2D() work better, or something else?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Drawing multiple images from a single image

    You mean you have a texture atlas ?
    Probably glTexCoord2f is best, but I am not sure of what you want to do exactly.
    glTexSubImage2D is only useful to update a part of a texture, so I don't see how you could use that in this case ?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    Re: Drawing multiple images from a single image

    Ah that's the name. I didn't know what it was called, so searching didn't help much

    I guess I misunderstood what glTexSubImage2D is for. I'll try using glTexCoord2f. Is there any way I can use glTexCoord2f() with coordinates other than 0-1?

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Drawing multiple images from a single image

    Is there any way I can use glTexCoord2f() with coordinates other than 0-1?
    Opengl uses normalized texture coordinates because this way, texture mapping does not depend on texture image size. You can easily compute normalized texture coordinates from a coordinates in pixel knowing the texture image size.
    Note that there is one case where opengl does not require normalized texture coordinates when you use the GL_TEXTURE_RECTANGLE target but this one has many limitations (no mipmapping support, ...)

  5. #5
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Drawing multiple images from a single image

    you can use 0, 0.1 , 0.33445433, ... even 4.2 etc are valid.
    However, outside the 0-1 range, the texture repeats.
    You can also denormalise the coordinates and have integer texel coords xy like that:
    glTexCoord2f(x * 1.0/texturewidth, y * 1.0/textureheight)

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    8

    Re: Drawing multiple images from a single image

    Ok thanks. I figured I'd just use basic math.

Similar Threads

  1. Multiple objects: single or multiple shaders?
    By sam_thedancer in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 04-29-2013, 03:29 AM
  2. Replies: 3
    Last Post: 08-11-2011, 01:52 AM
  3. Multiple DC, single RC.
    By b34r in forum OpenGL: Windows
    Replies: 3
    Last Post: 11-23-2004, 11:53 PM
  4. Load multiple images on a single 3D Object question
    By waldoo in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-25-2002, 04:39 AM
  5. Multiple RCs on a single DC
    By imported_ben in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 05-12-2000, 12:17 PM

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