Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: sprite sheet

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148

    Cool sprite sheet

    well I am using opengl and soil and c++. I am trying to use a sprite sheet to animate a 2D sprite. here is the code I am using. I am able to draw a single sprite to the screen, however I am making progress.
    Code :
    int LoadGLTextures()
    {
    	texture[0] = SOIL_load_OGL_texture
    	(
    		"planesheet.png",
    		SOIL_LOAD_AUTO,
    		SOIL_CREATE_NEW_ID,
    		SOIL_FLAG_INVERT_Y|SOIL_FLAG_POWER_OF_TWO|SOIL_FLAG_TEXTURE_REPEATS
    	);
     
    	if (texture[0] == 0)
    		return false;
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    	return true;
    }
     
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
     
    	glEnable(GL_TEXTURE_2D);
     
    	glGenTextures(8, &texture[1]);
    	glBindTexture(GL_TEXTURE_2D,texture[0]);
     
    	glBegin(GL_QUADS);
    	glTexCoord2f(0.0f, 0.0f); 
    	glVertex3f(-10.0f, -10.0f, 0.0f);
    	glTexCoord2f(1.0f, 0.0f); 
    	glVertex3f(-10.0f, 10.0f, 0.0f);
    	glTexCoord2f(1.0f, 1.0f); 
    	glVertex3f(10.0f, 10.0f, 0.0f);
    	glTexCoord2f(0.0f, 1.0f); 
    	glVertex3f(10.0f, -10.0f, 0.0f);
    	glEnd();
     
    	glutSwapBuffers();
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    can I please get some help on using a sprite sheet

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2013
    Posts
    184
    What is your question?
    You have not asked anything.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    how does one use soil to draw a sprite from a sprite sheet, I am adjusting the glTexCoord3f function, but cannot get the sprite to render properly. how does soil read the png files.
    Last edited by pbivens; 09-11-2018 at 03:43 PM.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,031
    Right, but what does SOIL, or whatever image loader you use, have to do with this? I mean yes, you need some way to load an image. But once that image is in a texture, the image loader no longer has anything to do with it.

    Are you able to load and display an image? If so, are you able to load and display part of an image? If so, are you able to load and display any part of that image you so desire? And if you can do all of those things... then you already have everything you need to use a sprite sheet.

    So which part are you hung up on?

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    Click image for larger version. 

Name:	screen.jpg 
Views:	5 
Size:	21.7 KB 
ID:	2840I am able to load an image when I am using glTexCoord2f(1.0f,1.0f); I am also able to load part of an image using glTexCoord2f(0.125,0.125); however I am unable to load the part of the image I want. here is a screenshot.

  7. #7
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,031
    I am able to load an image when I am using glTexCoord2f(1.0f,1.0f);
    First, a matter of terminology: `glTexCoord2f` has nothing to do with "loading an image". That is part of how you display the image or a portion thereof.

    Next, so you know that by manipulating the values you provide to `glTexCoord2f`, that you can manipulate the portion of the image that gets rendered. Have you tried playing around with those numbers? Do you see any pattern, any relationship between the numbers you provide and what portion of the image gets displayed? And have you tried changing the coordinates that are given 0 values as well?

    Take some time to explore the space of what you're doing here.

  8. #8
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    well here is code I am using it almost draws what I want it to do. here is a screenshotClick image for larger version. 

Name:	screenshot.jpg 
Views:	4 
Size:	21.6 KB 
ID:	2841it draws two triangles where the image wraps around itself.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    well I finally solved my problem, thanks alfonse

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    148
    I have also figured out how to animate a 2d plane sprite

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •