Results 1 to 4 of 4

Thread: Sprite Sheets

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    Conneaut, Ohio USA
    Posts
    13

    Sprite Sheets

    I don't get how you could use one image of a bunch of different sprites with a black background, and use that one image of all the sprites to incorporate each sprite into a game individually. How does that work?
    -Krak

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Sprite Sheets

    You load you image with your sprites into openGL as a texture.

    Then with texture mapping, you can tell openGL what part of an texture(image) to map to a quads surface.

    Look at nehe.gamedev.net on textured mapped font's, this should give you an idea on the loading and also his example of creating sprite type objects.


    Originally posted by Krak:
    I don't get how you could use one image of a bunch of different sprites with a black background, and use that one image of all the sprites to incorporate each sprite into a game individually. How does that work?

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    Conneaut, Ohio USA
    Posts
    13

    Re: Sprite Sheets

    Originally posted by nexusone:
    You load you image with your sprites into openGL as a texture.

    Then with texture mapping, you can tell openGL what part of an texture(image) to map to a quads surface.
    Any particular functions you'd use to do this?
    -Krak

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Sprite Sheets

    Originally posted by Krak:
    Any particular functions you'd use to do this?


    There is a good number of functions used in setting up an texture and then mapping it out. You will be best served to do as I suggested and go to the nehe.gamedev.net website and go through his tutors on loading a texture and then texture mapped fonts.

    Here is an example code of how I read the diffrent sprites from the texture.

    I have the sprites setup in equal square spaces, on the texture. pose is image position along the column and frame is row position. One texture holds a 8 colunms x 8 rows of sprites, you can adjust the maping to any column/row configuration.

    Code :
    void draw_badguy(int pose, int frame)
    {
     
    	float ex = pose * 0.125f;
    	float ey = frame * 0.125f;
     
    	glBindTexture(GL_TEXTURE_2D, texture_id[0]);
    	glBegin(GL_QUADS);
    		glTexCoord2f(ex+0.125f,1.0f-(ey +0.125f    ) ); glVertex3f(-1.0f,-1.0f,0.0f);
    		glTexCoord2f(ex,1.0f-(ey+0.125f  )); glVertex3f( 1.0f,-1.0f,0.0f);
    		glTexCoord2f(ex,1.0f-(ey)); glVertex3f( 1.0f, 1.0f,0.0f);
    		glTexCoord2f(ex +0.125f,1.0f-(ey )); glVertex3f(-1.0f, 1.0f,0.0f);
    	glEnd();
     
    }

Similar Threads

  1. Replies: 4
    Last Post: 06-16-2016, 04:47 AM
  2. Implementing Animation with Sprite Sheets
    By redalwaysmafia in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-24-2015, 12:57 PM
  3. GLSL v1.30 and v1.40 quick reference sheets?
    By bootstrap in forum OpenGL: GLSL
    Replies: 1
    Last Post: 06-06-2009, 12:26 PM
  4. Point Sprite example
    By zaphod in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-14-2006, 10:01 AM
  5. Sprite
    By Leyder Dylan in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-18-2001, 02:48 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