Results 1 to 3 of 3

Thread: OpenGL core and 2d graphics (sprites)

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    3

    OpenGL core and 2d graphics (sprites)

    What is the best way to render sprites with 3.2? (for GUI and the likes)

    I am currently storing multiple sprites in a single texture.

    This is how I used to do it:
    -load list of sprites (x,y,w,h,texid) from txt file.
    -draw_sprite(sprite* spr, x,y)...
    --pushmatrix
    --translate(x,y)
    --render quad with coords/texture coords according to spr.
    --popmatrix

    This is how I am thinking of doing it:
    -load one texture holding sprite graphics
    -load one texture holding sprite info (x,y,w,h)
    -send uniform with sprite info index
    -send uniform with sprite pos
    -render a vbo containing one quad corners (0,0) and (1,1)...
    --vertex shader scales and translates points and calcs uv's
    --fragment shader looks up sprite texture

    I presume that a more clever solution might exist, so pointers a most welcome

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: OpenGL core and 2d graphics (sprites)

    Well, IMHO using a texture to hold sprite info is a bit overkill.

    instead what you could do is to upload an array of all the possible sprites into the VBO.
    Then just update the position and render the vertics in question.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2009
    Posts
    3

    Re: OpenGL core and 2d graphics (sprites)

    hmm yeah ok, I guess that is more simple.. like

    void myDrawSpriteFunction(unsigned int id,float x, float y)
    {
    setup shaders and bind vbos etc..
    setup a uniform matrix for x and y translation
    // wasn't there a way to store and recall this information in one function call?

    glDrawArrays(GL_QUADS, id*4, 4 );
    }

Similar Threads

  1. How can I find or create a list of 3.3-core core only functions?
    By DragonautX in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-24-2017, 05:04 PM
  2. GL 4 Core Function Loading in Core 3.1+ Confusion
    By master_of_the_gl in forum OpenGL: Drivers
    Replies: 12
    Last Post: 01-04-2016, 07:48 AM
  3. Replies: 3
    Last Post: 06-24-2012, 08:01 AM
  4. core profile/core forward-compatible/compatibility
    By yjh1982 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-11-2010, 05:55 AM
  5. another core graphics question -- textures
    By in forum OpenGL: macOS
    Replies: 6
    Last Post: 10-03-2006, 07:26 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